imageproxy
imageproxy copied to clipboard
Transformation to add white space around image
I am looking for a way to add white space around image crop as illustrated in the image bellow. Anyone has ideas how to achieve that with the existing transformations?

Hello, I found a very good answer to this question here: (https://stackoverflow.com/questions/11142851/adding-borders-to-an-image-using-python)
Below is one way to do it
import Image
old_im = Image.open('someimage.jpg')
old_size = old_im.size
new_size = (800, 800)
new_im = Image.new("RGB", new_size) ## luckily, this is already black!
new_im.paste(old_im, ((new_size[0]-old_size[0])//2,
(new_size[1]-old_size[1])//2))
new_im.show()
# new_im.save('someimage.jpg')
by heltonbiker
Below is another using PIL
from PIL import Image, ImageOps
ImageOps.expand(Image.open('original-image.png'),border=300,fill='black').save('imaged-with-border.png')
by Igor Chubin