4

I have used PIL to convert and resize jpg/bmt to png .. i can easily resize and convert to png but the file size is of new image is too big

im=Image.open(p1.photo)
im_resize = im.resize((400, 400), Image.ANTIALIAS)    # best down-sizing filter
im.save(str(merchant.id)+'_logo.'+'png')

what else i have to do to reduce image size?

hangman
  • 845
  • 4
  • 20
  • 31

2 Answers2

4

PNG Images still have to hold all data for every single pixel on the image, so there is a limit on how far you can compress them.

One way to further decrease it, since your 400x400 is to be used as a "thumbnail" of sorts, is to use indexed mode:

im_indexed = im_resize.convert("P") im_resize.save(... )

*wait * Just saw an error in your example code: You are saving the original image, not the resized image:

im=Image.open(p1.photo)
im_resize = im.resize((400, 400), Image.ANTIALIAS)    # best down-sizing filter
im.save(str(merchant.id)+'_logo.'+'png')

When you should be doing:

im_resize.save(str(merchant.id)+'_logo.'+'png')

You are just saving back the original image, that is why it looks so big. Probably you won't need to use indexed mode them.

Aother thing: Indexed mode images can look pretty poor - a better way out, if you come to need it, might be to have your smalle sizes saved as .jpg instead of .png s - these can get smaller as you need, trading size for quality.

jsbueno
  • 86,446
  • 9
  • 131
  • 182
0

You can use other tools like PNGOUT

Vivek S
  • 4,996
  • 8
  • 49
  • 71