【发布时间】:2015-01-07 19:23:09
【问题描述】:
我正在尝试向我的服务器发送一个经过 base64 编码的图像(减去关于 data:image/jpeg;base64, 的起始位)。
我想在制作缩略图后上传图片 - 我正在使用图片魔术。
如何让 image magick 将我的 base64 字符串读取为图像,以便我可以修改并保存它?
到目前为止我的代码:
my $extension = 'jpg';
my $full_filename = $photo_filepath . $cand->id . '.' . $extension;
require Image::Magick;
my $cand_photo = Image::Magick->new;
my $decoded = decode_base64($args{image_string});
$cand_photo->read(blob=>$decoded);
#save original
$cand_photo->Write($full_filename);
#resize
$cand_photo->Set( Gravity => 'Center' );
$cand_photo->Resize( geometry => '120x120' );
$cand_photo->Extent( geometry => '120x120' );
my $full_filename_120
= $photo_filepath . $cand->id . '_120x120.' . $extension;
#save thumbnail
$cand_photo->Write($full_filename_120);
编辑:已经搞定了,上面的代码实际上是正确的,问题出在我的其他地方!
【问题讨论】: