-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The fill color in Image.transform doesn't work. #428
Comments
Are you sure |
|
@wiredfool Thanks, i had also traced/checked that already. That's why i was confused, about how to move forward after @aclark4life 's comment :) Are you guys considering this a non-issue, or not expecting to fix it or waiting for effbot to fix? There are ofcourse workarounds, using masks, and pastes. But this would have been nice if it worked by itself. |
Generally I'd consider the behavior of an unwired, undocumented option a won't fix. I'm not sure why the option is there, it's likely to be something back from the PIL era. Additionally, I strongly suspect that the actual function is redundant now that we're memsetting new images to 0. I think the code would do what you wanted it to do if the fill was disabled at the _imaging.c level, and a fill color was added to the new Image line in https://github.com/python-imaging/Pillow/blob/master/PIL/Image.py#L1634 . I'd lean to making the argument fillcolor, since it's got a different meaning than the current ignored fill parameter. |
👍 Agree with the fillcolor suggestion, hopefully i or someone else can find the time to add the feature. |
So is it possible to set the fill to transparent? |
The default parameter for fill is 1 and setting it to 0 does nothing. |
Here is a workaround: # original image
img = Image.open('test.png')
# converted to have an alpha layer
im2 = img.convert('RGBA')
# rotated image
rot = im2.rotate(22.2, expand=1)
# a white image same size as rotated image
fff = Image.new('RGBA', rot.size, (255,)*4)
# create a composite image using the alpha layer of rot as a mask
out = Image.composite(rot, fff, rot)
# save your work (converting back to mode='1' or whatever..)
out.convert(img.mode).save('test2.bmp') |
Even better: Image.paste(im, box=(x,y), mask=im) |
@RickyHan Hey, I am currently fighting with the same issue. Did you figure out a performant workaround for this? Unfortunately I can't deduce what you did exactly from your last comment :) |
@Zerphed not sure about performance. regarding the above line, |
@RickyHan Ahh, I see. I just realized that since I don't need the alpha channel, and since everything over the image boundaries is memset to 0, I can get a mask of the outside image pixels by adding an alpha channel to my image before the transform and setting alpha for all pixels to 255. This way all the pixels outside the image will get alpha channel values of 0 and I can extract a mask to replace those values with the value of my choosing :). Thanks for the tip though! |
For those finding themselves here wondering about setting fill color, use the transd = img.transform(size, Image.PERSPECTIVE, coeffs,
Image.BICUBIC, fillcolor=(150, 10, 30)) |
Exactly what the issue header says, the
fill
option inImage.transform()
doesn't seem to work. Here is what i have been trying:The transform works perfectly, it's only the fill color that doesn't work, no matter what color i try, it always ends up being black.
The text was updated successfully, but these errors were encountered: