【发布时间】:2011-01-29 16:45:32
【问题描述】:
我发现这个 PHP 版本似乎是我需要的结果。
<?php
try
{
/*** a new Imagick object ***/
$im = new Imagick('images/spork.jpg');
/*** set the image format to png ***/
$im->setImageFormat('png');
/*** an object for the drop shadow ***/
$shadow = $im->clone();
/*** an object for the drop shadow ***/
$drop_shadow = $im->clone();
/*** set shadow color to black ***/
$drop_shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) );
/*** Create the shadow ***/
$drop_shadow->shadowImage( 80, 3, 5, 5 );
/*** stick them together ***/
$drop_shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 );
/*** write image to disk ***/
$drop_shadow->writeImage( '/tmp/dropshadow.png' );
echo 'Wrote Image';
}
catch(Exception $e)
{
echo $e->getMessasge();
}
?>
(试图发布图片,不让我。) 此处示例:spork with drop shadow
现在,我已经获得了在 Perl 中使用它所需的结果(带有另一个图像):
#!/usr/bin/perl -w
use strict;
my imageurl='http://nonprofit.org/images/someimage.jpg';
my $contact='email@email.org';
system("montage $imageurl -geometry 476x356 -background '#F7F7F7' -quality 90 -fill '#ffffff' -shadow \ -stroke '#000C' -strokewidth 2 -gravity SouthWest -font Candice -pointsize 14 -annotate +2+1 '$contact' \ -stroke none -fill white -gravity SouthWest -font Candice -pointsize 14 -annotate +2+2 '$contact' \ -gravity center $new");
system("montage $new -geometry 480x360 -background '#F7F7F7' -quality 90 -fill '#F7F7F7' $new");
这给了我一个很好的阴影纵横比(ed)图像,中心在一个 480x360 的框/画布中,与页面 bgcolor f7f7f7 匹配。
现在,我希望在不使用系统方法的情况下做到这一点。
所以,我尝试了这个:
#!/usr/bin/perl -w
use Image::Resize;
use Image::Magick;
use strict;
my imageurl='http://nonprofit.org/images/someimage.jpg';
my $contact='email@email.org';
my $ibig = Image::Magick->new;
$ibig->Read("$imageurl");
$ibig->Resize(geometry=>'476x356');
$ibig->Montage(geometry=>'476x356',
background=>'#F7F7F7',
quality=>90,gravity=>'center',
shadow=>80x4+4+4);
#tried shadow=>'true' and '1' and many other variations.
$ibig->Annotate(text=>$contact,
x=>2,y=>1,
font=>'Candice',
pointsize=>14,
stroke=>'#000C',
strokewidth=>2,
gravity=>'SouthWest');
$ibig->Annotate(text=>$contact,
x=>2,y=>2,
font=>'Candice',
pointsize=>14,
fill=>'#ffffff',
stroke=>'none',
gravity=>'SouthWest');
$ibig->Montage(geometry=>'480x360',
background=>'#F7F7F7',
quality=>90,
fill=>'#F7F7F7');
$ibig->Write("$new");
这不起作用。注释有效,但没有阴影,图像通常以 479x360 结束。
系统方法完美无缺,但是,我真的很想通过我的 Image::Magick 示例来学习如何做到这一点。
我花了两天时间研究这个并阅读人。
当我想不通时,我会使用 stackoverflow 并始终得到解决方案!
提前致谢。
(对不起,格式问题。我试图清理它。)
【问题讨论】:
-
“当我想不通的时候,我就来stackoverflow,总能得到解决方案!”那为什么你的声望只有 1?
-
不知道。来这里一年了。也许是因为我总是在一天结束时删除我的 cookie?无论如何不要关心代表,而不是在这里。这会影响我获得答案的能力吗?关心我..
标签: perl imagemagick shadow