Preserving extent from the old image
I am using PIL 1.1.6, Python 2.5 on the Windows platform.
In my program, I am performing a point operation (changing the pixel values) and then saving the new image.
When I am loading the new and old image, they are not in the same extent. How to impose the extent of old image to the new image?
My code is:
i开发者_如何学JAVAmg = Image.open("D:/BTC/dada_72.tif")
out = Image.eval(img, lambda x: x * 5)
out.save("D:/BTC/dada_72_Com.tif")
Assuming by "extent" you mean "size" (pixels wide by pixels high), then there are several options depending on what you have as a "new" image.
If "new" is an existing image (and you want to stretch/shrink/grow the new):
from PIL import Image
>>> im1 = Image.open('img1.jpg')
>>> im2 = Image.open('img2.jpg').resize(im1.size)
If you want to crop or pad "new" that's a bit more complex...
If "new" is a new blank image:
>>> im1 = Image.open('img1.jpg')
>>> im2 = Image.new(im1.mode, im1.size)
精彩评论