The python PNG format images converted to jpg
"" " First look jpg and png images picture the difference between jpg format: lossy picture compression type, available disk space at least get a better picture quality png formats: No compression, transparent and so can save map " "" from the PIL Import Image Import CV2 AS CV Import OS DEF PNG_JPG (PngPath): IMG = cv.imread (PngPath, 0) W, H = img.shape [:: -. 1 ] INFILE = PngPath outfile = os.path.splitext ( INFILE) [0] + " .jpg " IMG = Image.open (INFILE) IMG = img.resize ((int (W / 2), int (H / 2 )), Image.ANTIALIAS) try: if len(img.split()) == 4: # prevent IOError: cannot write mode RGBA as BMP r, g, b, a = img.split() img = Image.merge("RGB", (r, g, b)) img.convert('RGB').save(outfile, quality=70) os.remove(PngPath) else: img.convert('RGB').save(outfile, quality=70) os.remove(PngPath) return outfile except Exception as e: print("JPG PNG conversion errors " , E) IF the __name__ == ' __main__ ' : PNG_JPG (R & lt " C: \ the Users \ Lenovo \ Desktop \ NEWi \ s.png " )
Original link: https://www.cnblogs.com/jiyanjiao-702521/p/10442416.html