PHP扩展之图像处理3——ImageMagick使用及相关类和方法
2014-11-07 00:00
1326 查看
[b]Example #1 在 Imagick 中创建缩略图
[/b]
<?php header('Content-type: image/jpeg'); $image = new Imagick('image.jpg'); // If 0 is provided as a width or height parameter, // aspect ratio is maintained $image->thumbnailImage(100, 0); echo $image; ?>
Example #2 Make a thumbnail of all JPG files in a directory
<?php $images = new Imagick(glob('images/*.JPG')); foreach($images as $image) { // Providing 0 forces thumbnailImage to maintain aspect ratio $image->thumbnailImage(1024,0); } $images->writeImages(); ?>
Example #3 Creating a reflection of an image
<?php /* Read the image */ $im = new Imagick("test.png"); /* Thumbnail the image */ $im->thumbnailImage(200, null); /* Create a border for the image */ $im->borderImage(new ImagickPixel("white"), 5, 5); /* Clone the image and flip it */ $reflection = $im->clone(); $reflection->flipImage(); /* Create gradient. It will be overlayed on the reflection */ $gradient = new Imagick(); /* Gradient needs to be large enough for the image and the borders */ $gradient->newPseudoImage($reflection->getImageWidth() + 10, $reflection->getImageHeight() + 10, "gradient:transparent-black"); /* Composite the gradient on the reflection */ $reflection->compositeImage($gradient, imagick::COMPOSITE_OVER, 0, 0); /* Add some opacity. Requires ImageMagick 6.2.9 or later */ $reflection->setImageOpacity( 0.3 ); /* Create an empty canvas */ $canvas = new Imagick(); /* Canvas needs to be large enough to hold the both images */ $width = $im->getImageWidth() + 40; $height = ($im->getImageHeight() * 2) + 30; $canvas->newImage($width, $height, new ImagickPixel("black")); $canvas->setImageFormat("png"); /* Composite the original image and the reflection on the canvas */ $canvas->compositeImage($im, imagick::COMPOSITE_OVER, 20, 10); $canvas->compositeImage($reflection, imagick::COMPOSITE_OVER, 20, $im->getImageHeight() + 10); /* Output the image*/ header("Content-Type: image/png"); echo $canvas; ?>
以上例程的输出类似于:
相关文章推荐
- PHP扩展之图像处理1——GD库使用及相关函数
- PHP图像处理(二) GraphicsMagick 安装扩展及使用方法
- PHP扩展之图像处理2——Gmagick库使用示例及相关类和函数
- [置顶] adaptive-images的使用方法 php 服务器端 图片处理相关工具
- 使用php缺少加密扩展mcrypt等相关问题的一些解决方法
- PHP使用imagemagick扩展处理图片
- PHP使用imagick扩展实现合并图像的方法
- PHP 图像处理库ImageMagick windows下的安装
- PHP安装与使用VLD查看opcode代码【PHP安装第三方扩展的方法】
- php学习笔记(十八)php扩展库mysqli的使用和处理结果集
- 使用lockbits方法处理图像(转)
- js一个典型的对象写法,推荐使用这种格式,用于处理图像的基本方法、
- PHP:ImageMagick完美代替GB类库处理图像
- C#中使用lockbits方法处理图像(译文)
- PHP安装扩展mcrypt以及相关依赖项 【PHP安装PECL扩展的方法】
- 浅析PHP安装扩展mcrypt以及相关依赖项(PHP安装PECL扩展的方法)
- 使用lockbits方法处理图像(转)
- PHP:ImageMagick完美代替GB类库处理图像
- 使用lockbits方法处理图像 from http://blog.sina.com.cn/s/blog_4e3e2ce4010009on.html