Ask a Question related to PERL Modules, Design and Development.
-
cb #1
Help: Image::Magick::Thumbnail
Hi,
The following example (from cpan.org) take an .jpg image and creates a
thumbnail.
It creates an image where the biggest size is 50 pixels.
Can this code be easily modified to make all sides 50 pixels (ie square
image)?
I've tried the following, but it doesn't create any image.
my ($thumb,$x,$y) = Image::Magick::Thumbnail::create(50,50);
my ($thumb,50,50) = Image::Magick::Thumbnail::create($src,50);
As a newbie I've tried without success.
Thanks
use Image::Magick::Thumbnail;
# Load your source image
my $src = new Image::Magick;
$src->Read('source.jpg');
# Create the thumbnail from it, where the biggest side is 50 px
my ($thumb,$x,$y) = Image::Magick::Thumbnail::create($src,50);
# Save your thumbnail
$thumb->Write('source_thumb.jpg');
cb Guest
-
Image Magick thumbnail batch resizing
Spartacus <spam@mailinator.com> writes: I think you want to scale instead of sample do convert -quality 85 -scale x75 $i ../thumbs/`basename $i... -
Image::Magick::Thumbnail::create problem
I am using a script based on the example from www.cpan.org for Image::Magick::Thumbnail:- #!/usr/bin/perl -w use CGI qw(:all); print header;... -
Thumbnail image in Flash to larger image in new window?
I have a series of thumbnail images in Flash and I want the user to be able to click on the thumbnail and get a larger photo. I know how to make the... -
Image Magick
Mike At Spy wrote: the easiest way to remove them is to use RPM, if that was what was used to install them rpm -e ImageMagick if there are no... -
[PHP] Image Magick
Mike -- ...and then Mike At Spy said... % % Anyone here familiar with the installation of Image Magick and what filesit % installs on your... -
gnari #2
Re: Image::Magick::Thumbnail
"cb" <cb2005uk@yahoo.co.uk> wrote in message
news:402bd388$0$3942$cc9e4d1f@news.dial.pipex.com. ..this fails because the first argument should be a Image::Magick object> Hi,
>
> The following example (from cpan.org) take an .jpg image and creates a
> thumbnail.
> It creates an image where the biggest size is 50 pixels.
>
> Can this code be easily modified to make all sides 50 pixels (ie square
> image)?
>
> I've tried the following, but it doesn't create any image.
> my ($thumb,$x,$y) = Image::Magick::Thumbnail::create(50,50);
this fails because you are trying to assing the returned values to> my ($thumb,50,50) = Image::Magick::Thumbnail::create($src,50);
the constant 50.
just read the Image::Magick docs (see>
> As a newbie I've tried without success.
>
> Thanks
>
>
> use Image::Magick::Thumbnail;
> # Load your source image
> my $src = new Image::Magick;
> $src->Read('source.jpg');
>
> # Create the thumbnail from it, where the biggest side is 50 px
> my ($thumb,$x,$y) = Image::Magick::Thumbnail::create($src,50);
[url]http://www.imagemagick.org/www/perl.html[/url])
and add an appropriate operation here. for example
$thumb->Resize(width=>50,height=>50);
>
> # Save your thumbnail
> $thumb->Write('source_thumb.jpg');
looks like Image::Magick::Thumbnail is pretty simple (and useless).
you probably should drop it altogether.
use Image::Magick;
my $src = new Image::Magick;
$src->Read('source.jpg');
$src->Resize(width=>50,height=>50);
$src->Write('source_thumb.jpg');
of course if you resize the image to 50x50 and it was not
square to begin with, it will stretch.
gnari
gnari Guest
-
thinkfirst #3
Re: Image::Magick::Thumbnail
use Image::Magick ;
my $input_img = ... ;
my $output_img = ... ;
my $max_dimension = 50 ;
my $fill_color = '#ffffff' ;
my $image = Image::Magick->new ;
$image->Read($input_img) ;
my $width = $image->Get('columns') ;
my $height = $image->Get('height') ;
$image->Scale(geometry=>"$max_dimension x $max_dimension") if $width > $max_dimension ;
$image->Scale(geometry=>"$max_dimension x $max_dimension") if $height > $max_dimension ;
my $border_width = int(0.5 + ($max_dimension - $image->Get('columns'))/2) ;
my $border_height = int(0.5 + ($max_dimension - $image->Get('height'))/2) ;
$image->Border(geometry=>"$max_dimension x $max_dimension",
width=>$border_width, height=>$border_height, fill=>$fill_color);
$image->Crop(geometry=>"$max_dimension x $max_dimension+0+0");
$image->Write($output_img);
thinkfirst Guest
-
Martien Verbruggen #4
Re: Help: Image::Magick::Thumbnail
On Thu, 12 Feb 2004 19:22:37 -0000,
cb <cb2005uk@yahoo.co.uk> wrote:use Image::Magick;> Hi,
>
> The following example (from cpan.org) take an .jpg image and creates a
> thumbnail.
> It creates an image where the biggest size is 50 pixels.
>
> Can this code be easily modified to make all sides 50 pixels (ie square
> image)?
>
> I've tried the following, but it doesn't create any image.
> my ($thumb,$x,$y) = Image::Magick::Thumbnail::create(50,50);
> my ($thumb,50,50) = Image::Magick::Thumbnail::create($src,50);
my $im = Image::Magick->new();
$im->Read($f);
$im->Scale(geometry => "50x50!");
You can read about the geometry values in the man page ImageMagick(1),
or in your locally installed documentation in HTML format, or at
[url]http://www.imagemagick.org/www/utilities.html[/url]
This will distort the image if it isn't square already. If you don't
want that, you will have to be more clear about what you want to
happen: Do you want the smallest dimension of the image to be scaled
to 50 pixels, and the rest cropped off? Do you want the largest
dimension to be scaled to 50, and the rest filled up?
Martien
--
|
Martien Verbruggen | That's not a lie, it's a terminological
Trading Post Australia | inexactitude.
|
Martien Verbruggen Guest
-
Martien Verbruggen #5
Re: Help: Image::Magick::Thumbnail
On 16 Feb 2004 05:38:29 GMT,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:[snip request for thumbnails of exactly 50x50, and one possible> On Thu, 12 Feb 2004 19:22:37 -0000,
> cb <cb2005uk@yahoo.co.uk> wrote:
solution, distorting aspect ratio]
Here's two others that don't distort aspect ratio:> This will distort the image if it isn't square already. If you don't
> want that, you will have to be more clear about what you want to
> happen: Do you want the smallest dimension of the image to be scaled
> to 50 pixels, and the rest cropped off? Do you want the largest
> dimension to be scaled to 50, and the rest filled up?
# resize smallest dimension, and crop
my $im = Image::Magick->new();
$im->Read($f);
my ($w, $h) = $im->Get("width", "height");
my $geometry = $w > $h ? "x50" : "50";
$im->Scale(geometry => $geometry);
($w, $h) = $im->Get("width", "height");
$im->Crop(width => 50, height => 50, x => ($w - 50)/2, y => ($h - 50)/2);
# resize largest dimension, and fill
my $im = Image::Magick->new();
$im->Read($f);
$im->Scale(geometry => "50x50");
my $im2 = Image::Magick->new(size => "50x50");
$im2->Read("xc:black");
$im2->Composite(image => $im, compose => "Over", gravity => "Center");
You should probably put some error checking in.
Martien
--
|
Martien Verbruggen | Useful Statistic: 75% of the people make up
Trading Post Australia | 3/4 of the population.
|
Martien Verbruggen Guest



Reply With Quote

