Page 1 of 1

Resize an Image, Center, and Posturize...

Posted: 2010-10-10T19:58:05-07:00
by manofmilk
I'm attempting to create a CGI page, where I can upload an image, and it automatically resize into formats compatible with all the different Cisco IP Phones. I'm having problems with a few parts:
1 - Ordered Dithering, I can't quite figure out how to dither to the 40R,40G,40B required
2 - Converting to Greyscale
3 - the "Gravity" on the extent doesn't seem to be working, as the image isn't centering...

Any help would be GREATLY appreciated...

I'm currently using the latest RPMs:
[user1@localhost IPT]# rpm -qa | grep Image
ImageMagick-6.6.4-10
ImageMagick-perl-6.6.4-10
[user1@localhost IPT]#

Currently my code is:

<snip>

&resize_file(320,212);
$image->Posterize(levels=>16);
print "Writing file...320x212x16<br>";
$image->Write("$filedir/FULLSIZE-320x212x16.png");

sub resize_file {
$image = new Image::Magick;
$image->Read("$filedir/$filename");
print "Preparing to resize...<br>";
my ($owidth,$oheight) = ($_[0],$_[1]);
my $width = $_[0];
my $height = $_[1];
my ($origw, $origh) = $image->Get('width', 'height');
if($origw >= $origh){
$height = $width * $origh / $origw;
} else {
$width = $height * $origw / $origh;
}
print "resizing...";
$image->Resize(width=>$width, height=>$height);
$image->Extent(gravity=>'Center', width=>$owidth, height=>$oheight, background=>'white');
print "Modifying contrast...<br>";
$image->Contrast();
print "Flattening Image...<br>";
$image->Flatten();
}

</snip>

Re: Resize an Image, Center, and Posturize...

Posted: 2010-10-10T23:34:08-07:00
by anthony
gravity on extent should be working!

to convert to greyscale use -colorspace gray (or equivelent for your API)
OR any of the other methods in
http://www.imagemagick.org/Usage/colors ... #grayscale

What do you mean by... 40R,40G,40B

Re: Resize an Image, Center, and Posturize...

Posted: 2010-10-11T07:00:50-07:00
by manofmilk
1 - More information provided.
2 - Solved! ($image->Quantize(colorspace=>grey), unless there is a better way)
3 - Still open... will provide examples.

yea, I would think that gravity would be working too. =)

I have a transparent PNG that I'm uploading, and the result comes out being at the top of the graphic, and all new space is at the bottom, I haven't tried with other graphic types yet.

and use $image->Quantize(colorspace=>grey) to convert to greyscale?

The 40R,40G,40B, would be the different channel limitations, as that gets close to a 65535 (16bit) color scheme (with a 40x40x40=64000 colors), which would effectively work, but I don't know how to automatically dither to those channels, when I look at the documentation, is it something like: $image->OrderedDither(channel=>40Red,40Green,40Blue)

I don't know how to handle use the syntax, but from reading the following: http://www.imagemagick.org/Usage/bugs/ordered-dither/ at the command line, you can do: "convert logo.png -ordered-dither o8x8,8,8,4 logo_o8x8_332.gif"

I'd be interested in doing the same with PerlMagick, but don't see any examples, (or can find any)...

Thanks for the help so far.

Re: Resize an Image, Center, and Posturize...

Posted: 2010-10-11T20:26:37-07:00
by anthony
The channel handling for ordered dither was so complicated you would have to pass the channel stuff as part of the sting containg the o8x8

So it would have to be something like
$image->OrderedDither(thresholds=>"o8x8,40")

The 40 will be across all channels. Though 40 color levels is very extreme for an ordered dither!


Just a shame I have been able to find no information on ordered dithering with a specific user provided color map! I know it exists, as I have seen it used.