Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > ImageMagick: Writing image with 4 colors and palette

Reply
Thread Tools

ImageMagick: Writing image with 4 colors and palette

 
 
Josef Moellers
Guest
Posts: n/a
 
      11-04-2008
zentara wrote:
> On Mon, 03 Nov 2008 16:12:55 +0100, Josef Moellers
> <> wrote:
>
>
>> It seems that it has to do with the fact that I have a transparent
>> background ...

>
> Guess to remove layer:
> Try adding the flatten option.


I've tried to call $img->Flatten() and $img->Layers(method =>
'flatten'), none of which worked.

Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
 
Reply With Quote
 
 
 
 
zentara
Guest
Posts: n/a
 
      11-05-2008
On Tue, 04 Nov 2008 13:53:57 +0100, Josef Moellers
<> wrote:

>zentara wrote:
>> On Mon, 03 Nov 2008 16:12:55 +0100, Josef Moellers
>> <> wrote:
>>
>>
>>> It seems that it has to do with the fact that I have a transparent
>>> background ...

>>
>> Guess to remove layer:
>> Try adding the flatten option.

>
>I've tried to call $img->Flatten() and $img->Layers(method =>
>'flatten'), none of which worked.
>
>Josef


This worked for me:
tig.png is a green curve on a transparent alpha layer

tig.png PNG 32x32 32x32+0+0 8-bit DirectClass 5.4e+02b
#after script is run
tig-4c.png PNG 32x32 32x32+0+0 8-bit PseudoClass 4c 3e+02b

#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
use MIME::Base64;

# tig.png is a green curve written on a transparent layer
# included here so we are on same page
my $blob = decode_base64(
'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAB mJLR0QA/wD/AP+gvaeTAAAACXBI
WXMAAAsTAAALEwEAmpwYAAABwUlEQVRYw+2VvS8EURTFf8/4CKJQTKOgEIlEqFCIRnSUhE6iUOhV
Go3Kf0ChkiipNWqFQuErEtFJSEREfO7O0dyNid2Z3X3sbmHfy8 2bdzPv3TPnnnvHSaKWo4EajzqA
OoBGn0MOl+cT+l8pmANugEdb53wBuHIbkdGfAYKYOws0+qTBl4 GgyL5ehhUHcFVkX3ERfm9jraAq
IrQgLmbewX+TghcgsvKLAFVbA895xFQLgMOFQHstq2ACaMnD5T sklWyIEPGMiFDe3C7nrpyVy8AI
0JaQ81mHO3C4oJIp2E0R3TswBKxWJAWIW6M+W4D+LOLd7BaxWP q9xQP3I64teITIxAIvIc7t+dPW
N8QdIvwrAKex4PG5guhAjMd8T8bCh4m13wuAqX0H8ZCg+GlEA6 IV0YZYLvBOZKycIcaSADhJuebS
B0wCvcAUECbIZgC4AJqAZhNfaNWxA4wWOBMBl8AecAIc2n/lHsQ8Yh9xYvQlzW3EIKIZ0fKDsU7z
dyO2TANKYCWyFB0jZkgJmJsZxIZRHqRoBYQzG0AclXD3axqAF8 SaT3czED2ILsRmKoQCrjvEQtrX
egAKEMOI9R9lHH0BkYPO/OE8jeIAAAAASUVORK5CYII=');

my $img = Image::Magick->new(magick=>'png');
$img->BlobToImage( $blob );
$img->Write('tig.png');

$img->Quantize( colors => 4 );
$img->Set( type => 'Palette' );
$img->Write("tig-4c.png");
__END__

I'm using IM-6.4.3

Maybe your libpng is defective?

zentara

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
TreeNode colors come from anchor colors AAaron123 ASP .Net 1 08-07-2008 07:56 PM
Manipulating GIF image frames w/ PIL - where'd my palette go? skip@pobox.com Python 0 09-04-2006 04:07 PM
Image magick palette kkarma Perl Misc 0 07-31-2004 03:16 AM
Q: How change color palette of Image in J2ME? Kenneth Ljunggren Java 0 06-16-2004 06:39 AM
Displaying Palette Tiff Image using JAI (very slow when scale operation is performed) atusc Java 1 06-04-2004 05:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57