Page 1 of 2

Dirty Transparency

Posted: 2010-07-06T04:32:41-07:00
by lorents
Good afternoon!
Prompt, please, as it is possible to make such through ImageMagick?

Dirty Transparency

Re: Dirty Transparency

Posted: 2010-07-06T10:43:27-07:00
by lorents
It is necessary to me, something on similarity of it
http://www.translate.ru/links/8020eb12

Re: Dirty Transparency

Posted: 2010-07-06T12:37:18-07:00
by fmw42
try


convert image.png \
\( -clone 0 -alpha extract \) \
\( -clone 0 -clone 1 -compose multiply -composite \) \
-delete 0 +swap -alpha off -compose copy_opacity -composite -depth 8 image_new.png

or

convert image.png \
\( -clone 0 -alpha extract \) \
\( -clone 0 -clone 1 -compose multiply -composite \) \
-delete 0 +swap -alpha off -compose copy_opacity -composite -define png:color-type=2 -define png:bit-depth=8 image_new.png

see http://www.imagemagick.org/Usage/formats/#png_write


This will make all the transparent pixels black.

If on windows, see http://www.imagemagick.org/Usage/windows/ for syntax differences with unix.

But I am not sure this will make the file smaller in IM. In fact, it may still be larger as IM is not very good at png optimization. You may still need to use one of the non-IM utilities to compress the png to get the benefit. See http://www.imagemagick.org/Usage/formats/#png_non-im

Let us know if this helps.

P.S. In IM you can remove the alpha channel to see if the transparent pixels are already black by

convert image.png -alpha off image_no_alpha.png

Re: Dirty Transparency

Posted: 2010-07-06T13:01:58-07:00
by snibgo
Does this do what is wanted?

convert image.png -background Black -alpha Background image_new.jpg

Re: Dirty Transparency

Posted: 2010-07-06T14:32:42-07:00
by fmw42
snibgo wrote:Does this do what is wanted?

convert image.png -background Black -alpha Background image_new.jpg

Alan,

Nice shortcut. But you really mean image_new.png.

convert image.png -background Black -alpha Background image_new.png

But I still get the same size output as input with yours or my first method and only a small decrease with my second method (via the -defines). I believe some external png optimising utility will be necessary to actually get the size reduction.

Fred

Re: Dirty Transparency

Posted: 2010-07-06T15:11:41-07:00
by snibgo
Yes, output should be to PNG, thanks Fred. (Can I have a new brain, please?)

I use pngcrush to compress pngs, but I don't know if it is better than the rest.

Re: Dirty Transparency

Posted: 2010-07-06T17:51:11-07:00
by fmw42
snibgo wrote: I use pngcrush to compress pngs, but I don't know if it is better than the rest.
Can you specify what file sizes before and after pngcrush with the before and after images from the black background processing?

Re: Dirty Transparency

Posted: 2010-07-06T20:01:50-07:00
by anthony
lorents wrote:Good afternoon!
Prompt, please, as it is possible to make such through ImageMagick?

Dirty Transparency
Basically Dirty transparency, is when the transparency has many color values! that its it contains a lot of fully-transparent junk colors.

The -alpha background setting will set all the fully-transparent colors to the current background color. A good background color is just black.

this and a few other techniques that do the same thing is given in
http://www.imagemagick.org/Usage/basics ... background

You can specify different compression types and techniques using -quality setting for PNG.
This is NOT a percentage! See http://www.imagemagick.org/Usage/formats/#png_quality

However pngcrush is still recommended as a final post-processing method.

You could generate a 'delegate' for pngcrush! Might make a good addition to the delegate configuration (and example of an output delegate)
http://www.imagemagick.org/Usage/files/#delegate_output

That same delegate could also include a convert command to automatically handle 'dirty transparency' too ;-)

If someone gives this a go, please contribute!

Re: Dirty Transparency

Posted: 2010-07-07T00:09:17-07:00
by lorents
I have not absolutely understood, how to me to make, that I have conceived.
I use Portable the version, and at me operating system Windows. And I should write a batch-file for this business

Re: Dirty Transparency

Posted: 2010-07-07T05:04:29-07:00
by snibgo
Using as input:
http://media.smashingmagazine.com/cdn_s ... ample1.png

dirty-tr-sample1.png is 75458 bytes.

Code: Select all

convert dirty-tr-sample1.png -background Black -alpha Background dirtyclean1.png
dirtyclean1.png is 29378 bytes.

Using pngcrush makes no significant difference for these files.

Re: Dirty Transparency

Posted: 2010-07-07T09:01:47-07:00
by lorents
Many thanks, all have turned out

Re: Dirty Transparency

Posted: 2010-07-07T09:15:03-07:00
by lorents
Whether prompt, please, as it is possible to learn is PNG a transparency, or not?

Re: Dirty Transparency

Posted: 2010-07-07T10:26:26-07:00
by fmw42
convert image.png -format "%A" info:

Will return True or False


see http://www.imagemagick.org/script/escape.php

Re: Dirty Transparency

Posted: 2010-07-07T10:40:03-07:00
by lorents
thanks

Re: Dirty Transparency

Posted: 2010-07-07T11:41:13-07:00
by lorents
Has noticed one strangeness into account PNG c a transparency.
If the picture is kept in PNG 32bit, and actually it PNG 24bit, i.e. in it there is no transparency. ImageMagick asserts that it is a picture with a transparency
Here a picture example
http://img2.immage.de/0707cddlogo.png