in reply to Re: Using Image::Size
in thread Using Image::Size

I inserted the two lines after the close(DIR) for a snippet of the following:
opendir(DIR,"../images/dir/name"); @files = readdir(DIR); close(DIR); use Data::Dumper; print \@files;
This gave me the following output: ARRAY(0x8057b2c)

I am new to Perl, and I am not sure what this means. I then tried your second suggestion, for a code of the following:
@files = glob '../images/dir/name/*.{jpg,JPG}'; use Image::Size; for(@files) { my ($x, $y) = imgsize($_); print "$_: x=$x, y=$y<BR>\n"; }
This gave me an output of: ../images/dir/name: x=, y=

I am still a little confused about what to try next, so if anyone has any suggestions, I would appreciate it.

Thanks so much for the help,
Kyle

Replies are listed 'Best First'.
Re^3: Using Image::Size
by Tanktalus (Canon) on Sep 24, 2005 at 02:28 UTC

    Ok, knowing your skill level is always a plus on how we approach helping you. So we'll take it in smaller steps here. First question: is the directory name right? If you run "dir ..\images\dir\name" if Windows or "ls ../images/dir/name" if Linux/unix, do you see the files you want to work with? If not, you need to convert to using the right directory names.

    There are ways to do this dynamically as something relative to where your script lives, but let's not cover too much ground in a single node here, so it may just be easier to put in the full path name such as "C:/images/dir/name" on Windows or "/home/kmarshall/images/dir/name" on Linux/unix. We can cover doing this in other ways at another time.

    Ok, now next step. Just put the following in your program:

    @files = glob '/home/kmarshall/images/dir/name/*'; use Data::Dumper; print Dumper(\@files);
    and tell us what it says. Of course, put in the right path name that applies to where your images are.

    Once we have gotten that far, it will be much easier to continue on from there.

      I used the following code with the right path:
      @files = glob '/home/kmarshall/public_html/images/KYX/Eta Class/*.{jpg +,JPG}'; use Data::Dumper; print Dumper(\@files);
      This gave me the following: $VAR1 = '/home/kmarshall/public_html/images/KYX/Eta' ;

      It is important to note that the last directory in the out put is only "Eta" and not "Eta Class" like the code specified. I am not sure what this means.

      Thanks,
      Kyle

        It means that having spaces in your filenames is a very, very bad idea. Now I see why you need to use opendir/readdir/closedir. This was very relevant information that you omitted in your original post that led towards a suboptimal suggestion from me.

        My first recommendation is to remove the space. Either chop it out or change it to underscore. That will simplify your life in many ways.

        The next suggestion is to switch to using File::Glob::bsd_glob. You can do that by changing your @files line to:

        use File::Glob qw(:glob); @files = bsd_glob '/home/kmarshall/public_html/images/KYX/Eta Class/*. +{jpg,JPG}';
        The difference between glob and bsd_glob is that glob first splits on spaces and then calls bsd_glob for each item. bsd_glob will treat its parameter as a single glob to be dealt with - so the space doesn't have any meaning other than a character in the file name.

Re^3: Using Image::Size
by nedals (Deacon) on Sep 24, 2005 at 01:57 UTC

    What you are printing is a reference to the array
    It should be..

    print Dumper(\@files);