def convert(product, show=True): W = 410 H = 410 url = pyqrcode.QRCode(product["url"], error='H') url.png('test.png', scale=10) im = Image.open('test.png') im = im.convert("RGBA") box = (135, 135, 270, 270) im.crop(box) region = Image.open('logoBSC.png') region = region.resize((box[2] - box[0], box[3] - box[1])) im.paste(region, box) w, h = ImageDraw.Draw(im).textsize(product["name"]) position = ((W - w * 2) / 2, 10) # Font must be in the same folder. font = ImageFont.truetype("ArchivoBlack-Regular.ttf", 18) font2 = ImageFont.truetype("ArchivoBlack-Regular.ttf", 14) ImageDraw.Draw(im).text( position, # Coordinates product["name"], # Text (0, 0, 0), # Color font=font) ImageDraw.Draw(im).text( (300, 380), # Coordinates "[ SCAN ME ]", # Text (0, 0, 0), # Color font=font2) if show: im.show() im.save("qr_codes/" + clean_name(product["name"])) print( f"{clean_name(product['name'])} saved at: ./qr_codes/{clean_name(product['name'])}" )
def create_qr(self): self.id = str(uuid4()) url = pyqrcode.QRCode(self.id, error='H') data = url.png_as_base64_str(scale=13) im = Image.open(BytesIO(base64.b64decode(data))) im = im.convert("RGBA") return im
def generate_board_certificate(request, slug): if request.method=='GET': board_data = Board_member_details.objects.get(slug=slug) board_certificate_data = Board_Certificate.objects.get(id=board_data.Designation_id) im = Image.open(board_certificate_data.image) d = ImageDraw.Draw(im) board_name_location = (board_certificate_data.board_name_location_x, board_certificate_data.board_name_location_y) designation_name_location = (board_certificate_data.boardposition_name_location_x, board_certificate_data.boardposition_name_location_y) text_color = (board_certificate_data.text_color_R, board_certificate_data.text_color_G, board_certificate_data.text_color_B) font_style = FontStyle.objects.get(id=board_certificate_data.font_type_id) font = ImageFont.truetype("get_board_data/arial.ttf", board_certificate_data.font_size) d.text(board_name_location, board_data.Board_Full_Name, fill=text_color, font=font) d.text(designation_name_location, board_certificate_data.Designation, fill=text_color, font=font) url = pyqrcode.QRCode("https://ieee-cs-cert-verify.herokuapp.com/board/"+str(slug)) url.png('test.png', scale=1) qr = Image.open('test.png') qr = qr.resize((board_certificate_data.qr_code_size_x, board_certificate_data.qr_code_size_y)) qr = qr.convert("RGBA") im = im.convert("RGBA") box = (board_certificate_data.qr_code_location_x, board_certificate_data.qr_code_location_y) #qr.crop(box) #region = im print(im) print(qr) im.paste(qr, box) #im.show() response = HttpResponse(content_type='image/png') im.save(response, "PNG") return response
def my_main(): t = turtle.Turtle() s = turtle.getscreen() lib.InitMyWindows(s, 1000, 800) shapedata = lib.ReadShape("myshape.txt") s.register_shape("myshape", tuple(shapedata)) t.shape("myshape") t.shapesize(2, 2) t.penup() t.goto(-300, 250) t.pendown() t.stamp() qr = pyqrcode.QRCode("www.oit.edu.tw") codeimg = qr.xbm(8) codebmp = tk.BitmapImage(data=codeimg) cv = s.getcanvas() cv.create_image(0, 0, image=codebmp, anchor=tk.N) s.onkey(lambda: lib.close(s), "X") s.onclick(lambda x, y: lib.mouse_R(s), btn=3) s.listen() s.mainloop()
def qr_code(): code = "v-gnaret@microsoft" qr = pyqrcode.create(code) qr = pyqrcode.QRCode(version=1, box_size=10) qr.add_data("*****@*****.**") qr.make(fit=True) img = qr.make_image(fill_colour='black', back_colour='white') print(img)
def get(self): # TODO check these arguments - they could be malicious! client_url = self.get_argument('location') file = self.get_argument('file', 'index.html') print(client_url) url = external_url(client_url, file=file, request=self.request) result = {'qr': pyqrcode.QRCode(url).code, 'url': url} return self.write(json.dumps(result) + "\n")
def convert_certificate_to_pdf(request, slug): if request.method == 'GET': user_data = ParticipantData.objects.get(slug=slug) #print(user_data.Full_Name) #print(user_data.Event_Name) certificate_data = Certificate.objects.get(id=user_data.Event_Name_id) #print(certificate_data.image) im = Image.open(certificate_data.image) d = ImageDraw.Draw(im) participate_name_location = ( certificate_data.participate_name_position_x, certificate_data.participate_name_position_y) event_name_location = (certificate_data.event_name_position_x, certificate_data.event_name_position_y) text_color = (certificate_data.text_color_R, certificate_data.text_color_G, certificate_data.text_color_B) font = ImageFont.truetype(certificate_data.font_type, certificate_data.font_size) d.text(participate_name_location, user_data.Full_Name, fill=text_color, font=font) d.text(event_name_location, certificate_data.Event_Name, fill=text_color, font=font) url = pyqrcode.QRCode( "http://127.0.0.1:8000/get_data/generate_certificate/" + str(slug)) url.png('test.png', scale=1) qr = Image.open('test.png') qr = qr.resize( (certificate_data.qr_code_size_x, certificate_data.qr_code_size_y)) qr = qr.convert("RGBA") im = im.convert("RGBA") box = (certificate_data.qr_code_position_x, certificate_data.qr_code_position_y) #qr.crop(box) #region = im print(im) print(qr) im.paste(qr, box) Imgfile = im.convert("RGB") #pdf_bytes = img2pdf.convert(im) #print(pdf_bytes) #response = HttpResponse(content_type='application/pdf') #response['Content-Disposition'] = 'inline; filename=' + str(user_data.Full_Name) + '.pdf' img_bytes = BytesIO() Imgfile.save(img_bytes, "PDF") img_bytes = img_bytes.getvalue() #print(img_bytes) response = HttpResponse(img_bytes, content_type='application/pdf') response['Content-Disposition'] = 'inline; filename=' + str( user_data.Full_Name) + '.pdf' return response
def generate_certificate(request, slug): if request.method == 'GET': user_data = ParticipantData.objects.get( slug=slug ) # get specific user data from database using primary key "slug" certificate_data = Certificate.objects.get( id=user_data.Event_Name_id ) # get certificate data from database using Event id (FK) where FK = foreign key im = Image.open(certificate_data.image) # open image d = ImageDraw.Draw(im) # code to give edit access to image selected participate_name_location = ( certificate_data.participate_name_position_x, certificate_data.participate_name_position_y ) # give location in terms of co-ordinate for participant name in certificate event_name_location = ( certificate_data.event_name_position_x, certificate_data.event_name_position_y ) # give location for even name in certificate (co-ordinates is used) text_color = (certificate_data.text_color_R, certificate_data.text_color_G, certificate_data.text_color_B) # set color font_style = FontStyle.objects.get(id=certificate_data.font_type_id) #print(font_style.font_type) font = ImageFont.truetype("get_data/arial.ttf", certificate_data.font_size) # set font size ######## write text i.e full name, event name into certificate d.text(participate_name_location, user_data.Full_Name, fill=text_color, font=font) d.text(event_name_location, certificate_data.Event_Name, fill=text_color, font=font) ######## url = pyqrcode.QRCode( "https://ieee-cs-cert-verify.herokuapp.com/events/" + str(slug)) # set dyanmic URL link into qr code url.png('test.png', scale=1) qr = Image.open('test.png') qr = qr.resize( (certificate_data.qr_code_size_x, certificate_data.qr_code_size_y)) # set QR code position # convert to pdf qr = qr.convert("RGBA") im = im.convert("RGBA") box = (certificate_data.qr_code_position_x, certificate_data.qr_code_position_y) im.paste(qr, box) # pasted qr code into certificate response = HttpResponse(content_type='image/png') # send as response im.save(response, "PNG") return response
def qrcodegen(): """To generate Qr-Code""" name1 = "Generate Qr-Code" #Check if the user logged in if ('user' in session and session['user'] == params['admin_email']): if request.method == "POST": #Getting the data title = request.form.get('title') endpoint = request.form.get('endpoint') #Getting the folder path THIS_FOLDER = os.path.dirname(os.path.abspath(__file__)) my_file = os.path.join( THIS_FOLDER, "static/images/", ) filename = my_file + str(endpoint) + ".png" stime = datetime.now() #Generate QrCode url = pyqrcode.QRCode(title, error='H') url.png(filename, scale=10) im = Image.open(filename) im = im.convert("RGBA") logo = Image.open(my_file + "logo.png") box = (135, 135, 235, 235) im.crop(box) region = logo region = region.resize((box[2] - box[0], box[3] - box[1])) im.paste(region, box) #Naming the QrCode File qrcode = str(endpoint) + ".png" #Add an entry to database qrcode3 = Qrcode(title=title, qrcode=qrcode, stime=stime, endpoint=endpoint) db.session.add(qrcode3) db.session.commit() #Flashing the success message flash('A qr code has been generated successfully') return redirect('/qr-code') #Return to the Qr-Code Generator page return render_template("qrcode-gen-admin.html", params=params, title=name1) #If user not logged in then redirect to dashboard return redirect('/dashboard')
def generate_QR(data, pin): key = sk_to_data(data, pin) qr = qrcode.QRCode(version=1, box_size=10, border=4) qr.add_data(key) qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") cleardata() qr = "qr" + str(time.time()) + ".png" img.save('static/' + qr) return qr
def save(self, *args, **kwargs): super().save(*args, **kwargs) if not self.qr_code: memfile = BytesIO() qr = pyqrcode.QRCode(self.storeURL) qr.png(memfile, scale=10) self.qr_code.save(self.slug + '.png', File(memfile), save=False) super(Restaurant, self).save(*args, **kwargs) print('generated QR') memfile.close()
def qrfilegen(token, creator): qrfilename = get_str() link = create_redemption_url(token) url = pyqrcode.QRCode(link) handle = BytesIO() url.svg(handle, scale = 1, xmldecl=False) tup = handle.getvalue().decode("UTF-8") string_svg = "".join(tup) b64_svg = string_svg.encode("base64") # Saves a b64 representation of the SVG in the QRCode db model save_qr(token, b64_svg, creator)
def generateQR(): try: file = open(FILE, "r") content = file.readlines() i=0 for x in content: print(x) text = pyqrcode.QRCode(x, encoding="utf-8") text.png(str(i)+".png", scale=50) i+=1 except FileNotFoundError: print("File not found")
def generate_qr_png(url, logo='RoboyLogoCut.png', name='qr.png'): url = pyqrcode.QRCode(url, error='H') url.png('test.png', scale=15) im = Image.open('test.png') im = im.convert("RGB") logo = Image.open(logo) x = im.width / 2 - im.width / 6 y = im.width / 2 + im.width / 6 box = (x, x, y, y) im.crop(box) region = logo region = region.resize((box[2] - box[0], box[3] - box[1])) im.paste(region, box, mask=region) im.save(name, "PNG")
def __init__(self): # print('it works') checkStr = check.Check(test=True).getFiscalString() interface.UserInterface() # PNG TRYING # with open("./output/QR.png", "wb") as outputFile: # qr = QR.create(checkStr) # qr.png(outputFile, scale=4) # SVG TRYING with open("./output/QR.svg", "wb") as outputFile: qr = QR.QRCode(checkStr) qr.svg(file=outputFile, scale=4)
def generator(): if len(input_url.get()) != 0: global myQr #generates code from url myQr = pyqrcode.QRCode(input_url.get(), error='H') #where the png will be saved dir = 'Desktop/qrcode' #if path does't exist create one if not os.path.isdir(dir): os.makedirs(dir) #save png to dir with the given file name myQr.png(os.path.join(dir, file_name.get() + ".png"), scale=6) #display qrcode myQr.show() else: messagebox.showinfo("Invalid Input", "Please enter a URL")
def generate_certificate(request, slug): if request.method == 'GET': user_data = ParticipantData.objects.get(slug=slug) #print(user_data.Full_Name) #print(user_data.Event_Name) certificate_data = Certificate.objects.get(id=user_data.Event_Name_id) #print(certificate_data.image) im = Image.open(certificate_data.image) d = ImageDraw.Draw(im) participate_name_location = ( certificate_data.participate_name_position_x, certificate_data.participate_name_position_y) event_name_location = (certificate_data.event_name_position_x, certificate_data.event_name_position_y) text_color = (certificate_data.text_color_R, certificate_data.text_color_G, certificate_data.text_color_B) font = ImageFont.truetype(certificate_data.font_type, certificate_data.font_size) d.text(participate_name_location, user_data.Full_Name, fill=text_color, font=font) d.text(event_name_location, certificate_data.Event_Name, fill=text_color, font=font) url = pyqrcode.QRCode( "http://127.0.0.1:8000/get_data/generate_certificate/" + str(slug)) url.png('test.png', scale=1) qr = Image.open('test.png') qr = qr.resize( (certificate_data.qr_code_size_x, certificate_data.qr_code_size_y)) qr = qr.convert("RGBA") im = im.convert("RGBA") box = (certificate_data.qr_code_position_x, certificate_data.qr_code_position_y) #qr.crop(box) #region = im print(im) print(qr) im.paste(qr, box) #im.show() response = HttpResponse(content_type='image/png') im.save(response, "PNG") return response
def ticket(self, filmnaam, username, email): """This function creates the ticket code and also makes a qr code that connects with your ticket code :parameter filmnaam= is the movies chosen by the user username= the name that was entered in the login-screen of the user email= the e-mailadres entered in the login-screen of the user """ name_film = filmnaam[0] starttime = filmnaam[1] ticket_code = Function_file.codegenerator(username, email, name_film, starttime) qr_code = pyqrcode.QRCode(ticket_code) qr_code.show() # Schrijft de ticket informatie naar de database Function_file.SQL_Write_User(username, email, ticket_code, filmnaam[0], filmnaam[1], filmnaam[3]) # Weergeeft de ticketcode in de UI ticketcode_schem = Toplevel() Label(ticketcode_schem, text="Uw ticketcode is als onderstaande", width=100).grid(row=1) Label(ticketcode_schem, text=ticket_code, width=100).grid(row=6)
def convert_certificate_to_pdf(request, slug): if request.method == 'GET': user_data = ParticipantData.objects.get(slug=slug) certificate_data = Certificate.objects.get(id=user_data.Event_Name_id) im = Image.open(certificate_data.image) d = ImageDraw.Draw(im) participate_name_location = ( certificate_data.participate_name_position_x, certificate_data.participate_name_position_y) event_name_location = (certificate_data.event_name_position_x, certificate_data.event_name_position_y) text_color = (certificate_data.text_color_R, certificate_data.text_color_G, certificate_data.text_color_B) font_style = FontStyle.objects.get(id=certificate_data.font_type_id) #print(font_style.font_type) font = ImageFont.truetype("get_data/arial.ttf", certificate_data.font_size) # set font size d.text(participate_name_location, user_data.Full_Name, fill=text_color, font=font) d.text(event_name_location, certificate_data.Event_Name, fill=text_color, font=font) url = pyqrcode.QRCode( "https://ieee-cs-cert-verify.herokuapp.com/events/" + str(slug)) url.png('test.png', scale=1) qr = Image.open('test.png') qr = qr.resize( (certificate_data.qr_code_size_x, certificate_data.qr_code_size_y)) qr = qr.convert("RGBA") im = im.convert("RGBA") box = (certificate_data.qr_code_position_x, certificate_data.qr_code_position_y) im.paste(qr, box) Imgfile = im.convert("RGB") img_bytes = BytesIO() Imgfile.save(img_bytes, "PDF") img_bytes = img_bytes.getvalue() response = HttpResponse(img_bytes, content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename=' + str( user_data.Full_Name) + '.pdf' return response
def start_server_process(port: int = 2908, showServerURL=False): """Start Server in another process. Parameters ---------- port The port on which to run the server (default is 2908). Returns ------- Completed Process of `subprocess.run`. """ import sys python = sys.executable # or os.__file__.split("lib/")[0],"bin","python") ? proc = subprocess.Popen( [python, '-m', 'plotar.server', '--port', str(port)]) if showServerURL: url = _host + '/index.html' try: response = requests.get(_host + "/qr.json") response.raise_for_status() url = response.json()['url'] except Exception as ex: print("Problem getting external IP: ", ex) pass try: from IPython.display import display, SVG, HTML import pyqrcode from io import BytesIO io = BytesIO() pyqrcode.QRCode(url).svg(io, scale=4) img = io.getvalue().decode('utf-8') display(HTML(f'Visit: <a href="{url}">{url}</a>')) display(SVG(img)) except ImportError: print(f"Visit: {url}") return proc
def convert_certificate_to_pdf(request, slug): if request.method=='GET': user_data = Board_member_details.objects.get(slug=slug) #print(user_data.Full_Name) #print(user_data.Event_Name) certificate_data = Board_Certificate.objects.get(id=user_data.Designation_id) #print(certificate_data.image) im = Image.open(certificate_data.image) d = ImageDraw.Draw(im) participate_name_location = (certificate_data.board_name_location_x, certificate_data.board_name_location_y) event_name_location = (certificate_data.boardposition_name_location_x, certificate_data.boardposition_name_location_y) text_color = (certificate_data.text_color_R, certificate_data.text_color_G, certificate_data.text_color_B) font_style = FontStyle.objects.get(id=certificate_data.font_type_id) font = ImageFont.truetype("get_board_data/arial.ttf", certificate_data.font_size) d.text(participate_name_location, user_data.Board_Full_Name, fill=text_color, font=font) d.text(event_name_location, certificate_data.Designation, fill=text_color, font=font) url = pyqrcode.QRCode("https://ieee-cs-cert-verify.herokuapp.com/board/"+str(slug)) url.png('test.png', scale=1) qr = Image.open('test.png') qr = qr.resize((certificate_data.qr_code_size_x, certificate_data.qr_code_size_y)) qr = qr.convert("RGBA") im = im.convert("RGBA") box = (certificate_data.qr_code_location_x, certificate_data.qr_code_location_y) #qr.crop(box) #region = im print(im) print(qr) im.paste(qr, box) Imgfile = im.convert("RGB") #pdf_bytes = img2pdf.convert(im) #print(pdf_bytes) #response = HttpResponse(content_type='application/pdf') #response['Content-Disposition'] = 'inline; filename=' + str(user_data.Full_Name) + '.pdf' img_bytes = BytesIO() Imgfile.save(img_bytes, "PDF") img_bytes = img_bytes.getvalue() #print(img_bytes) response = HttpResponse(img_bytes , content_type='application/pdf') response['Content-Disposition'] = 'attachment; filename=' + str(user_data.Board_Full_Name) + '.pdf' #response = FileResponse(img_bytes) return response
def get_image(): base_dir = "qr_image/" file_format = "png" url = "www.naver.com" scale = 10 # localhost:5000/get_image?format=png&url="www.google.com"&scal=20 print(request.args) try: if request.args.get("format"): file_format = request.args.get("format") else: pass if request.args.get("url"): url = request.args.get("url") else: pass if request.args.get("scal"): scale = request.args.get("scal") else: pass except: pass filename = base_dir + str(time.time()).replace(".","") +'.' + file_format print(filename) file = pyqrcode.QRCode(url, error='H') if request.args.get("format") == "eps": file.eps(filename, scale=scale) return send_file(filename, mimetype='application/postscript') elif request.args.get("format") == "png": file.png(filename, scale=scale) return send_file(filename, mimetype='image/png') elif request.args.get("format") == "jpg": file.png(filename, scale=scale) return send_file(filename, mimetype='image/jpg') else: file.png(filename, scale=scale) return send_file(filename, mimetype='image/png')
def create_qr_code(value): # Generate the qr code and save as png qrcode_png = value + ".png" qrobj = pyqrcode.QRCode(qrcode_prefix + value, error="H") qrobj.png(qrcode_png, scale=10, quiet_zone=1) # Now open that png image to put the logo img = Image.open(qrcode_png) img = img.convert("RGBA") width, height = img.size # Open the logo image and define how big the logo we want to put in the qr code png logo = Image.open(qrcode_logo_img) logo_size = 80 # Calculate logo size and position xmin = ymin = int((width / 2) - (logo_size / 2)) xmax = ymax = int((width / 2) + (logo_size / 2)) logo = logo.resize((xmax - xmin, ymax - ymin)) # put the logo in the qr code and save image img.paste(logo, (xmin, ymin, xmax, ymax)) img.save(image_home + qrcode_png) return image_home + qrcode_png
def img_to_qr(filename): title = "6100" * 20 author = "6100" * 9 place = "6100" * 9 prefix = title + "0000b6ec" + author + "000044c5" + place + "00001931" interfix = "cc0a090000" # 主色调颜色的字符串,取15种颜色的对应标签,长度为30位字符串 palette = '' # 主色调颜色及标签列表 list of [color,labe] palette_list = compress_colors(img_resize(filename)) # 单独抽离出主色调颜色 palette_colors_list = [] # 单独抽离出主色调标签 label_list = [] for color, label in palette_list: palette += label palette_colors_list.append(color) label_list.append(label) image = np.array(Image.open('temp_temp_' + filename), dtype=np.int) canvas = '' # 通过两次循环,将读取的所有像素点的色值转换为主色调列表中最接近的颜色,并给出最接近颜色在主色调列表里的16进制索引下标 for i in range(0, 32): for j in range(0, 16): # 读取的图片颜色用get_closet_color函数重新计算一次最接近颜色,色表用主色调列表 color = get_closest_color(image[i][j * 2 + 1], palette_colors_list) label = palette_list[palette_colors_list.index(list(color))][1] # 给出color在主色调列表的索引下标,并转为16进制 index = hex(label_list.index(label))[2:] canvas = canvas + hex(int(index, 16))[2:] color = get_closest_color(image[i][j * 2], palette_colors_list) label = palette_list[palette_colors_list.index(list(color))][1] index = hex(label_list.index(label))[2:] canvas = canvas + hex(int(index, 16))[2:] # 编码,将字符串转为bytelist byte_array = hex_to_byte(prefix + palette + interfix + canvas) qr_code = pyqrcode.QRCode(byte_array, error='M') qr_code.png('qrcode_' + filename) os.remove('temp_' + filename) os.remove('temp_temp_' + filename)
def make_qr(data, version=4): qr = pyqrcode.QRCode(data, version=version) text = qr.text(quiet_zone=1) return [map(int, row) for row in text.split()]
from PIL import Image, ImageTk, ImageFont, ImageDraw j = 3.7795275591 # 1 j = 1 mm # TAMANHO EM MM tamanhoQR = (int(35 * j) + 1, int(35 * j) + 1) xDoPapel = int(148 * j) + 1 yDoPapel = int(45 * j) + 1 ## LOOP, Abre um arquivo LISTA e pega os nomes separados pela tecla enter e armazena em jv with open("LISTA.txt") as f: for line in f: print line jv = line.replace('\n', '') url = pyqrcode.QRCode(jv, error='H') url.png('imgs/' + jv + '.png', scale=10) im = Image.open('imgs/' + jv + '.png') im = im.convert("RGBA") logo = Image.open('logo.png') #Box => a imagem ficará em um (x,y) inicial até (x2,y2) final. box = (135, 135, 235, 235) #imagem terá 100 x 100 px im.crop(box) region = logo region = region.resize((box[2] - box[0], box[3] - box[1])) im.paste(region, box)
import pyqrcode from PIL import Image #variable definitions logoWidth = 100 #change this to enlarge/reduce logo size string = 'https://www.facebook.com/HolyFamilyKajang/' #url to be embedded logoString = 'logo.png' #path to intended logo location out = 'qrcode.jpg' #save name and format as jpg #generate qr code, open, obtain width and height of qrcode url = pyqrcode.QRCode(string) url.png('test.png', scale=10) #save qrcode as test.png im = Image.open('test.png') #open saved qrcode im = im.convert("RGBA") width, height = im.size #open logo image, crop and paste logo logo = Image.open(logoString) a, b = logo.size logoRatio = a / b logoHeight = int(logoWidth / logoRatio) leftBorder = int((width - logoWidth) / 2) upBorder = int((height - logoHeight) / 2) rightBorder = int((width + logoWidth) / 2) bottomBorder = int((height + logoHeight) / 2) box = ( leftBorder, upBorder, rightBorder, bottomBorder ) #logo placement. take (qrcode size-logo size)/2 , (qrcode size+logo size)/2 im.crop(box) logo = logo.resize((logoWidth, logoHeight)) #set logo size im.paste(logo, box) #place logo
import pyqrcode from PIL import Image url = pyqrcode.QRCode('https://www.facebook.com/Annasurbangarden/', error='H') url.png('test.png', scale=8) im = Image.open('test.png') im = im.convert("RGBA") logo = Image.open('logo.png') box = (140, 140, 230, 230) im.crop(box) region = logo region = region.resize((box[3] - box[1], box[3] - box[1])) im.paste(region, box) im.show() im = im.save('final.png')
data = 'CSCI 0' error = 'H' version = None mode = 'alphanumeric' if not os.path.exists(code_dir): os.mkdir(code_dir) elif not os.path.isdir(code_dir): raise ValueError('{} is not a directory.'.format(code_dir)) if len(sys.argv) > 1: v = int(sys.argv[1]) if len(sys.argv) > 2: s = int(sys.argv[2]) #for i in range(1, v+1): # print('Generating version {}'.format(i)) # try: code = pyqrcode.QRCode(data, error=error, version=version, mode=mode) print code.terminal() code.png('{}/v{}.png'.format(code_dir, code.version), scale) #code.svg('{}/v{}.svg'.format(code_dir, code.version), scale, background="white") print('Error={}\nVersion={}\nMode={}\nScale={}'.format(code.error, code.version, code.mode, scale)) # except ValueError: # print('Version {} will not fit'.format(i)) # pass
import pyqrcode from PIL import Image # insert logo or pict logo = Image.open('syekhalijaber.png') # size basewidth = 75 wpercent = (basewidth / float(logo.size[0])) hsize = int((float(logo.size[1]) * float(wpercent))) logo = logo.resize((basewidth, hsize), Image.ANTIALIAS) # qr code qr_big = pyqrcode.QRCode(error_correction=pyqrcode.constants.ERROR_CORRECT_H) qr_big.add_data('https://google.com') qr_big.make() img_qr_big = qr_big.make_image(fill_color='#0B4E39', back_color="white").convert('RGB') pos = ((img_qr_big.size[0] - logo.size[0]) // 2, (img_qr_big.size[1] - logo.size[1]) // 2) img_qr_big.paste(logo, pos) img_qr_big.save('syekhalijaber_qr.jpg')