Reputation: 1
I am new to Python and I have tried sample code I have been given.
I Want to convert bulk TIFF files to JPG. The TIFF size will be 3MB or more. I want to resize to my requirement width is 1200 height also I will provide some Y
When I run sample codes given
For example:
original image size is 1748 X 2479
import PIL
import PIL.Image, PIL.ImageFile
from exceptions import IOError
img = PIL.Image.open("p3.tif")
img.MAXBLOCK = 2**20
destination = "x.jpeg"
img.resize((1200,1800))
try:
img.save(destination, "JPEG", quality=10, optimize=True, progressive=True)
except IOError:
PIL.ImageFile.MAXBLOCK = img.size[0] * img.size[1]
img.save(destination, "JPEG", quality=10, optimize=True, progressive=True)
Its not resize the value what I have given.
Upvotes: 0
Views: 2655
Reputation: 365587
As the docs say, resize
Returns a resized copy of this image.
So, this line:
img.resize((1200,1800))
… does not resize an image in-place, it returns a new, resized, image. That's the one you want to save.
So:
img1200 = img.resize((1200, 1800))
img1200.save(destination, "JPEG", quality=10, optimize=True, progressive=True)
Meanwhile, whatever tutorial or sample code you were following, if it gave you this code, you should find a better source.
Upvotes: 3