jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

I have the following subroutine:
sub imgmk { my $imgmkpath = "../home/edit/docs/$myfile/$tstamp.$extension"; my $src = new Image::Magick; $src->Read("$imgmkpath"); my ($ox,$oy) = $src->Get('width','height'); my $r = $ox / 300; $src->Resize(width=>300,height=>$oy/$r); $src->Write("../home/edit/docs/$myfile/$tstamp.$extension"); }
This fails because the Read() is not finding the file. If I change the path to something like "../new.jpg"; the subroutine succeeds and the Write() occurs in "../home/edit/etc". My question is why does the module recognise the path for the Write() function, but not the Read()?

Replies are listed 'Best First'.
Re: path problem with ImageMagick
by pbeckingham (Parson) on Aug 11, 2004 at 16:40 UTC

    • Try printing out the value of $imgmkpath - is it what you expected?
    • Can you convert the relative path to an absolute path? That way you are not reliant on which directory you launch the program from.
    • Can you check the return value of Image::Magick::Read?
    • Can you check the return value of Image::Magick::Write?
    • Did you know that $src->Read($imgmkpath); is functionally the same as, but better style than $src->Read("$imgmkpath");?
    • It is preferable to write Image::Magick->new than new Image::Magick.



    pbeckingham - typist, perishable vertebrate.
Re: path problem with ImageMagick
by Roger (Parson) on Aug 11, 2004 at 16:25 UTC
    Where did you set up your $myfile, $tstamp and $extension variables? They are globals I presume?

    Try to print out the name of your file before you read it, that might give you more clue as why you are not reading the file correctly. :-)