Page 1 of 1

Problems creating transparent PNG from JPG with clip path

Posted: 2012-11-22T08:56:15-07:00
by jd.wiese
Hi!

I have JPG image with a clip path and want to create a PNG with everthing outside the path being transparent.
This is the image I use: http://www.netgroup.de/tl_files/downloa ... 924200.jpg

This is the command I use:
convert 43924200.jpg -alpha transparent -clip -alpha opaque 43924200.png

The command above works perfect with the windows 6.8.0-5 version of ImageMagick. Here is the result:
http://www.netgroup.de/tl_files/downloa ... -5_win.png

The probem is, I have to use ImageMagic on CentOS 6.3. So I tried the 6.5.4-7 version of ImageMagick that comes with CentOS 6.3. The result is nearly perfect, only the "eyes" of the scissors are not transparent. Here is the result: http://www.netgroup.de/tl_files/downloa ... centos.png

I then installed a fresh CentOS and built a recent ImageMagick RPM using the descriptions from http://www.imagemagick.org/Usage/api/#building and http://en.citizendium.org/wiki/User:Dan ... k_6.6.2-10. Everything compiled and installed fine, but the command above issued the following error "convert: image size differs `43924200.jpg' @ error/image.c/SetImageClipMask/2392". The resulting image isn't transparent at all: http://www.netgroup.de/tl_files/downloa ... centos.png

And at this point I'm stuck. Is this an error in ImageMagick or am I using it wrong?

There is another topic with a similar problem viewtopic.php?f=3&t=22240 but without a solution so far.

Any help would be appreciated.

Regards

JD

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2012-11-25T18:21:46-07:00
by fmw42
I can verify your results. It works fine for me under IM 6.8.0.6 Q16 Mac OSX Snow Leopard, but under 6.6.0-10 I get the following error messages:


convert: unable to load module `/Users/fred/Applications/ImageMagick-6.6.0-10/coders/svg.la': file not found @ error/module.c/OpenModule/1229.
convert: no decode delegate for this image format `43924200.jpg#1' @ error/blob.c/BlobToImage/348.
convert: unable to load module `/Users/fred/Applications/ImageMagick-6.6.0-10/coders/svg.la': file not found @ error/module.c/OpenModule/1229.
convert: no decode delegate for this image format `43924200.jpg#1' @ error/blob.c/BlobToImage/348.
convert: unable to load module `/Users/fred/Applications/ImageMagick-6.6.0-10/coders/svg.la': file not found @ error/module.c/OpenModule/1229.
convert: no decode delegate for this image format `43924200.jpg#1' @ error/blob.c/BlobToImage/348.


This seems to be associated with the SVG code. This is likely an issue of the version of IM you are using and any relevant support delegates needed by SVG. However, I am not really an expert on these matters. So you may need to hear back from the IM developers. Or just upgrade if you can.

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2012-12-24T03:10:08-07:00
by jd.wiese
Today I tried again with the latest ImageMagick version (6.8.1-2). But still the same problem:

