Hai
i am using the image magick to convert an image from 72 dpi to 300 dpi. with
the corresponding image height and width.
but now i need to resize this image to the corresponding height and width
which are existing at 72 dpi.
when i do that it is not creating the image with the exact values i gave..
how do i do with exact values.
or else can i keep the image with the fixed height and let image magick take
the proportionate width for me.
Can any one help me on this..
this is my code..
my $file = shift;
> my $folder = "";
> my $filename = $folder . $file . ".jpg";
> $image = Image::Magick->new;
>
> if ( -e $filename ) {
> my $jpgfile = $folder . $file . "_new.jpg";
> my $tjpgfile = $folder . $file . "_t.jpg";
> my $err = 0;
> print $filename. "\n";
> my $image = Image::Magick->new;
> eval { my $ImgRead = $image->Read($filename); };
> if ($@) {
> $err = 1;
> print "cannot read input\n";
> return ( "", "", $err );
> }
> my $width = $image->[0]->Get('width');
> my $height = $image->[0]->Get('height');
> my $xy = $image->[0]->Get('density');
> my @xyz = split( "x", $xy );
> my $density = 300;
> my $imgwidth = ( $width / $xyz[0] ) * $density;
> my $imgheight = ( $height / $xyz[0] ) * $density;
> #print "XY==> " . $xyz[0] . "\n";
> $log_data .= "XYZ array ==> @xyz\n";
> $log_data .= "Width==> ".$width."\n";
> $log_data .= "Height==> ".$height."\n";
> eval {
> # if($xyz[0] ne '300'){
> # system( "convert $filename -resize "
> # . ceil($imgwidth) . "x"
> # . ceil($imgheight)
> # . "! -density $density -quality 80 $jpgfile" );
> # }
> # system("convert $filename -resize 150x130 $tjpgfile");
> $image->[0]->Thumbnail(width=>$imgwidth,height=>$imgheight);
> $image->[0]->Set("density"=>300);
> $image->[0]->Set("units"=>"PixelsPerInch");
> $image->[0]->Resize("$height");
> #$image->[0]->Thumbnail(width=>$width,height=>$height);
> $image->[0]->Set(quality=>100);
> $image->[0]->Set("units"=>"PixelsPerInch");
> $image->Write(filename=>"$jpgfile");
>
> $image->[0]->Thumbnail(width=>'150',height=>'130');
> $image->[0]->Set("density"=>300);
> $image->[0]->Set("units"=>"PixelsPerInch");
> $image->Write(filename=>"$tjpgfile");
> };
> if ($@) {
> $err = 1;
> print "cannot convert input\n";
> return ( "", "", $err );
> }
>
> #unlink($filename);
> return ( $jpgfile, $tjpgfile, $err );
> }
> else {
> $log_data .= $filename . " does not exist\n";
> }
>
Chaitanya