The following script runs in a loop, retrieving images using LWP::UserAgent
, and resizing them using Image::Magick
.
I am getting this error from Image::Magick
when reading the downloaded image:
Exception 450: Unsupported marker type 0x54
If I download the LWP-downloaded image to my computer, open it in a photo editor, save as a .jpg file, upload it and attempt to read with Image::Magick
then all is fine. This would lead me to believe that the image is not saving correctly.
I need to use LWP::UserAgent
because the server I am connecting to won't allow the download unless it thinks a client is requesting the data.
use LWP::UserAgent;
use Image::Magick;
$ua = new LWP::UserAgent;
$ua->agent("$0/0.1 " . $ua->agent);
$ua->agent("Mozilla/8.0");
my $PICURL ="http://www.example.com/img.aspx?pid=cjfsaf79afffafhfah777af7";
my $PICDEST ="/var/vhosts/mysite.com/httpdocs/images";
my $PICNAME ="01.jpg";
my $response = $ua->get("$PICURL");
open(outfile, ">:raw", "$PICDEST/$PICNAME");
binmode outfile;
if ($response->is_success) {
print outfile $response->content;
$Pi++;
$PTOT++;
}
else {
die $response->status_line;
}
$image = new Image::Magick;
$image->Read("$PICDEST/$PICNAME");
$image->Scale(width=>800, height=>600);
$image->Write("$PICDEST/$PICNAME");
$image->Scale(width=>216, height=>163);
$image->Set(quality=>90);
$image->Write("$PICDEST/TH_$PICNAME");