我正在尝试使用Image :: Magic为图像添加水印,我继续发现此错误
Can't call method "Read" on an undefined value at ImageUploader.pl line xxx.
女巫是:
$Logo->Read('../Data/Images/Watermark.png');
在下面的代码中,无法弄清楚路径是否正确,文件是否存在。
有什么想法吗?
use Image::Magick;
my $NewImage = Image::Magick->new;
$NewImage->Read("../Data/Temp/Images/$SaveAs$Extension");
my ($Width,$Height) = $NewImage->Get('width','height'); # find dimensions
my $ResizedWidth = 275;
my $ResizedHeight = 450;
my $MeduimThumbnailWidth = 300;
my $MeduimThumbnailHeight = 300;
if($Height >= $ResizedHeight){
my $ResizedHeight = int($Height * ($ResizedWidth / $Width));
$Logo->Read('../Data/Images/Watermark.png');
$NewImage->Composite(compose=>'blend', blend=>'50x50', x=>'50', y=>'50', image=>$Logo,);
$NewImage->Resize(width=>$ResizedWidth, height=>$ResizedHeight);
$NewImage->Write("../Data/Images/$URL/$SaveAs\_lrg$Extension");
}else{
$NewImage->Write("../Data/Images/$URL/$SaveAs\_lrg$Extension");
}
答案 0 :(得分:3)
$Logo
未定义,因为您从未为其指定值。
可能你错过了:
my $Logo = Image::Magick->new();
你也失踪了:
use strict;
use warnings;
...应出现在所有现代Perl程序中。