0
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 !

6
  • You're redimensioning to the height - width of the original image? No wonder the size does'nt change.... Commented Jul 2, 2015 at 9:10
  • I want change file size. not change height - width. Commented Jul 2, 2015 at 9:28
  • for example : image cod2.png has size file 5 MB, I want change size file image cod2.png < 5MB ( about 500KB). without change height - width and quality ! Commented Jul 2, 2015 at 9:32
  • Ok, then you want to change the compression rate. Youcan't do it with a png because it's a loseless format. To get a smaller file with a constant image size (width-height) your only option is change the color depth or subsample it. before creating your png Jpg is a losy? format and you can squeeze it at will when building te file. Commented Jul 2, 2015 at 9:39
  • what about loseless format. I don't understand. Commented Jul 2, 2015 at 9:59

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.