3 examples of 'python convert png to jpg' in Python

Every line of 'python convert png to jpg' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
12def 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
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

32def png2x(fig):
33 """render figure to 2x PNG via HTML"""
34 import matplotlib
35 if not fig.axes and not fig.lines:
36 return
37 # double DPI
38 dpi = 2 * matplotlib.rcParams['savefig.dpi']
39 pngbytes = print_figure(fig, fmt='png', dpi=dpi)
40 x,y = pngxy(pngbytes)
41 x2x = x // 2
42 y2x = y // 2
43 png64 = encodestring(pngbytes).decode('ascii')
44 return u"<img src='data:image/png;base64,%s' width=%i height=%i/>" % (png64, x2x, y2x)
41def frameToJPeg( frame ):
42 jpeg = cv2.imencode('.jpg', frame)[1].tostring()
43 jpegFramesCache[bytes(jpeg)] = frame
44 return jpeg

Related snippets