can't scale or clone tiff image using libimage-imlib2-perl

andy baxter andy at earthsong.free-online.co.uk
Sun Aug 26 12:44:35 BST 2007


I have written a program in perl which scales a collection of panoramic
tiff images to various different sizes. It was working fine, but
recently stopped working for no obvious reason. I am using the perl
wrapper to libimlib2, from the package libimage-imlib2-perl. The program
works by loading the image into a variable '$img', then using
'create_scaled_image' to generate scaled versions of the image at
several sizes. The text of the program is copied below. I have commented
out the line which originally scaled the image and replaced it with the
simpler 'clone' function. Neither version works - i.e whichever line of
the two I comment out, the program dies when the original image (which
seems to load OK) is scaled or cloned.

I have submitted a bug report about this problem.

Any help would be greatly appreciated, as this is holding me up with a
project I want to get finished. I have tried reinstalling both libimlib2
and libimage-imlib2-perl, but this doesn't help.

andy baxter.

#!/usr/bin/perl
#
# scale-panoramas.pl - scale a series of raw panorama files into various resolutions for the virtual tour.
#
# This program expects to be run in a set directory which contains a subdir 'raw' containing the raw panoramas (each in its own subdir with the same filename as the subdir but the '.tiff' extension).
# There should also be a subdir 'scaled' to put the scaled images into.

use Image::Imlib2;

my $rawPanoDir="raw"; # directory with the raw panoramas in. The subdirectories of this give the names of the scaled panoramas.
        # each subdir has a file in it called '<subdirname>.tif' where <subdirname> is the name of the subdirectory. This contains the raw 
        # panorama file.
my $scaledPanoDir="scaled"; # directory with the scaled panoramas in. The names of the files are <panoname>-<resolution>.jpg,
        # where <panoname> is the name of the panorama (taken from subdirname above), and <resolution> is the vertical resolution
        # of the scaled image.
my @resolutions=qw(100 140 200 280 400); # list of resolutions to scale the panoramas to. These are the vertical heights in pixels.
my @qualities=qw(70 70 70 80 90); # list of jpeg qualities to use for each of the above resolutions.
my $scaledFormat="jpeg"; # format to use for scaled images. (usually jpeg)
my $scaledExtn=".jpg"; # file extension ditto.

print "Reading directory names\n";
my $dirh;
opendir($dirh,$rawPanoDir);
my @subdirs=readdir($dirh);
foreach my $panoName (@subdirs) {
        next if $panoName =~ /^\./;
        print "Processing panorama: $panoName\n";
        my $panoFile="${rawPanoDir}/${panoName}/${panoName}.tif";
        print "  opening file: $panoFile\n";
        my $img=Image::Imlib2->load($panoFile) || die "Can't open panorama file: $panoFile\n";
        my ($width,$height)=($img->get_width,$img->get_height);
        my $numRes=@resolutions;
        for (my $res=0; $res<$numRes; $res++) {
                print "  scaling to $resolutions[$res] pixels high at quality: $qualities[$res]\n";
                my $newheight=$resolutions[$res];
                my $newwidth=int($width*($newheight/$height));
                print "  new width=$newwidth, new height=$newheight\n";
                my $scaledImg=$img->clone() ||die;
                #my $scaledImg=$img->create_scaled_image($newwidth,$newheight)|| die "can't scale image";
                print "  img=$img, scaledImg=$scaledImg \n";
                $scaledImg->set_quality($qualities[$res]);
                $scaledImg->image_set_format($scaledFormat);
                $scaledImg->save("${scaledPanoDir}/${panoName}-${newheight}${scaledExtn}");
                }
        }





More information about the ubuntu-users mailing list