-colorize loses transparency. Bug?

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
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

-colorize loses transparency. Bug?

Post by tkagerer »

Hey guys! I have this PNG file: http://loft9211.serverloft.de/icon.png (with transparency)

if i do

Code: Select all

convert icon.png -fill '#93117e' -colorize 100% output.png
I get this (http://loft9211.serverloft.de/output.png) on one server (ImageMagick 6.7.7-10 2012-11-06 Q16) and that (http://85.25.147.10/output.png) on the other server - what i expected (ImageMagick 6.6.0-4 2012-05-02 Q16)

Have there been changes between these versions or is this a bug and how can I get around that problem?

Thanks!

P.S.:
I found this thread: viewtopic.php?f=1&t=23552#p99415 where fmw42 suggests to use -alpha off and -alpha on

But if I use

Code: Select all

convert icon.png -alpha off -fill '#93117e' -colorize 100% -alpha on output.png
or

Code: Select all

convert -background transparent icon.png -alpha off -fill '#93117e' -colorize 100% -alpha on output.png
it doesn't work neither :?

P.S.S.:
This thread viewtopic.php?f=3&t=23370 is also about this topic and again

Code: Select all

 convert partiallytransparentimage -alpha off -fill red -colorize 100% -alpha on output
doesn't work neither ...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -colorize loses transparency. Bug?

Post by snibgo »

Taking http://85.25.147.10/output.png as the desired result, purple letters on a white background, I get that result using ...

Code: Select all

convert icon.png -alpha off -fill #93117e -colorize 100 -alpha on output.png
... for a variety of versions, including 6.6.0-8, 6.7.9-6 and 6.8.6-0.

Note that "-colorize" takes a number that is automatically a percentage. It shouldn't have a % sign, but it seems harmless.
snibgo's IM pages: im.snibgo.com
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

Re: -colorize loses transparency. Bug?

Post by tkagerer »

Thanks for your reply.

I just executed your command

Code: Select all

convert icon.png -alpha off -fill "#93117e" -colorize 100 -alpha on output2.png
and this is the result: http://loft9211.serverloft.de/output2.png - still w/o transparency :-/

Exact version information:

Version: ImageMagick 6.7.7-10 2012-11-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

Re: -colorize loses transparency. Bug?

Post by tkagerer »

So will I have to upgrade to a newer version or is there any workaround to archive the desired result?

I am using Debian 7.1 and I am not keen on upgrading to a newer version for one application if it is not absolutely necessary.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -colorize loses transparency. Bug?

Post by snibgo »

I don't have 6.7.7-10, but may be able to find a solution that does what you want on that version.

But I don't know what you want. icon.png has aliased black letters on a transparent background. The background is transparent black near the letters; otherwise transparent white.

What result do you want? Purple letters on a transparent background, or what?
snibgo's IM pages: im.snibgo.com
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

Re: -colorize loses transparency. Bug?

Post by tkagerer »

snibgo wrote:I don't have 6.7.7-10, but may be able to find a solution that does what you want on that version.

But I don't know what you want. icon.png has aliased black letters on a transparent background. The background is transparent black near the letters; otherwise transparent white.

What result do you want? Purple letters on a transparent background, or what?
Exactly! I want purple letters on a transparent background, yes :D
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -colorize loses transparency. Bug?

Post by snibgo »

Try:

Code: Select all

convert icon.png -fill #93117e -alpha off -opaque Black -alpha on output.png
snibgo's IM pages: im.snibgo.com
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

Re: -colorize loses transparency. Bug?

Post by tkagerer »

snibgo wrote:Try:

Code: Select all

convert icon.png -fill #93117e -alpha off -opaque Black -alpha on output.png
Thanks! That's it!

I tried opaque Black before, but i forgot to disable alpha.

Thank you very much!!
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

Re: -colorize loses transparency. Bug?

Post by tkagerer »

Just another issue...

If the image is grayscale this is the output http://loft9211.serverloft.de/output3.png

I tried to solve the problem by converting it to TrueColor, but my approach doesn't seem to work ...

Code: Select all

convert input.png -type TrueColorMatte -fill "#93117e" -alpha off -opaque Black -alpha on -define png:color-type=6 output3.png
Tom
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -colorize loses transparency. Bug?

Post by snibgo »

Apart from size, what's the difference between output3.png and output.png?
snibgo's IM pages: im.snibgo.com
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

Re: -colorize loses transparency. Bug?

Post by tkagerer »

snibgo wrote:Apart from size, what's the difference between output3.png and output.png?
Well the colorcode of output3.png is wrong, if I ask photoshop
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -colorize loses transparency. Bug?

Post by fmw42 »

You cannot trust PS because it may be changing the color profile. You need to be sure you are importing with the same color profile or lack of one. Open the Color Settings panel and be sure you know what is there.

You also have a very strange image. If you do


convert icon.png -alpha off icon_aoff.png
convert icon.png -alpha extract icon_alpha.png

You will see that the base image (aoff) is white with a black patch in the middle.
All the text is in the alpha channel as 8 bit gray.

Perhaps this is what you want

convert icon.png \( -clone 0 -fill "#93117e" -colorize 100 \) \( -clone 0 -alpha extract \) -delete 0 -alpha off -compose copy_opacity -composite result.png
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

Re: -colorize loses transparency. Bug?

Post by tkagerer »

fmw42 wrote:You cannot trust PS because it may be changing the color profile. You need to be sure you are importing with the same color profile or lack of one. Open the Color Settings panel and be sure you know what is there.

You also have a very strange image. If you do


convert icon.png -alpha off icon_aoff.png
convert icon.png -alpha extract icon_alpha.png

You will see that the base image (aoff) is white with a black patch in the middle.
All the text is in the alpha channel as 8 bit gray.
Well you guys helped me enough - so if this is not possible or you don't wanna waste any more time, I will stay with the fact, that one has to use RGB PNGs.

But if you want to still think about the problem: The output image obviously has another color (profile?)! This image is made for the web and the output image is lighter than it should be (I use Google Chrome - if this makes any difference?)...
fmw42 wrote: Perhaps this is what you want

convert icon.png \( -clone 0 -fill "#93117e" -colorize 100 \) \( -clone 0 -alpha extract \) -delete 0 -alpha off -compose copy_opacity -composite result.png
Mhh not really - now the image has a complet different color?
http://loft9211.serverloft.de/result.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -colorize loses transparency. Bug?

Post by snibgo »

tkagerer wrote:This image is made for the web and the output image is lighter than it should be (I use Google Chrome - if this makes any difference?)...
I don't have your old version of IM, or any version of PS, but it might be a gamma problem, aka RGB/sRGB. If so, then sprinkling "-set colorspace sRGB" or "-set colorspace RGB" in conversions might help.
snibgo's IM pages: im.snibgo.com
tkagerer
Posts: 9
Joined: 2013-07-15T05:02:59-07:00
Authentication code: 6789

Re: -colorize loses transparency. Bug?

Post by tkagerer »

snibgo wrote:
tkagerer wrote:This image is made for the web and the output image is lighter than it should be (I use Google Chrome - if this makes any difference?)...
I don't have your old version of IM, or any version of PS, but it might be a gamma problem, aka RGB/sRGB. If so, then sprinkling "-set colorspace sRGB" or "-set colorspace RGB" in conversions might help.
Damn that did it!

You guys are all wizards, thanks a lot! :D :D :D
Post Reply