Resize an Image, Center, and Posturize...
Posted: 2010-10-10T19:58:05-07:00
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>
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>