convert 43924200.jpg -alpha transparent -clip -alpha opaque 43924200.png
convert: image size differs `43924200.jpg' @ error/image.c/SetImageClipMask/2395.

Any help or hint would be appreciated.

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2012-12-24T07:30:24-07:00
by magick
Curious, your command worked for us with ImageMagick 6.8.1-2. ImageMagick needs to render the SVG clip mask before it can be applied. Which suggests your SVG renderer is not working properly. Let's see the SVG renderer we're using:
  • -> convert -version
    Version: ImageMagick 6.8.1-3 2012-12-24 Q16 http://www.imagemagick.org
    Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
    Features: OpenMP Modules
    Delegates: bzlib djvu mpeg fftw fontconfig freetype jbig jng jp2 jpeg lcms lqr lzma openexr pango png ps tiff x xml zlib
Looks like we're using Pango. The choices are the internal renderer (MVG), Pango, Inkscape, or RSVG. Let's try extracting the clip path and rendering it from the command line:
  • identify -format '%[8BIM:1999,2998:#1]' 43924200.jpg > 43924200.svg
    convert 43924200.svg info:
    43924200.svg SVG 1000x2700 1000x2700+0+0 8-bit sRGB 60.5KB 0.060u 0:00.060
    identify 443924200.jpg
    43924200.jpg JPEG 1000x2700 1000x2700+0+0 8-bit sRGB 586KB 0.000u 0:00.000
Both the clip mask and image are the same size as required to clip an image. What results do you get?

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2013-02-16T15:25:43-07:00
by jd.wiese
Hi!

Thanks for your response and sorry for the late reply. Here is what I get:

# convert -version
Version: ImageMagick 6.8.3-1 2013-02-16 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP Modules
Delegates: bzlib djvu fontconfig freetype gslib jng jp2 jpeg lcms openexr pango png ps rsvg tiff wmf x xml zlib

# convert 43924200.svg info:
43924200.svg SVG 1250x3375 1250x3375+0+0 16-bit sRGB 6.7KB 0.120u 0:00.129

# convert 43924200.jpg info:
43924200.jpg JPEG 1000x2700 1000x2700+0+0 8-bit sRGB 586KB 0.040u 0:00.049

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2013-02-16T15:38:17-07:00
by jd.wiese
Hi again,

I uninstalled librsvg2-devel and rebuilt the whole thing. Now the "convert info:" shows the same sizes for the SVG and the JPG file. And even better, the conversion gives me the correct result :-) Thank you very much for pointing me into the right direction!

Does that mean that there is an error in the librsvg2-devel?
Can I mark this topic as "solved"?

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2013-02-20T23:46:41-07:00
by georgeleo104
at this point I'm stuck. Is this an error in ImageMagick or am I using it wrong?

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2013-02-24T11:32:52-07:00
by Andreas
I can verify the problems reported by jd.wiese. But only with the imagemagick version equal and above 6.7.9-10 and compiled with rsvg support. The version 6.7.8 compiled with rsvg support worked. i think the problem is
2012-10-01 6.7.9-10 Cristy <quetzlzacatenango@image...>
SVG specs says "1pt" equals "1.25px" (reference viewtopic.php?f=3&t=21967).
as described in the http://imagemagick.org/script/changelog.php

The version equal and above 6.7.9.10 without rsvg support, which means that the inbuilt msvg interpreter (which is limited in comparison to the rsvg afaik) is used, works properly. the problem becomes clear:

# /usr/local/ImageMagick-6.7.8/bin/identify -format '%[8BIM:1999,2998:#1]' 43924200.jpg > 43924200.svg
# /usr/local/ImageMagick-6.7.8/bin/identify 43924200.svg
43924200.svg SVG 1000x2700 1000x2700+0+0 8-bit DirectClass 6.7KB 0.000u 0:00.000
# /usr/local/ImageMagick-6.7.8/bin/identify 43924200.jpg
43924200.jpg JPEG 1000x2700 1000x2700+0+0 8-bit DirectClass 586KB 0.000u 0:00.009

# /usr/local/ImageMagick-6.7.9/bin/identify -format '%[8BIM:1999,2998:#1]' 43924200.jpg > 43924200.svg
# /usr/local/ImageMagick-6.7.9/bin/identify 43924200.svg
43924200.svg SVG 1250x3375 1250x3375+0+0 8-bit sRGB 6.7KB 0.000u 0:00.000
# /usr/local/ImageMagick-6.7.9/bin/identify 43924200.jpg
43924200.jpg JPEG 1000x2700 1000x2700+0+0 8-bit sRGB 586KB 0.000u 0:00.000

as you see the mask/svg from 6.7.9 with rsvg is factor 1.25 compared to the mask from 6.7.8 with rsvg or 6.7.9 with msvg.

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2013-02-26T14:11:27-07:00
by magick
We can reproduce the problem you posted and have a patch in ImageMagick 6.8.2-6 Beta available by sometime tomorrow. Thanks.

Re: Problems creating transparent PNG from JPG with clip pat

Posted: 2013-02-28T07:23:23-07:00
by Andreas
For me is the problem with ImageMagick-6.8.3-6 solved. Thanks