Please bottom post....

Brian Volk wrote:
Thank you Wiggins!  I have changed everything that you suggested and I think
I am much closer.  However, I have run into an error w/ the Read line.

foreach my $file (@files) {
  $image->Read (file=> $file)

Bad filehandle: brian.jpg at C:/Program Files/PerlEdit/scripts/test_3.pl
line 17

as you can see the script is seeing the file name in the image directory.  I
re-read chapter 11 Learning Perl on Bad Filehandles but I'm still having
trouble.  Any suggestion would be greatly appreciated.

Thanks!

Brian


Either....

It appears that the docs for I::M are incorrect and that C<Read> and C<Write> must take a filehandle. Difficult to tell since all the code is XS/C and I didn't feel like popping the hood on it. You could try switching back to using a handle but I would be more specific about it, so for instance, within the foreach you would have:

open my $READHANDLE, $filename or die "Can't open file for reading: $!";
$image->Read('file' => $READHANDLE);

etc.

Or there is an issue with the installation, paths, etc. on Windows. You should retrieve the actual error message from I::M and see what it says, similar to,

my $result = $image->Read('file' => $filename);
print $result;

Have you checked out the info at:

http://www.dylanbeattie.net/magick/

It appears to be good info for Win32 specific stuff related to I::M. Personally I can't even test it here so it is difficult for me to point you in the right direction. Maybe one of the other M$ users will chime in ...

http://danconia.org



-----Original Message----- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Thursday, September 09, 2004 12:28 PM To: Brian Volk; Beginners (E-mail) Subject: Re: perl crashing at $image->Read (file=> \*ARGV);



Hi All,

I my perl script is crashing perl at this line;

$image->Read (file=> \*ARGV);

I know that it is this line because I have commented out everything else
around it.  When I just have the Read statment, perl will crash.   Here is
the script, can someone please suggest what I am doing wrong.

Thanks!


----------------------------------------------------------------------------

---------------------
#!/user/local/bin/perl -w

use strict;
use Image::Magick;

my $images = "C:/images";
   opendir (IMAGES, $images) or die "can not open $images: $!";

# load @ARGV for (<>)

@ARGV = map { "$images/$_" } grep { !/^\./ } readdir IMAGES;



my @files = map { "$images/$_" } grep { !/^\./ } readdir IMAGES;

Not sure why you are using @ARGV just for its special qualities (aka the
<> operator) why not name our variables, we are allowed too.


my $image = Image::Magick->new(magick=>'JPEG');

# Read images, Scale down and Write to new directory

while (<>) {


No need to use a while here, since you already have a complete array,

foreach my $file (@files) {


$image->Read (file=> \*ARGV)


By naming our variables we now see that we are dealing with a filename,
rather than a typeglob reference.


$image->Read(file => $file)

The example you are using assumes that *ARGV contains an opened
filehandle to the file itself, *but* within the loop you are executing
on each line. See perldoc perlop for more. I would skip using the
special nature of the variables until you understand them. Try using
specifically named variables until the program works, then reduce it if
you must.


   and $image->Scale (width=>'50', height=>'50')
   and $image->Write ("C:/images")


C<Write> expects a filename argument, not a directory, or a handle.


and close (ARGV);


Not sure why these statements are strung together with C<and> they can
be separate, you haven't really benefited by making them a single
statement. And you wouldn't normally close ARGV.


   }

closedir IMAGES;



You can close your dir earlier in the process, since you are done
reading from it.


Brian Volk
HP Products
317.289.9950 x1245
<mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]



http://danconia.org



-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to