Every line of 'base64 to image python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
12 def png2rgb(b64png): 13 b = base64.b64decode(b64png) 14 i = io.BytesIO(b) 15 img = mpimg.imread(i, format='PNG') 16 # # Pretty slow 17 # img = Image.open(i) 18 # i = np.array(img.getdata(), np.uint8).reshape(img.size[1], img.size[0], 3) 19 return img
9 def convert_image(image_data): 10 try: 11 image = Image.open(io.BytesIO(base64.b64decode(image_data))) 12 if image is not None : 13 image = image.resize(default_image_size, Image.ANTIALIAS) 14 image_array = img_to_array(image) 15 return np.expand_dims(image_array, axis=0), None 16 else : 17 return None, "Error loading image file" 18 except Exception as e: 19 return None, str(e)
131 def base64_to_gcode(self, base64str, w,h, x,y): 132 133 # remove "data:image/png;base64," and add a "\n" in front to get proper base64 encoding 134 if(base64str.startswith("data:")): 135 commaidx = base64str.find(',') 136 base64str = "\n" + base64str[commaidx:] 137 138 # fh = open("debug.png", "wb") 139 # fh.write(base64str.decode('base64')) 140 # fh.close() 141 142 image_string = cStringIO.StringIO(base64.b64decode(base64str)) 143 img = Image.open(image_string) 144 145 pixArray = self.img_prepare(img, w, h) 146 gcode = self.generate_gcode(pixArray, x, y, ) 147 return gcode
9 def _tobytes(image): 10 if hasattr(image, 'tobytes'): 11 return image.tobytes() # PIL 12 elif hasattr(image, 'tostring'): 13 return image.tostring() # PIL 14 elif hasattr(image.pixels.data, 'tobytes'): 15 return image.pixels.data.tobytes() # pymaging 16 else: 17 return image.pixels.data.tostring() # pymaging
9 def toBufFromImage( image ): 10 ss = BytesIO() 11 image.SaveFile( ss, wx.BITMAP_TYPE_PNG ) 12 return srcPrefix + base64.b64encode(ss.getbuffer()).decode()