Shrinking Image Size Using Perl
Perl is a versatile language. It is easy to shrink or resize the image width and height using perl script.The Image::Magick module in Perl is the best way to reduce the image size. It is useful to create the image thumbnails.
The following steps are required to shrink the image size using Perl,
<>Specify the path of the image to be reduced.
<>Assign a factor value which should be less than 1.
<>Use the Resize function to shrink the image width and height.
#! /usr/bin/perl -w
#Assign factor value less than 1.Here '0.5' is used to reduce the image size to its half.
my $factor = 0.5;
#Specify the path of the image.
my $src. = "src._img.jpg";
my $img = Image::Magick->new();
# To compare the image size, Clone is used.
my $newimg= $img->Clone;
#Now extract the image height and width and new reduced image size is obtained by multiplying it with factor value.
my $h = $newimg->Get('height');
my $w = $newimg->Get('width');
my $err = $newimg->Resize(height=> $h * $factor, width=> $w * $factor,);
#instead of Resize you can also use the Scale method as
# $newimg->Scale(width =>$w * $factor, height =>$h*$factor);
#script is finished or completed.