perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marius Feraru <>
Subject Re: too many files open
Date Mon, 03 Dec 2001 23:06:04 GMT
Hash: SHA1

Today at 10:14, 'John Michael' wrote:
|JM|Perlmagick claims that it handles all of the file handling.
And it really does it. So why don't you let him do its job!!?!
... meaning, why do you use things like:
|JM|    my $image = Image::Magick->new(magick=>'JPEG');
|JM|    my $file = join("/",$working_dir, $pic);
|JM|    open(DATA, "$file") || die "$file $!";
|JM|        $image->Read(file=>DATA);
|JM|    close(DATA);
|JM|open(DATA, ">$out_file");
|JM|    $image->Write(file=>DATA,filename=>$out_file);
instead of i.e.:
	my $image = Image::Magick->new;
	my $ret = $image->Read($file);
	return $ret if $ret;
	$ret = $image->Write($out_file);
	return $ret if $ret;

Yet, there is no obvious error in your code that should drive you system
crazy. So, there are some suggestions (in addition to the questioned one
above :) that could make your code behave nicer:
- - do check error codes returned by PerlMagick!
- - globing? use it just at home ;-] in fact enhance your program using some 
MIME module to detect properly the file type + check out for files like 
'foo.jpg' that in fact is an animated GIF file so you will get an entire 
group of output files instead of one etc...
- - you will surely gain lots of cpu time if avoiding that rotation stuff***
- - use File::Spec for constructing file paths in a portable way
- - you may wanna use some thumbmakeronly module :)) : Image::GD::Thumbnail
if that gaussian blur it's not so important ;-]

*** as I see it you need some thumbnails size normalization so: how to avoid
image rotation and re-rotation?

my ($w,$h) = calcGeometry($image->Get('width','height'), 50, 50);
$ret = $image->Scale( width => $w, height => $h);
warn $ret if $ret;

sub calcGeometry {
	my ($w,$h,$stdW,$stdH) = @_;
	if($w>$h) {
		$h = $h/($w/$stdW);
		$w = $stdW;
	} else {
		$w = $w/($h/$stdH);
		$h = $stdH;
	return int($w), int($h);

- -- 
Marius Feraru                       
"its easy to stop using Perl: I do it after every project"



View raw message