TIF to PNG with trim + clip = loss of 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?".
Post Reply
bsArithnea
Posts: 8
Joined: 2017-02-09T06:22:53-07:00
Authentication code: 1151

TIF to PNG with trim + clip = loss of transparency

Post by bsArithnea »

Hello,

i have a tiff image, which has a clipping path (and as far as i can tell, it is already transparent).

This command, does its job perfectly fine

Code: Select all

convert apu80365.tif[0] -alpha transparent -clip -alpha opaque clipped.png
Also, if i do this:

Code: Select all

convert apu80365.tif[0] -trim +repage trimmed.png
The result is perfectly fine, the image is trimmed, and it kept the current state (is transparent)

if i combine these commands:

Code: Select all

convert apu80365.tif[0] -alpha transparent -clip -alpha opaque -trim clipped.png
i lose the transparency and the image is black or white (depends on cmyk/srgb)

The example image is here:
https://owncloud.arithnea.de/public.php ... c46c1a811c

thank you very much in advance for your help.

My IM Version:

Code: Select all

Version: ImageMagick 7.0.3-8 Q16 x64 2016-11-24 http://www.imagemagick.org
Best Regards,

Bernhard
Last edited by bsArithnea on 2017-08-07T00:23:47-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIF to PNG with trim + clip = loss of transparency

Post by fmw42 »

You need to reset the page geometry using +repage after a trim.

Code: Select all

convert apu80365.tif[0] -alpha transparent -clip -alpha opaque -trim +repage clipped
bsArithnea
Posts: 8
Joined: 2017-02-09T06:22:53-07:00
Authentication code: 1151

Re: TIF to PNG with trim + clip = loss of transparency

Post by bsArithnea »

Hello fmw42,

thanks for your reply.

it didnt work with repage, the background is still black for me.

Code: Select all

convert apu80365.tif[0] -alpha transparent -clip -alpha opaque -trim +repage asdf.png
Best Regards,

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

Re: TIF to PNG with trim + clip = loss of transparency

Post by fmw42 »

Upgrade your Imagemagick version to the latest and try again. Or post your tiff file to some free hosting service that will not reformat your tiff file, such as dropbox.com and put the URL here so we can test it.
bsArithnea
Posts: 8
Joined: 2017-02-09T06:22:53-07:00
Authentication code: 1151

Re: TIF to PNG with trim + clip = loss of transparency

Post by bsArithnea »

i ve already uploaded the image to our owncloud server and posted the link in the first post. i have trouble finding a host which accepts 13 MB TIFF images.

I ve tried it with the latest version of imagemagick:

Code: Select all

"C:\Program Files\ImageMagick-7.0.6-Q16\magick.exe" apu80365.tif[0] -alpha transparent -clip -alpha opaque -trim +repage asdf1.png

Code: Select all

Version: ImageMagick 7.0.6-5 Q16 x64 2017-08-03 http://www.imagemagick.org

ive tried it with rgb/cmyk color profiles, then i get a white background instead of black

Code: Select all

"C:\Program Files\ImageMagick-7.0.6-Q16\magick.exe" apu80365.tif[0] +profile 'icc,icm' -profile ISOcoated_v2_eci.icc -profile sRGB_IEC61966-2-1_black_scaled.icc +profile 'icc,icm' -alpha transparent -clip -alpha opaque -trim +repage asdf1.png
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: TIF to PNG with trim + clip = loss of transparency

Post by GeeMack »

bsArithnea wrote: 2017-08-07T00:14:46-07:00it didnt work with repage, the background is still black for me.

Code: Select all

convert apu80365.tif[0] -alpha transparent -clip -alpha opaque -trim +repage asdf.png
Put "-background none" in your command.

Code: Select all

convert apu80365.tif[0] -alpha transparent -background none -clip -alpha opaque -trim clipped.png
That results in a transparent background for me using IM 6.9.8-10 or IM 7.0.6-5 (magick ...) from a Windows 10 command prompt.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIF to PNG with trim + clip = loss of transparency

Post by fmw42 »

This command works fine for me on IM 6.9.6.5 Q16 Mac OSX Sierra.

Code: Select all

convert apu80365.tif[0] -alpha transparent -clip -alpha opaque -trim +repage clipped.png
On IM 7.0.6.5, it does leave a black background. This would appear to be a bug in IM 7.

However, GeeMack's solution of adding -background none, seems to work for me in IM 7.

Code: Select all

magick apu80365.tif[0] -alpha transparent -background none -clip -alpha opaque -trim +repage clipped.png
bsArithnea
Posts: 8
Joined: 2017-02-09T06:22:53-07:00
Authentication code: 1151

Re: TIF to PNG with trim + clip = loss of transparency

Post by bsArithnea »

Hello and thank you very much for your help,

i ve been a few days off, sorry for the late reply

Ive tried it with -background none (with the latest version of IM) and it worked, the background is transparent again.

Code: Select all

"C:\Program Files\ImageMagick-7.0.6-Q16\magick.exe" apu80365.tif[0] +profile 'icc,icm' -profile ISOcoated_v2_eci.icc -profile sRGB_IEC61966-2-1_black_scaled.icc +profile 'icc,icm' -alpha transparent -background none -clip -alpha opaque -trim +repage asdf1.png
Best Regards,

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

Re: TIF to PNG with trim + clip = loss of transparency

Post by snibgo »

Note that "-clip" applies to all following operations. See http://www.imagemagick.org/script/comma ... s.php#clip

It is good practice when you have "-clip" to always have "+clip" somewhere after it, when you no longer need to apply the clipping path to operations.
snibgo's IM pages: im.snibgo.com
bsArithnea
Posts: 8
Joined: 2017-02-09T06:22:53-07:00
Authentication code: 1151

Re: TIF to PNG with trim + clip = loss of transparency

Post by bsArithnea »

snibgo wrote: 2017-08-21T02:45:59-07:00 Note that "-clip" applies to all following operations. See http://www.imagemagick.org/script/comma ... s.php#clip

It is good practice when you have "-clip" to always have "+clip" somewhere after it, when you no longer need to apply the clipping path to operations.
Thanks for the hint!

Best Regards,

Bernhard
Post Reply