On Tue, 28 Oct 2008 20:56:23 +0100
Benct Philip Jonsson <[EMAIL PROTECTED]> wrote:

>I have a sheaf of scanned png images of
>uneven sizes.  what I want to do is to
>add borders so that he original image,
>without resizing, is cenetered in the new
>image, all the new images having the
>same size.  How do?

Here is a Perl script to do it.  I suppose you should loop thru
all the images first, and get the biggest size...... I just hardcoded 800x800 
in.

#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;

# reuse objects
my $image = Image::Magick->new;
my $image1 = Image::Magick->new;

umask 0022;
my @pics= <*.png>;
  
foreach my $pic (@pics){    
   # make your background
   $image1->Set(size=>'800x800');   #all will be 800x800
   $image1->ReadImage('xc:white'); # a white background
 
   my ($picbasename) = $pic =~ /^(.*).png$/;
   my $ok;
   $ok = $image->Read($pic) and warn ($ok);
   my $resize = 'zzz'.$picbasename . '-r.png';
     
   #add a border maybe?
   $image->Border('width'=>20,'height'=>20,'bordercolor'=>'lightblue');
   
   $image1->Composite('image'=>$image,'compose'=>'Atop','gravity'=>'center');  
   
   $ok = $image1->Write($resize) and warn ($ok);
   undef @$image; #needed if $image is created outside loop
   undef @$image1; #needed if $image1 is created outside loop
   print "$pic -> $resize\n";
  
}
__END__


zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to