Home > Article > Backend Development > How to call php imagemagick to achieve old photo effect
imagemagick is an image processing software with powerful image processing capabilities. This article uses PHP to call imagemagick to process the image into an old photo effect. imagemagick address: www.imagemagick.org
You need to install imagemagick. The installation method is as follows: Click to view
To use imagemagick to generate old photo effects, you need to perform the following steps
1 .Use the sepia-tone filter to process the input image
2. Generate a white mask, fill it with random noise, convert it to grayscale, and add an alpha channel
3. Use the results of steps 1 and 2 Overlay method compose
The code is as follows:
<?php/** * php 调用imagemagick实现老照片效果 * Date: 2016-12-31 * Author: fdipzone * Ver: 1.0 *//** * 调用imagemagick实现老照片效果 * @param String $source 原图 * @param String $dest 目的图 */function createOldPhoto($source, $dest){ // 命令行 $cmd = sprintf("convert '%s' -sepia-tone '75%%' \( '%s' -fill '#FFFFFF' -colorize '100%%' +noise Random -colorspace gray -alpha on -channel A -evaluate Set 100 \) -compose overlay -composite '%s'", $source, $source, $dest); // 执行命令 exec($cmd); }// 原图$source = dirname(__FILE__).'/source.jpg';// 生成效果图$dest = dirname(__FILE__).'/dest.jpg';// 创建效果图createOldPhoto($source, $dest);// 显示原图与效果图比较echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';echo '<p>原图</p>';echo '<p><img src="'.basename($source).'" alt="How to call php imagemagick to achieve old photo effect" ></p>';echo '<p>效果图</p>';echo '<p><img src="'.basename($dest).'" alt="How to call php imagemagick to achieve old photo effect" ></p>';?>
Comparison of the original image and the generated old photo effect
imagemagick is an image processing software with powerful image processing capabilities. This article uses PHP to call imagemagick to process the image into an old photo effect.
imagemagick address: www.imagemagick.org
You need to install imagemagick. The installation method is as follows: click to view
This article explains how to use php imagemagick to achieve the old photo effect. For more related content, please pay attention to the php Chinese website.
Related recommendations:
About PHP's explanation of calculating the Cartesian product of multiple sets
About the use of PHP file containing directory configuration open_basedir And performance analysis
Explanation on the solution to cookie loss in ajax cross-domain access
The above is the detailed content of How to call php imagemagick to achieve old photo effect. For more information, please follow other related articles on the PHP Chinese website!