Reputation: 21
My use case : I want to add a border of 10 pixel to the image using the ImageOps.expand method in the PIL. It asks for a fill value the default being black. I researched and found that in order to find the color value of a pixel, you need to do
pix = im.load()
im = ImageOps.expand(im, border=10, fill=pix[0,0])
Issue:
I am not able to pass this pix[x,y]
value to the expand method. I went through the method definition and can't find the exact reason this is failing. This is the official documentation of the PIL that asks you to send a fill value.
Upvotes: 2
Views: 735
Reputation: 123463
The following works for me:
from PIL import Image, ImageOps
img = Image.open('skooter.png')
x, y = 0, 0
pix = img.load()
img2 = ImageOps.expand(img, border=10, fill=pix[x,y])
img2.show()
Result:
Upvotes: 1