以下脚本循环运行,使用 检索图像LWP::UserAgent,并使用 调整它们的大小Image::Magick。
Image::Magick读取下载的图像时出现此错误:
Exception 450: Unsupported marker type 0x54
如果我将 LWP 下载的图像下载到我的计算机,在照片编辑器中打开它,另存为 .jpg 文件,上传并尝试阅读,Image::Magick那么一切都很好。这会让我相信图像没有正确保存。
我需要使用LWP::UserAgent,因为我连接的服务器不允许下载,除非它认为客户端正在请求数据。
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");