So I have a table with image sizes. There are multiple images of different sizes (66x66, 400x400, etc.). I have one example of image (the original) that always has a size of 600x532, and on this image is a product (a TV, a PC, etc.).
I have to resize this image, which isn't a problem. But if I do this with proportion I get something like 66x55. If I don't do this with proportion the image doesn't look good.
So the background of the original is always white. Is there a way to extend the area of the image and filling the rest with white? So like this: 600x532 -> 600x600 -> 66x66 etc etc.
It should be like a anti-crop.
EDIT: I found out that if I use crop() from PIL and instead of "minimizing" using a value above the actual image-size it creates my extra area. but it is going to be black. Any idea how I could fill this area white?
EDIT2: I guess it has something to do with ImageDraw.
EDIT3: After finding out that ImageDraw was the solution, my problem was solved. Please close this.
Here my solution:
import Image, ImageDraw
img1 = Image.open("img.jpg")
img2 = img1.crop((0,0,600,600))
draw = ImageDraw.Draw(img2)
draw.rectangle( (0,532,600,600), fill='white' )
del draw
img2.save("img2.jpg","JPEG", quality=75)
The next thing I will do is to make the extra crop above and under. So the picture stays in the middle.
EDIT4: final solution
img1 = Image.open("img1.jpg")
img2 = img1.crop( (0,-34,600,566) )
draw = ImageDraw.Draw(img2)
draw.rectangle( (0,0,600,34), fill="white" )
draw.rectangle( (0,566,600,600), fill="white" )
del draw
img2.save("img2.jpg", "JPEG", quality=75)