This script ( from author unknown) works on a gif I tested.
#!/usr/bin/perl #None of these is fast, mainly because of the overhead of calling Perl #code for each pixel. use strict; my $imagefile = shift or die "No file specified\n"; sub rgba2hex { sprintf "%02x%02x%02x%02x", map { $_ || 0 } @_; } { use Imager; my %colors; my $img = Imager->new(); $img->open( file => $imagefile ) or die $img->errstr; my ( $w, $h ) = ( $img->getwidth, $img->getheight ); for my $i ( 0 .. $w - 1 ) { for my $j ( 0 .. $h - 1 ) { my $color = $img->getpixel( x => $i, y => $j ); my $hcolor = rgba2hex $color->rgba(); print "$hcolor "; $colors{$hcolor}++; } } printf "Imager: Number of colours: %d\n", scalar keys %colors; } { use GD; my %colors; my $gd = GD::Image->new($imagefile) or die "GD::Image->new($imagef +ile)"; my ( $w, $h ) = $gd->getBounds(); for my $i ( 0 .. $w - 1 ) { for my $j ( 0 .. $h - 1 ) { my $index = $gd->getPixel( $i, $j ); my $hcolor = rgba2hex( $gd->rgb($index), 0 ); $colors{$hcolor}++; } } printf "GD: Number of colours: %d\n", scalar keys %colors; } { use Image::Magick; my %colors; my $img = Image::Magick->new(); my $rc = $img->Read($imagefile); die $rc if $rc; my ( $w, $h ) = $img->Get( 'width', 'height' ); for my $i ( 0 .. $w - 1 ) { for my $j ( 0 .. $h - 1 ) { my $color = $img->Get("pixel[$i,$j]"); my $hcolor = rgba2hex split /,/, $color; $colors{$hcolor}++; } } printf "Image::Magick: Number of colours: %d\n", scalar keys %colo +rs; }

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Need module for retrieving pixels from GIF format image... by zentara
in thread Need module for retrieving pixels from GIF format image... by TedPride

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.