Jpeg clipping path transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
snibgo
Posts: 9253
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Jpeg clipping path transparency

Post by snibgo » 2017-04-21T03:39:59-07:00

Andreas1974 wrote:... I get an image with the car part transparent (hiding the car completely).
Strange, that's the opposite to my result. I don't know which is correct. So removing "-channel A -negate +channel" should give you the car, with transparent background.

You seem to be using IM 7.0.5-4. What is your SVG renderer?
Andreas1974 wrote:It's obvious that the clipping path does not adapt to the trimmed size.
Yes, that is true. IM is a raster processor, not a vector processor. Operations that transform the raster image geometry won't change cliping path geometry. Adding that facility to IM would be a major task.
snibgo's IM pages: im.snibgo.com

Andreas1974
Posts: 4
Joined: 2017-04-20T07:53:34-07:00
Authentication code: 1151

Re: Jpeg clipping path transparency

Post by Andreas1974 » 2017-04-21T04:56:11-07:00

Yes it's 7.0.5-4. I accidentally got that part into the code sample above. It's the standalone version, just a zip archive that I downloaded and unpacked to a folder.
How do I find out what SVG renderer ImageMagick use, that you ask for?

Removing "-channel A -negate +channel" gives me an image that is fully transparent (nothing but transparency).

Could it be that I'm missing some component that is needed for this kind of masking?

snibgo
Posts: 9253
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Jpeg clipping path transparency

Post by snibgo » 2017-04-21T05:34:36-07:00

Andreas1974 wrote:How do I find out what SVG renderer ImageMagick use, that you ask for?
The renderer used is either Inkscape (as external delegate, ie a separate program), or RSVG or MSVG (both as internal delegates, built-in to IM). Generally, Inkscape is slowest but most correct.

"convert -version" will say whether RSVG is a built-in delegate. MSVG is always built-in.

"convert -verbose old_trans_car_multiple_clips_added_space_topleft.jpg {... etc}", with "-verbose", will say if it is trying to use Inkscape.
snibgo's IM pages: im.snibgo.com

snibgo
Posts: 9253
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Jpeg clipping path transparency

Post by snibgo » 2017-04-21T06:00:43-07:00

Andreas1974 wrote:Could it be that I'm missing some component that is needed for this kind of masking?
To investigate clipping problems, we can break down the steps. First, tell IM to read the clip path and output it as an SVG file:

Code: Select all

identify -format "%[8BIM:1999,2998:#1]" old_trans_car_multiple_clips.jpg  1>ec.svg
Then rasterize that SVG file:

Code: Select all

convert ec.svg x.png
With IM v6.9.5-3 and Inkscape 0.91, I get a black car and box, and white background (and anti-aliasing between them).

If the image is distorted geometrically, the same distortion can easily be applied to the rasterization of the clip path (x.png). The result can then be vectorized, and this can be done with IM in a rather complex script.
snibgo's IM pages: im.snibgo.com

Andreas1974
Posts: 4
Joined: 2017-04-20T07:53:34-07:00
Authentication code: 1151

Re: Jpeg clipping path transparency

Post by Andreas1974 » 2017-04-21T07:08:34-07:00

I've got RSVG in the "delegates (built-in)" list that showed up when running the -version command. Verbose does not shows any text about inkscape.
I too got the black car and white background (with some grey anti-alias pixels on the edge between then) following your description.

What you describe about recreating the path from the raster image version of the path sounds interesting.

But (I'm guessing now)... the trim command, wouldn't that still be a problem? With -trim the image is "cropped" depending on the colour of the most top-left pixel, and you will never know how that "moves" the contents of the image, right? If there is a spot of other colour outside the path, the trim command will stop at that. And the clipping path might surround a smaller part of the image.

Post Reply