-
-
Save tomvon/ae288482869b495201a0 to your computer and use it in GitHub Desktop.
| #Resizes an image and keeps aspect ratio. Set mywidth to the desired with in pixels. | |
| import PIL | |
| from PIL import Image | |
| mywidth = 300 | |
| img = Image.open('someimage.jpg') | |
| wpercent = (mywidth/float(img.size[0])) | |
| hsize = int((float(img.size[1])*float(wpercent))) | |
| img = img.resize((mywidth,hsize), PIL.Image.ANTIALIAS) | |
| img.save('resized.jpg') |
thank you
thanks
Thanks for the code but ANTIALIAS is deprecated for 3.11 version of python. I have used Image.LANCZOS instead but quality is compromised. Can you please help?
It is reducing the colors. Which I don't want, that'swhy trying to find something which reduces the size but will not change the quality.
Original Size 31MB
After Size 4.55MB
Sorry, I can't upload the images here also because Github also not allowing me to upload file size above 10MB.
Alternatively, I want a code that should reduce the size 'just below 10MB'.
Thanks for the code but ANTIALIAS is deprecated for 3.11 version of python. I have used Image.LANCZOS instead but quality is compromised. Can you please help?
Yes Bro, same problem. What to do? I too don't understand.
PIL.Image.LANCZOS is now Image.Resampling.LANCZOS.
Possible options: https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-filters
Thanks, code helped a lot !!