perl: Image grab REGEX

Hi

From the Image-Grab page on cpan

  use Image::Grab;
  my $url ='http://www.example.com/FileName.html'
                      my $pic = Image::Grab->new(SEARCH_URL=>$url,
                                    REGEXP    =>'.*\.jpg');
                  $pic->grab;
                  my $File = basename($url);
                      $File =~ s/html/jpg/i;
                    # Now to save the image to disk
                    open(IMAGE, ">$File") || die"$File: $!";
                    binmode IMAGE;  # for MSDOS derivations.
                    print IMAGE $pic->image;
                    close IMAGE;

Open in new window


I'm getting the error "Couldn't determine an absolute URL!" because the html page I'm searching uses upper case 'JPG' so the regex fails

How do I make the REGEX non case sensitive?

Also can you determine the File name of the image from the REGEX?
" my $File = $pic->name;" causes another error
Can't access `name' field in class Image::Grab
LVL 1
trevor1940Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Well... It appears Image::Grab fails to support passing a pre-compiled regex, so you can't easily say ignore case... so, I'd try this...

.+\.[jJ][pP][eE]?[gG]$

Open in new window

0
ozoCommented:
REGEXP    =>qr'.*\.jpg'i
or
REGEXP    =>'(?i).*\.jpg'

You can get the name from $pic->expand_url
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
trevor1940Author Commented:
In case someone else has similar issue this worked

my $Fold = "Path/To/SaveJPG";
                     unless (-d "$Fold")
                      {
                       make_path("$Fold");
                      }                      

            my $uri   = URI->new($url);
            my $pic = Image::Grab->new(SEARCH_URL=>$url,
            REGEXP    =>qr'.*\.jpg'i); 
            $pic->grab;
            my $File = $Fold . "\\" . basename($pic->expand_url);
           ## check if has extension sometimes basename returns just file name
            unless($File =~m/jpg$/i){
             $File .= ".jpg";
            }
            print "File $File\n";
            
            # Now to save the image to disk
            open(IMAGE, ">$File") || die"$File: $!";
            binmode IMAGE;  # for MSDOS derivations.
            print IMAGE $pic->image;
            close IMAGE;

Open in new window

0
trevor1940Author Commented:
Thanx ozo
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.