Professional Web Applications Themes

perl crashing at $image->Read (file=> \*ARGV); - PERL Beginners

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 -----Original Message----- From: Wiggins d Anconia [mailto:org] Sent: Thursday, September 09, 2004 12:28 PM To: Brian Volk; Beginners (E-mail) ...

  1. #1

    Default RE: perl crashing at $image->Read (file=> \*ARGV);

    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


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

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

    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.
     

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

    foreach my $file (files) {
     

    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.
     

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

    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.
     

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

    http://danconia.org
    Brian Guest

  2. #2

    Default Re: perl crashing at $image->Read (file=> \*ARGV);

    Please bottom post....

    Brian Volk wrote: 

    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

     
    >
    > ----------------------------------------------------------------------------

    >
    >
    > 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.
    >

    >
    >
    > No need to use a while here, since you already have a complete array,
    >
    > foreach my $file (files) {
    >

    >
    >
    > 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.
    >

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

    >
    >
    > 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.
    >

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

    >
    >
    > http://danconia.org
    >
    >[/ref]
    Wiggins Guest

  3. #3

    Default RE: perl crashing at $image->Read (file=> \*ARGV);

    Wiggins d'Anconia wrote:
     

    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:org]
    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: 
    think 


    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

     
    >
    >[/ref]
    ---------------------------------------------------------------------------- 
    >
    >
    > 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.
    >

    >
    >
    > No need to use a while here, since you already have a complete array,
    >
    > foreach my $file (files) {
    >

    >
    >
    > 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.
    >

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

    >
    >
    > 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.
    >

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

    >
    >
    > http://danconia.org
    >
    >[/ref]

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


    Brian Guest

  4. #4

    Default RE: perl crashing at $image->Read (file=> \*ARGV);

    Brian Volk wrote:
     
    Files/ 
    Files/PerlEdit/sc 
    it >.hits "Scale", I get the undefined value error. I'm not sure what that
    means.

    No need to respond. I was using "my" agian on the same variable. It works
    now.

    Brian

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

    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";
    $img->Scale(width=>'30', height=>'30');
    $img->Write("jpg:$image_dest_folder\\$image_source_file ");
    undef $img;
    }
    }

    -----Original Message-----
    From: Brian Volk
    Sent: Monday, September 13, 2004 10:18 AM
    To: 'Beginners (E-mail)'
    Subject: RE: perl crashing at $image->Read (file=> \*ARGV);


    Wiggins d'Anconia wrote:
     

    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:org]
    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: 
    think 


    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

     
    >
    >[/ref]
    ---------------------------------------------------------------------------- 
    >
    >
    > 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.
    >

    >
    >
    > No need to use a while here, since you already have a complete array,
    >
    > foreach my $file (files) {
    >

    >
    >
    > 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.
    >

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

    >
    >
    > 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.
    >

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

    >
    >
    > http://danconia.org
    >
    >[/ref]

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


    Brian Guest

Similar Threads

  1. Can PHP read wmv file as image?
    By NOSPAMNONAME in forum PHP Development
    Replies: 1
    Last Post: September 2nd, 09:48 PM
  2. How to read a pdf file in perl
    By Mallik in forum PERL Beginners
    Replies: 2
    Last Post: May 14th, 10:55 AM
  3. Can PHP read an image file?
    By Randy in forum PHP Development
    Replies: 12
    Last Post: January 23rd, 12:50 AM
  4. read VB file with Perl
    By Gregory Toomey in forum PERL Miscellaneous
    Replies: 16
    Last Post: September 7th, 05:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139