Imge.show () may not work under Liunx.
PS: The standard version of the show () method is not very efficient because it first saves the image as a temporary file and then displays it using XV. If XV is not installed, the function does not even work. However, this method is very convenient for debug and test. (The default picture viewer should be called in Windows to open)
The code is as follows:
#-*-coding:utf-8-*-
#这是一个二维码的生成代码
Import QRCode
Import OS
From PIL import Image
Import Pillow
Print ()
Class QRCode ():
def __init__ (self, version=8,
Error_correction=qrcode.constants.error_correct_h,
Box_size=4,
Border=1,
Save_path_name= "Two-dimensional code",
Cont= ' Your QR code information is not generated, please try again ',
Path= ',
Logo= "
):
Self.version=version #值范围为1 ~40, control the size of the QR code, None and use the Fit parameter
self.error_correction=error_correction# Error correction Ability _l about 7%,_m about 15%,_h about 30%
self.box_size=box_size# controls the number of pixels that each little man in the QR code contains
self.border=border# border Value, Min. 4
Self.name=save_path_name
Self.cont=cont
Self.save_path_name=save_path_name
Self.logo = Logo
Print ("I already have the properties of the QR Code")
def Save (self):
qr = QRCode. QRCode (
Version=self.version,
Error_correction=self.error_correction,
Box_size=self.box_size,
Border=self.border,
)
Qr.add_data (Self.cont)
Qr.make (Fit=true)
img = Qr.make_image ()
img = Img.convert (' RGBA ')
icon = Image.open (Self.logo)
img_w, Img_h = img.size
Factor = 1/4
Size_w,size_h = (int (img_w*factor), int (img_h*factor))
icon = icon.resize ((size_w,size_h), Image.antialias)
W,h = (int (img_w* (1-factor)/2), int (img_h* (1-factor)/2))
Icon =icon.convert (' RGBA ')
Img.paste (icon, (w,h), icon)
Img.save (Self.save_path_name)
Img.show ()
#print ("The QR code has been generated, exists in the current directory")
#image =image.open (self.name+ '. png ')
#image. Show ()
#os. System ("Explorer.exe%s"%OS.GETCWD ()) Open the current folder and use it under win
A=qrcode (cont= "http://www.jb51.net/article/58579.htm", save_path_name= '/home/fuhan/fuhan.jpg ', logo= '/home/fuhan /a.jpg ')
A.save ()
Python generates QR code for picture