ajju has asked for the wisdom of the Perl Monks concerning the following question:

Hi frnds , Using this sub rotuine i used to extract images from webpages by giving inputs as the image location in web and the local location at where the image should be saved. using uri; getstore($imageloc,"picss/".$loc."Images/image$i3c.jpg"); But gif format and other format images extracted from webpages are being stored as jpg by the above code and they are not being opened in my local system when i try to see them.So,how do i change my code so that any format image can be stored in its own format instead of jpg and hence i can see the images after extracted.
  • Comment on How to save different format of images from webpages

Replies are listed 'Best First'.
Re: How to save different format of images from webpages
by roboticus (Chancellor) on Nov 21, 2010 at 21:45 UTC

    ajju:

    Just save the image with the extension that matches the source image, rather than forcing a .jpg on the end.

    ...roboticus

      how to know the source image format...
        Either the url tells you, or the headers tell you, or nothing tells you and you have to guess

        LWP::MediaTypes, File::MMagic

        $ ls -loanh *.gif -rw-rw-rw- 1 0 53 2010-09-17 23:39 working.gif $ perl -MWWW::Mechanize -le" $ua = WWW::Mechanize->new; $ua->get('file +:working.gif'); die $ua->ct; " image/gif at -e line 1. $ perl -MWWW::Mechanize -MLWP::MediaTypes=media_suffix -le" $ua = WWW: +:Mechanize->new; $ua->get('file:working.gif'); die media_suffix( $ua- +>ct ); " gif at -e line 1.
Re: How to save different format of images from webpages
by ww (Archbishop) on Nov 22, 2010 at 00:55 UTC
    if you are determining the location of the image on the web via your code, you need not assign a type; just let the existing filename.typ pass through your code.
Re: How to save different format of images from webpages
by Anonymous Monk on Nov 21, 2010 at 21:47 UTC
    You make with the clicking of the keyboards until .jpg is replaced by a variable which contains the correct extension to use :)