Beispiel #1
0
def topdf(image_file: str, left=0, top=0):
    # image_file: str = "./test.png"
    # image_file = "https://zyai.jxwifi.com/uploads/20201203/ae26751e48348f0765322f9eb26a5a32.png"

    uuidName = str(uuid.uuid4())
    pdfName = uuidName + '.pdf'
    c = canvas.Canvas(getUploadDir() + '/' + pdfName, pagesize=A3)
    width, height = A3

    if image_file[-3:].lower() == 'png':
        jpgName = download_img(image_file, uuidName)
        im = Image.open(getUploadDir() + "/" + jpgName)
        x, y = im.size
        p = Image.new('RGBA', im.size, (255, 255, 255))
        p.paste(im, (0, 0, x, y), im)
        savePath = getUploadDir() + "/" + uuidName + '.png'
        p.save(savePath)
        c.drawImage(savePath, left, top, width, height)
    else:
        #c.drawImage(image_file, 0, 0, width, height)
        #c.drawInlineImage(image_file, 0, 0)
        # c.showPage()
        c.drawImage(image_file, left, top, width, height)
    c.save()
    return pdfName
Beispiel #2
0
def genLongImage(args):
    '''
    生成长图
    '''
    try:
        drawGentt(args[:3])
        drawTable(args)
        imgs = [
            Image.open(f'static/{fn}') for fn in listdir(path='static/')
            if fn.endswith('.png')
        ]
        width, height = imgs[0].size
        result = Image.new(imgs[0].mode, (width, height * len(imgs)))
        for index, img in enumerate(imgs):
            result.paste(img, box=(0, index * height))
        result.save('pws.png')
    except Exception:
        return False
    return True
Beispiel #3
0
# create the empty document object
Story=[]

figcnt = 0
qrcodeimagepath = utbiomelocation+"PNGFIGURES"
tmpsavefolder = utbiomelocation+"tempSaveFolder"
if os.path.exists(tmpsavefolder):
    shutil.rmtree(tmpsavefolder)
    os.mkdir(tmpsavefolder)
else:
    os.mkdir(tmpsavefolder)

for f in os.listdir(qrcodeimagepath):
    print f
    figcnt = figcnt+1
    new_im = Image.new('RGB', (1050,400))
    qr_file = qrcodeimagepath +'\\'+ f
    im = Image.open(qr_file)
    #Here I resize my opened image, so it is no bigger than 100,100
    #im.thumbnail((210,198))
    #Iterate through a 4 by 4 grid with spacing, to place my image
    for i in xrange(0,1050,210):
        for j in xrange(0,400,198):
            #paste the image at location i,j:
            new_im.paste(im, (i,j))
    new_im.show()
    new_im.save(tmpsavefolder+"\\new_imout"+str(figcnt)+".png","png")

# Now lets collect the stitched QRCode Images and append to the story doc and make the pdf
stitchedQrcodesPath = tmpsavefolder
for qr in os.listdir(stitchedQrcodesPath):
Beispiel #4
0
from reportlab.lib.units import inch, mm
from PIL import Image, ImageChops, ImageDraw, ImagePath, ImageFont
import numpy

c = canvas.Canvas("hello.pdf", pagesize=(1562, 221 * mm))
# logo = "images/1.png"
# logo_width,logo_height = 1043,445
# image = Image(logo,logo_width,logo_height)
# image = Image.open("images/1.png").save('lalala.png')
# c.drawImage(image,0,0)
# hello(c)

c.drawString(226, 110, "Hello")
hair = Image.open("images/ab_thumb_male_hair_straight.png")
white_back = Image.open("lalala.png")
txt = Image.new('RGBA', white_back.size, (255, 255, 255, 0))
d = ImageDraw.Draw(txt)
font = ImageFont.truetype("arial.ttf", size=20)
d.text((20, 20), "Hello WORLD!", fill=(0, 0, 0, 255), font=font)
# d.text((20,100),"Hello WORLD2!",fill=(0,0,0,255))
white_back.paste(hair, (700, 20), hair)


# TEXT TRANSFORMATION
def find_coeffs(pa, pb):
    matrix = []
    for p1, p2 in zip(pa, pb):
        matrix.append(
            [p1[0], p1[1], 1, 0, 0, 0, -p2[0] * p1[0], -p2[0] * p1[1]])
        matrix.append(
            [0, 0, 0, p1[0], p1[1], 1, -p2[1] * p1[0], -p2[1] * p1[1]])
Beispiel #5
0
def get_Invoice(request):
    if (request.method == 'POST'):
        data = request.data
        ingredientsList = data["nameList"]
        quantityList = data["quantityList"]
        #print(quantityList)
        priceList = data["priceList"]
        ingredientsdict = dict(
            my_custom_sql("select name,ingredient_id from inventory"))
        for i in range(0, len(ingredientsList)):
            ingredientsList[i] = str(ingredientsdict[ingredientsList[i]])
        balance = list(my_custom_sql("select balance from variable"))
        balance = list(itertools.chain(*balance))
        actbal = balance[0]
        ingredientsList = [int(i) for i in ingredientsList]
        quantityList = [float(i) for i in quantityList]
        #print(quantityList)
        priceList = [float(i) for i in priceList]
        # for index in range(len(priceList)):
        #     priceList[index]=(quantityList[index])*(priceList[index])
        gndprice = sum(priceList)
        print(gndprice)
        if (gndprice > actbal):
            return Response("Insufficient balance")
        else:
            #print(ingredientsList)
            for i in range(len(ingredientsList)):
                ingred = Inventory.objects.get(pk=ingredientsList[i])
                new_purchase = Purchase(ingredient=ingred,
                                        quantity=quantityList[i],
                                        price=priceList[i],
                                        date=datetime.now())
                new_purchase.save()
                try:
                    purchase_list = PurchaseList.objects.get(
                        ingredient_name=ingred.name, is_ordered=1)
                    # print(purchase_list)
                    if (purchase_list.amount <= quantityList[i]):
                        purchase_list.delete()
                    else:
                        purchase_list.amount -= float(quantityList[i])
                        purchase_list.is_ordered = 0
                        purchase_list.save()
                except:
                    traceback.print_exc()
            actbal = actbal - gndprice
            print(actbal)
            my_custom_sql('update variable SET balance={}'.format(actbal))
            for i in range(len(ingredientsList)):
                my_custom_sql(
                    'update inventory set quantity=quantity+{} where ingredient_id={}'
                    .format(quantityList[i], ingredientsList[i]))
            global invoice_no
            filename = "check" + str(invoice_no) + ".jpg"
            generate_check("supplier", gndprice, filename)
            invoice_no += 1
            try:
                with open(filename, "rb") as f:
                    return HttpResponse(f.read(), content_type="image/jpeg")
            except IOError:
                red = Image.new('RGBA', (1, 1), (255, 0, 0, 0))
                response = HttpResponse(content_type="image/jpeg")
                red.save(response, "JPEG")
                return response