简体   繁体   中英

Resize file data image .PNG in Python

import Image
import os  
def resize_file(fname):
    width, height = get_image_size(fname) /// get_image_size return width and height ///
    name, ext = os.path.splitext(fname)
    new_image_file = "%s%s%s" %(name, 'new' , ext)
    im1 = Image.open(fname)
    im5 = im1.resize((width, height), Image.ANTIALIAS)
    ext2 = ".jpg"
    im5.save(name + 'new' + ext2)
    import webbrowser
    webbrowser.open(name + 'new' + ext2)
if __name__ == "__main__":
    resize_file('/home/kirito/Desktop/HD_69830_Planet.jpg')
    resize_file('/home/kirito/Desktop/cod2.png')

* My problem : line when I change ext2 = ".png" data file not change. but when ext2 = ".jpg" data size down (case true). I want change image.png data file size down and result still image.png !

Close !

A lossless format, such as PNG, allows one to recover the exact pixel values of the original image from the compressed file. A lossy format makes some assumptions about what the human eye can and can't see, and removes the "non relevant" information to reduce the size of the file. This way, you have an image visually indistinguishable from the original - until you zoom it and find the artifacts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM