Wiggins d'Anconia wrote:
>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;
Well, I got it reading from a directory, Mike at the Image::Magick mailing
list help me out... "The read must contain the path as well as the filename.
$image->Read (file=> "$path\\$file");"
but I am stil having some problems with Scale and Write. The error is:
"my" variable $img masks earlier declaration in same scope at C:/Program
Files/
erlEdit/scripts/image_test.pl line 25.
JPEG 70048.jpg
Can't call method "Scale" on an undefined value at C:/Program
Files/PerlEdit/sc
ipts/image_test.pl line 24.
As you can see the program starts to read from the image directoy, but when
it hits "Scale", I get the undefined value error. I'm not sure what that
means.
-------------------------------
#!/user/bin/perl -w
use strict;
use Image::Magick;
my $image_source_folder = "C:/images";
my $image_dest_folder = "C:/images_small";
opendir(IMAGES,$image_source_folder);
my @images_to_process_list=grep {!(/^\./) && -f "$image_source_folder/$_"}
readdir(IMAGES);
closedir (IMAGES);
foreach my $image_source_file(@images_to_process_list) {
my $img = new Image::Magick;
my $status=$img->Read("$image_source_folder\\$image_source_file");
if ($status eq "") {
my $fmt = $img->Get('format');
print "JPEG $image_source_file\n";
my $img->Scale(width=>'30', height=>'30');
my
$img->Write("jpg:$image_dest_folder\\$image_source_file");
undef $img;
}
}
Thanks for any help!
Brian
-----Original Message-----
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 09, 2004 6:32 PM
To: Brian Volk
Cc: Beginners (E-mail)
Subject: Re: perl crashing at $image->Read (file=> \*ARGV);
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>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>