Page 1 of 1

Can't Read an image file

Posted: 2011-02-07T05:21:19-07:00
by dj_judas21
Hi all,

I'm trying to use PerlMagick to open and read in a jpg file, but I've had no luck so far. This is my code snippet:

Code: Select all

# Open the inputImage for reading
my $inputImage = Image::Magick->new;
my $status = $inputImage->Read($filePath) or die;
print "$file status $status\n";
The script dies at the die statement. If I remove the die, $status is an empty string - no return code.

$filePath contains a valid path to my JPG image, no spaces or funny characters. Permissions on the JPG are world-readable. Any ideas?

Cheers,
Jonathan

Re: Can't Read an image file

Posted: 2011-02-07T05:55:44-07:00
by dj_judas21
To follow up, if I change my die to die $! the given error is "No such file or directory".

However, I am absolutely 100% sure that the path and permissions are correct, since the $filePath variable is used in an earlier call to read some EXIF data from the JPG. This works fine.

The usual suspect for odd permissions issues is SELinux, but this is disabled on my system. Any ideas?

Re: Can't Read an image file

Posted: 2011-02-07T06:29:59-07:00
by magick
Try this command:
  • convert logo: logo.pnm
Then read it with
  • $image->Read('logo.pnm') || die $!;
Does that work?

Re: Can't Read an image file

Posted: 2011-02-07T07:02:59-07:00
by dj_judas21
The first command worked, and wrote out a logo. The second command failed with the same "no such file" message.

I presume the Read() call can take a whole path like Read("/home/jonathan/Pictures/logo.pnm") rather than having to cd and then calling Read("logo.pnm") ?

Re: Can't Read an image file

Posted: 2011-02-07T08:02:21-07:00
by magick
The most likely cause is that there is a structure mismatch between ImageMagick and PerlMagick. Try reinstalling both ImageMagick and PerlMagick so that they are built against the same version of ImageMagick or try downloading the PerlMagick source and build and install.

Re: Can't Read an image file

Posted: 2011-02-07T08:24:21-07:00
by dj_judas21
I'm using ImageMagick from Fedora's yum repo:

Code: Select all

[jg4461@cse-jeg ~]$ yum list installed ImageMagick*
Loaded plugins: presto, refresh-packagekit
Installed Packages
ImageMagick.x86_64                                                                       6.6.4.1-15.fc14
ImageMagick-c++.x86_64                                                                   6.6.4.1-15.fc14
ImageMagick-perl.x86_64                                                                  6.6.4.1-15.fc14
It isn't really practical to recompile from source since it will be overwritten at next package update, and I can't remove the packages because they are required by other packages on the system. Is there any other workaround?

Re: Can't Read an image file

Posted: 2011-02-07T09:56:16-07:00
by magick
Any reason why you can't install in /usr/local/? If that's not a problem, type:

Re: Can't Read an image file

Posted: 2011-03-10T22:15:26-07:00
by Manisha
Try using this:

#!/usr/bin/perl
use Image::Magick;
my $img = new Image::Magick;

my $status = $img->Read("image.gif");
if($status) {
die "$status";
}
#Montage() returns a new image

my $montage = $img->Montage(geometry=>'100x100',tile=> '3*2',borderwidth =>2);
$montage=$img->Write('montage1.gif')

There might be a problem to automatically display images once read because X11 server might not be installed.

So, try creating any object or modify an existing image. Open it with some other image viewer and check if the image is modified.

Re: Can't Read an image file

Posted: 2011-08-28T22:37:45-07:00
by sin
I'm using Perlmagick. it is working fine in my windows.

but I'm unable to write a code in such a way that the "code asks user to enter the filename of his interest"
instead of reading the filename that is mentioned in the code.

Re: Can't Read an image file

Posted: 2011-08-28T23:47:17-07:00
by sin
dj_judas21 wrote:Hi all,

I'm trying to use PerlMagick to open and read in a jpg file, but I've had no luck so far. This is my code snippet:

Code: Select all

# Open the inputImage for reading
my $inputImage = Image::Magick->new;
my $status = $inputImage->Read($filePath) or die;
print "$file status $status\n";
The script dies at the die statement. If I remove the die, $status is an empty string - no return code.

$filePath contains a valid path to my JPG image, no spaces or funny characters. Permissions on the JPG are world-readable. Any ideas?

Cheers,
Jonathan




can you please tell me on how you are going to write the path in "$filepath".