JPG with Clipping Path to PNG with 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?".
silver6523

JPG with Clipping Path to PNG with transparency

Post by silver6523 »

What I want to do is trimming a JPG to its clipping path and setting everything outside the clipping path to transparency. The new file should be a PNG.

For example:
I have a picture with a bottle. The bottle is in the middle of the image an its edges does not touch the corner of the pictures. The bottle is outlined by a clipping path and now i want to create a new file with nothing more than this bottle. Now the bottle should touch the corner of the new picture.

I'm working with ImageMagick (Version 6.3.0) and tried this one: convert src.jpg -clip -trim dst.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: JPG with Clipping Path to PNG with transparency

Post by fmw42 »

Post a link to your jpg image which has the clipping path in it.
silver6523

Re: JPG with Clipping Path to PNG with transparency

Post by silver6523 »

Here is the JPG-File I want to clip to a transparent background:

http://rene.ateam.de/bild.JPG
silver6523

Re: JPG with Clipping Path to PNG with transparency

Post by silver6523 »

btw.:

"convert bild.JPG -clip -background transparent test.png"

results in an file where the clipped picture is on a black background (instead of a transparent one)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: JPG with Clipping Path to PNG with transparency

Post by snibgo »

This will do it:

/usr/bin/convert bild.JPG -alpha set -channel alpha -clip -negate temp.png
/usr/bin/convert temp.png -channel Alpha -negate c.png

Smarter folks than me will simplify it.

Edit: +trim +repage after the final -negate, if you want.
snibgo's IM pages: im.snibgo.com
silver6523

Re: JPG with Clipping Path to PNG with transparency

Post by silver6523 »

what i get is: unrecognized option `-alpha'.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: JPG with Clipping Path to PNG with transparency

Post by snibgo »

It's fine on 6.4.5. Your version is very old; I suggest you upgrade it and try again.
snibgo's IM pages: im.snibgo.com
shellynne7

Re: JPG with Clipping Path to PNG with transparency

Post by shellynne7 »

Thank you for the original post. It has been most helpful. I've been able to use that set of commands to successfully convert EPS files with clipping paths to transparent-background PNG files locally on two Macs (one running Snow Leopard, and one considerably older than that.) Both machines that work are using 6.6.2.7 and were built from source to include several other libraries. I then built IM on a linux box here, using the same version of those same libraries, and using IM 6.6.2.10. In those files, the transparency isn't working. When I open and get the details on the file created after the first step on the new (broken) machine, I'm getting:
Alpha:
min: 0 (0)
max: 0 (0)
mean: 0 (0)

For the one that works, I'm getting:
Alpha:
min: 0 (0)
max: 255 (1)
mean: 70.1693 (0.275174)

Is there possibly an issue with 6.6.2.10 (or .8 / .9)? Or is there some other library I need to watch out for on this new box. I've listed the libraries I used for the IM builds below.

libpng-1.4.3
jpeg-8a
lcms-1.19
ghostscript-8.71
freetype-2.3.12
libwmf-0.2.8.4
tiff-3.9.4

Thanks in advance for any insights you might have!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: JPG with Clipping Path to PNG with transparency

Post by fmw42 »

on older versions of IM -matte is the same as -alpha set, as I recall,

see http://www.imagemagick.org/Usage/basics/#alpha
shellynne7

Re: JPG with Clipping Path to PNG with transparency

Post by shellynne7 »

I'm not really on an older version (or that old, at least. The versions I'm on are only a couple of months old or less). The machine that is working fine using the original post's recommendation is 6.6.2-7, and the machine that isn't working is running 6.6.2-10. I'm doubting it's an issue with the commands working differently between the two versions. Rather, I suspect there is some sort of library that I already had installed on one machine but didn't have on the new machine. But I'm not sure what that could be, and I'm looking for ideas on whether there are any libraries that would affect alpha channel output.

My next step is to try to downgrade the non-working machine back to 6.6.2-7 to isolate whether that is the problem. As I mentioned, I highly doubt it is, but if there are no obvious libraries or other issues (mac osx vs. linux) anyone might suspect, then I'll go down that route to see for sure.

Thanks in advance!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: JPG with Clipping Path to PNG with transparency

Post by fmw42 »

silver6523 wrote:what i get is: unrecognized option `-alpha'.
What is the full command line that produces this error?
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: JPG with Clipping Path to PNG with transparency

Post by Drarakel »

silver6523 is not around anymore, Fred. (And probably his problem is already solved.) :wink:

@shellynne7:
I don't think that version 6.6.2-10 has an issue. But, yes, other things could be involved, especially with EPS files (Ghostscript).
Can you post the commandline that you were using and a link to your EPS file (and perhaps your output file)? That would make it easier for us. And what is the "original post" you're refering to? You don't mean 'convert src.jpg -clip -trim dst.png' (from the original post), do you?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: JPG with Clipping Path to PNG with transparency

Post by fmw42 »

silver6523 is not around anymore, Fred. (And probably his problem is already solved.)
Sorry, I had not realized that someone had tacked onto this post. You are on top of it, so I will bow out. Thanks.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: JPG with Clipping Path to PNG with transparency

Post by anthony »

silver6523 wrote:what i get is: unrecognized option `-alpha'.
Use the older option -matte instead then.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
shellynne7

Re: JPG with Clipping Path to PNG with transparency

Post by shellynne7 »

Thanks for your response.

I'm using the following commands:
convert 1031517_A.eps -alpha set -channel alpha -clip -negate Temp1/1031517_A.eps.png;
convert Temp1/1031517_A.eps.png -channel Alpha -negate Temp2/1031517_A.eps.png;

I've attached the source file, as well. As I mentioned, it's working fine on the two macs I have set up, but on the linux box I set up, that file that ends up in the Temp1 folder in this command contains no alpha channel values when I run it through the linux set up, so, subsequently, the final image in the Temp2 folder does not have a transparent background. When I run it through the macs, the file in Temp1 has a black background with a grey knockout inside the clipping path, and the Temp2 output has the original contents from within the clipping path on a transparent background (the desired outcome).

Please let me know if there's anything else I can provide as to server set-up or if there are problems you see with the way I'm converting these files to get the desired results.

Source Image: http://ackappdev.brandconstructionkit.c ... 1517_A.eps

Thanks so much for your time!
Post Reply