Re: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL?
On 4/10/07, César Pérez <[EMAIL PROTECTED]> wrote: > Hi, > I am new to this list but and i have a small problem with PIL. > > I am looking for a function that works like composite does in > imagemagick. [..snip..] > from PIL import Image > > dtop = Image.open("dtop.png") > frame = Image.open("frame.png") > > dtop.paste(frame,(0,0),frame) > dtop.save("test.png") > > I tried every form of paste but I always get this result or worst. The problem you have happens because alpha channel of images *also* gets composited using the mask you specified. To do it right you actually need to split image, save target image alpha channel and after compositing merge it back using original alpha channel: from PIL import Image dtop = Image.open("dtop.png") frame = Image.open("frame.png") assert dtop.mode == "RGBA" r,g,b,a = dtop.split() dtop = Image.merge("RGB", (r,g,b)) dtop.paste(frame,(0,0),frame) r,g,b = dtop.split() dtop = Image.merge("RGBA", (r,g,b,a)) dtop.save("test.png") Best regards, Alexey. ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] seeking guidance on image conversion
Brad Allen wrote: Hello, Hello, I am new to this list, having gotten involved in a project at work that uses PIL. I am looking for guidance in a few areas, hoping to find a better way than our methods for manipulating images. We have a workflow which involves converting various file formats to TIFF, and allowing them to be viewed and manipulated in a wxPython app. A solution can be that already replied. Another can be to use freeimagepy that is born because PIL doesn't handle, like I need, the g3, g4 and multipage tiff files. I create it, and I use it, for hylapex, a fax client that need to work with fax files, that are in g3 and g4 format! My old solution, like you wrote, was use the tiff gnuwin32 files, but work with a dll a some python (ctypes) code, are better! :) Here is a list of the image conversions we are performing: * One of the Python scripts is calling Linux tiffsplit command to convert multipage faxes (TIFF group 4 compressed) into collections of single page TIFFs. Ok with freeimagepy (convertToMultiPage and convertToSinglePages) * The wxPython app is calling GnuWin32's tiffcp.exe to rejoin single page TIFFs into multipage TIFFs. Like above * We're calling the ImageMagick convert command to make PDFs into TIFFs. I use ghostscript (present on linux, but not on win, where I need it and install it every time) for do all the work. It's not so difficult to do the work. If you need some questions, I'm here. * We're calling an Open Office 1.1.5 command line tool to convert Word documents to PDF (which then get converted to TIFF by ImageMagick). Like said, you can use pdfcreator or ghostscript itself, that has the psXXX and pdfXXX devices. In some of these cases there may be C libraries we could wrap, but if someone has already done that work or if there is a better approach I would be grateful to hear about it. My image library wrapper are there! If you want to contribute for add the part that I don't already wrap, contact me! Thanks! Bye, Michele smime.p7s Description: S/MIME Cryptographic Signature ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL?
Alexey Borzenkov wrote: > The problem you have happens because alpha channel of images *also* > gets composited using the mask you specified. To do it right you > actually need to split image, save target image alpha channel and > after compositing merge it back using original alpha channel: Alexey, I think you are completely right about the problem, but the solution can be quite a bit simpler: dtop = Image.open("dtop.png") frame = Image.open("frame.png") dtop.paste(frame.convert('RGB'), (0,0), frame) dtop.save("test.png") I would say that this alpha-merging quirk comes close to being a bug -- it's probably not what most people expect. douglas ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL?
Thanks to both of you and yes I was expecting the paste function to work just like a paste in any Image Editor. César On Wed, 2007-04-11 at 11:48 +1200, Douglas Bagnall wrote: > Alexey Borzenkov wrote: > > > The problem you have happens because alpha channel of images *also* > > gets composited using the mask you specified. To do it right you > > actually need to split image, save target image alpha channel and > > after compositing merge it back using original alpha channel: > > Alexey, I think you are completely right about the problem, but the > solution can be quite a bit simpler: > > dtop = Image.open("dtop.png") > frame = Image.open("frame.png") > > dtop.paste(frame.convert('RGB'), (0,0), frame) > dtop.save("test.png") > > > I would say that this alpha-merging quirk comes close to being a bug -- > it's probably not what most people expect. > > douglas > ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Help with PIL, Imagemagick Composite function in PIL?
On 4/11/07, Douglas Bagnall <[EMAIL PROTECTED]> wrote: > Alexey, I think you are completely right about the problem, but the > solution can be quite a bit simpler: > > dtop = Image.open("dtop.png") > frame = Image.open("frame.png") > > dtop.paste(frame.convert('RGB'), (0,0), frame) > dtop.save("test.png") Hmm... The good part I see in this solution is that when image is converted from RGBA to RGB it just so happens that its pixelsize is still 4 but 4th byte is filled with 255. Then paste_mask_RGBA kicks in, and if dtop has alpha channel it will composite its alpha channel with 255, decreasing dtop transparency where frame is not completely transparent. To be honest I'm not sure what is generally expected in this situation, though looking at the way antigrain does rgba blending I see that it essentially has this formula: a = a * (1 - alpha) + 1 * alpha Which is just the way it works in the code above (and absolutely not the way it'd worked in my code). So if this behavior is expected my example wouldn't even work as it should, thanks for showing that. :) Best regards, Alexey. ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig