php编程用imagick组件给图片增加圆角和倒影的代码
本人windows下面调用的imagick.dll组件4.21,很遗憾没有成功,大家可以试试linux和apache,或者使用最新版本的imagick,据说作者使用的3.6竟然也成功了,我一时懒惰没有测试了:<?php
/* Read the image into the object */
$im = new Imagick( 'strawberry.png' );/* Make the image a little smaller, maintain aspect ratio */
$im->thumbnailImage( 200, null );/* Round corners, web 2.0! */
$im->roundCorners( 5, 5 );/* Clone the current object */
$shadow = $im->clone();/* Set image background color to black
(this is the color of the shadow) */
$shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) );/* Create the shadow */
$shadow->shadowImage( 80, 3, 5, 5 );/* Imagick::shadowImage only creates the shadow.
That is why the original image is composited over it */
$shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 );/* Display the image */
header( "Content-Type: image/png" );
echo $shadow;?>
源文件:
最终效果:
上面那个编程例子还增加倒影,下面这个最直接:
<?php
$image = new Imagick();
$image->newPseudoImage(100, 100, "magick:rose");
$image->setImageFormat("png");$image->roundCorners(5,3); //这个地方是关键 一句话搞定
$image->writeImage("rounded.png");
?>
大家可以看看我用php+gd做的类似的效果:http://www.zhaoxi.org/h/20.htm 源码见下一页