PNG trim to clipping path with transparent background
PNG trim to clipping path with transparent background
Hello
I'm trying to create a PNG with a transparent background from a jpeg, which must be trimmed to the area of the active clipping path.
The command below works fine in 'ImageMagick 6.7.8-9 2016-06-03 Q16', but with 'ImageMagick 7.0.7-3 Q16 x86_64 2017-09-17' I just get a 1x1 pixel file:
/usr/bin/convert -units PixelsPerInch test_file_1.jpg -filter lanczos -density 200 +clip-path "#1" -fuzz %1 +transparent black -trim +repage PNG:crop_test_file_1.png
Hope someone can help?
Thanks
Link to sample file is:
https://www.dropbox.com/sh/51z3ghlp8pcg ... RhkMa?dl=0
Image Magick Version is:
ImageMagick 7.0.7-3 Q16 x86_64 2017-09-17
Linux Version is:
Red Hat Enterprise Linux Server release 7.4 (Maipo)
I'm trying to create a PNG with a transparent background from a jpeg, which must be trimmed to the area of the active clipping path.
The command below works fine in 'ImageMagick 6.7.8-9 2016-06-03 Q16', but with 'ImageMagick 7.0.7-3 Q16 x86_64 2017-09-17' I just get a 1x1 pixel file:
/usr/bin/convert -units PixelsPerInch test_file_1.jpg -filter lanczos -density 200 +clip-path "#1" -fuzz %1 +transparent black -trim +repage PNG:crop_test_file_1.png
Hope someone can help?
Thanks
Link to sample file is:
https://www.dropbox.com/sh/51z3ghlp8pcg ... RhkMa?dl=0
Image Magick Version is:
ImageMagick 7.0.7-3 Q16 x86_64 2017-09-17
Linux Version is:
Red Hat Enterprise Linux Server release 7.4 (Maipo)
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: PNG trim to clipping path with transparent background
Your command, on your file, works fine for me with IM v6.9.5-3 and v7.0.3-5 (using "magick"). I get the shirt surrounded by a transparent background.
For v7, I suggest you use "magick", not "convert".
If that doesn't help, simplify your command by removing operations to find out where it is going wrong.
For v7, I suggest you use "magick", not "convert".
If that doesn't help, simplify your command by removing operations to find out where it is going wrong.
snibgo's IM pages: im.snibgo.com
Re: PNG trim to clipping path with transparent background
Thanks for your response.
I forgot to post the error I'm getting before, but here the same message using 'magick' instead of convert:
magick: geometry does not contain image `test_file_1.jpg' @ warning/attribute.c/GetImageBoundingBox/240.
From looking into this before I did this post, this message is caused by the trim option according to the command line option documentation, so it looks like either the '+transparent black' operation or the +clip-path "#1" operation isn't working .
Changing the colour value from 'black' to 'white' stops the error message appearing, but doesn't produce the final result I want, which is if the colour isn't black outside the clipping path make it transparent.
From my understanding of the documentation, this should be working, but isn't.
Can you try using the same version of Image Magick I'm using?
I forgot to post the error I'm getting before, but here the same message using 'magick' instead of convert:
magick: geometry does not contain image `test_file_1.jpg' @ warning/attribute.c/GetImageBoundingBox/240.
From looking into this before I did this post, this message is caused by the trim option according to the command line option documentation, so it looks like either the '+transparent black' operation or the +clip-path "#1" operation isn't working .
Changing the colour value from 'black' to 'white' stops the error message appearing, but doesn't produce the final result I want, which is if the colour isn't black outside the clipping path make it transparent.
From my understanding of the documentation, this should be working, but isn't.
Can you try using the same version of Image Magick I'm using?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: PNG trim to clipping path with transparent background
Sorry, I don't have any later versions.
An alternative to simplifying your command is: insert "+write XX.png" operations between each of your operations, like this:
-units PixelsPerInch test_file_1.jpg -filter lanczos -density 200 +clip-path "#1" +write x0.png -fuzz %1 +transparent black +write x1.png -trim +write x2.png +repage PNG:crop_test_file_1.png
An alternative to simplifying your command is: insert "+write XX.png" operations between each of your operations, like this:
-units PixelsPerInch test_file_1.jpg -filter lanczos -density 200 +clip-path "#1" +write x0.png -fuzz %1 +transparent black +write x1.png -trim +write x2.png +repage PNG:crop_test_file_1.png
snibgo's IM pages: im.snibgo.com
Re: PNG trim to clipping path with transparent background
Thanks that's helped.
I've run that with version 6.7.8-9 and 7.0.7-3.
With 6.7.8-9 the x1.png image is correct, the t-shirt surrounded by a transparent background before it gets trimmed, however with version 7.0.7-3 the x1.png image is completely transparent with no sign of the t-shirt.
Is this therefore a bug?
I've run that with version 6.7.8-9 and 7.0.7-3.
With 6.7.8-9 the x1.png image is correct, the t-shirt surrounded by a transparent background before it gets trimmed, however with version 7.0.7-3 the x1.png image is completely transparent with no sign of the t-shirt.
Is this therefore a bug?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PNG trim to clipping path with transparent background
try using PNG32: rather than PNG for your output if you want it to have transparency
Re: PNG trim to clipping path with transparent background
Thanks for the suggestion, but that didn't make any difference.
The transparency is being created. It's just that the original image inside the clipping path isn't retained, so I've just got a completely transparent image with no content.
The transparency is being created. It's just that the original image inside the clipping path isn't retained, so I've just got a completely transparent image with no content.
Re: PNG trim to clipping path with transparent background
Hi
Can someone tell me if to get this reported as a bug do I need to repost this in the Bugs forum?
Thanks
Can someone tell me if to get this reported as a bug do I need to repost this in the Bugs forum?
Thanks
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: PNG trim to clipping path with transparent background
ImageMagick v7 handles alpha operations differently than IMv6. Using IM 7.0.7-3 in Windows 10 I can get the result you want by running this command...
Code: Select all
magick test_file_1.jpg -alpha set -background none ^
-clip-path "#1" -fuzz 1% -transparent black -trim crop_test_file_1.png
To run it in a *nix shell you'd have to change the continued line caret "^" to a backslash "\" or just run it all on one line.
Re: PNG trim to clipping path with transparent background
Thanks GeeMack, that's very helpful.
The original image works fine now as you say. However I've tried it with a second image and although the background is made transparent, the trim option isn't being applied. I've tried adding +repage after the -trim, but that hasn't made any difference.
Do you have any idea why that would be happening? I've added a test_file_2 image to the drop box link I shared.
Thanks again
The original image works fine now as you say. However I've tried it with a second image and although the background is made transparent, the trim option isn't being applied. I've tried adding +repage after the -trim, but that hasn't made any difference.
Do you have any idea why that would be happening? I've added a test_file_2 image to the drop box link I shared.
Thanks again
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PNG trim to clipping path with transparent background
This command works fine for me on IM 7.0.7.3 Q16 Mac OSX
Code: Select all
magick test_file_1.jpg -alpha transparent -clip -alpha opaque +clip -strip -trim +repage test_file_1_clip.png
magick test_file_2.jpg -alpha transparent -clip -alpha opaque +clip -strip -trim +repage test_file_2_clip.png
Re: PNG trim to clipping path with transparent background
Thank you
That works perfectly.
Much appreciated
That works perfectly.
Much appreciated