tags:

views:

48

answers:

1

I am using PIL 1.1.6, python 2.5 on windows platform.

In my program I am performing 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?

RE edited question:

My code is:

img = Image.open("D:/BTC/dada_72.tif")
out = Image.eval(img, lambda x: x * 5)
out.save("D:/BTC/dada_72_Com.tif")

Thank you

A: 

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)
bpowah
I am creating new image by performing pixel level manipulations on the old image. And then saving the new image. When I am opening the images in the viewer it shows that old and new image are located in different locations(may be problem of projection or extent, I cannot determine)
Sonai