Dirty 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?".
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Dirty Transparency

Post by lorents »

Good afternoon!
Prompt, please, as it is possible to make such through ImageMagick?

Dirty Transparency
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Dirty Transparency

Post by lorents »

It is necessary to me, something on similarity of it
http://www.translate.ru/links/8020eb12
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dirty Transparency

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Dirty Transparency

Post by snibgo »

Does this do what is wanted?

convert image.png -background Black -alpha Background image_new.jpg
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dirty Transparency

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Dirty Transparency

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dirty Transparency

Post 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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Dirty Transparency

Post 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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Dirty Transparency

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Dirty Transparency

Post 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.
snibgo's IM pages: im.snibgo.com
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Dirty Transparency

Post by lorents »

Many thanks, all have turned out
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Dirty Transparency

Post by lorents »

Whether prompt, please, as it is possible to learn is PNG a transparency, or not?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dirty Transparency

Post by fmw42 »

convert image.png -format "%A" info:

Will return True or False


see http://www.imagemagick.org/script/escape.php
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Dirty Transparency

Post by lorents »

thanks
lorents
Posts: 42
Joined: 2010-07-06T04:27:53-07:00
Authentication code: 8675308

Re: Dirty Transparency

Post 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
Post Reply