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?".

Dirty Transparency

Postby lorents » 2010-07-06T04:32:41+00:00

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

Dirty Transparency
lorents
 
Posts: 20
Joined: 2010-07-06T04:27:53+00:00

Re: Dirty Transparency

Postby lorents » 2010-07-06T10:43:27+00:00

It is necessary to me, something on similarity of it
http://www.translate.ru/links/8020eb12
lorents
 
Posts: 20
Joined: 2010-07-06T04:27:53+00:00

Re: Dirty Transparency

Postby fmw42 » 2010-07-06T12:37:18+00:00

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
User avatar
fmw42
 
Posts: 14802
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Dirty Transparency

Postby snibgo » 2010-07-06T13:01:58+00:00

Does this do what is wanted?

convert image.png -background Black -alpha Background image_new.jpg
snibgo's IM pages: im.snibgo.com
snibgo
 
Posts: 3757
Joined: 2010-01-23T23:01:33+00:00

Re: Dirty Transparency

Postby fmw42 » 2010-07-06T14:32:42+00:00

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
User avatar
fmw42
 
Posts: 14802
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Dirty Transparency

Postby snibgo » 2010-07-06T15:11:41+00:00

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
snibgo
 
Posts: 3757
Joined: 2010-01-23T23:01:33+00:00

Re: Dirty Transparency

Postby fmw42 » 2010-07-06T17:51:11+00:00

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
fmw42
 
Posts: 14802
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Dirty Transparency

Postby anthony » 2010-07-06T20:01:50+00:00

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
http://www.imagemagick.org/Usage/
User avatar
anthony
 
Posts: 8729
Joined: 2004-05-31T19:27:03+00:00
Location: Brisbane, Australia

Re: Dirty Transparency

Postby lorents » 2010-07-07T00:09:17+00:00

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
lorents
 
Posts: 20
Joined: 2010-07-06T04:27:53+00:00

Re: Dirty Transparency

Postby snibgo » 2010-07-07T05:04:29+00:00

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
snibgo
 
Posts: 3757
Joined: 2010-01-23T23:01:33+00:00

Re: Dirty Transparency

Postby lorents » 2010-07-07T09:01:47+00:00

Many thanks, all have turned out
lorents
 
Posts: 20
Joined: 2010-07-06T04:27:53+00:00

Re: Dirty Transparency

Postby lorents » 2010-07-07T09:15:03+00:00

Whether prompt, please, as it is possible to learn is PNG a transparency, or not?
lorents
 
Posts: 20
Joined: 2010-07-06T04:27:53+00:00

Re: Dirty Transparency

Postby fmw42 » 2010-07-07T10:26:26+00:00

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

Will return True or False


see http://www.imagemagick.org/script/escape.php
User avatar
fmw42
 
Posts: 14802
Joined: 2007-07-02T17:14:51+00:00
Location: Sunnyvale, California, USA

Re: Dirty Transparency

Postby lorents » 2010-07-07T10:40:03+00:00

thanks
lorents
 
Posts: 20
Joined: 2010-07-06T04:27:53+00:00

Re: Dirty Transparency

Postby lorents » 2010-07-07T11:41:13+00:00

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
lorents
 
Posts: 20
Joined: 2010-07-06T04:27:53+00:00

Next

Return to Users

Who is online

Users browsing this forum: dlemstra, fireundubh and 21 guests