Can't Read an image file

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
dj_judas21
Posts: 4
Joined: 2011-02-07T05:09:46-07:00
Authentication code: 8675308

Can't Read an image file

Post 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
dj_judas21
Posts: 4
Joined: 2011-02-07T05:09:46-07:00
Authentication code: 8675308

Re: Can't Read an image file

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Can't Read an image file

Post by magick »

Try this command:
  • convert logo: logo.pnm
Then read it with
  • $image->Read('logo.pnm') || die $!;
Does that work?
dj_judas21
Posts: 4
Joined: 2011-02-07T05:09:46-07:00
Authentication code: 8675308

Re: Can't Read an image file

Post 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") ?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Can't Read an image file

Post 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.
dj_judas21
Posts: 4
Joined: 2011-02-07T05:09:46-07:00
Authentication code: 8675308

Re: Can't Read an image file

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Can't Read an image file

Post by magick »

Any reason why you can't install in /usr/local/? If that's not a problem, type:
Manisha
Posts: 5
Joined: 2011-03-10T22:01:02-07:00
Authentication code: 8675308

Re: Can't Read an image file

Post 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.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: Can't Read an image file

Post 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.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: Can't Read an image file

Post 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".
Post Reply