Home >Backend Development >PHP Tutorial >Use imagemagick in php to achieve old photo effects

Use imagemagick in php to achieve old photo effects

jacklove
jackloveOriginal
2018-06-20 16:52:321711browse

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. Replace step 1 Use the overlay method to compose with the result of step 2
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 &#39;%s&#39; -sepia-tone &#39;75%%&#39; \( &#39;%s&#39; -fill &#39;#FFFFFF&#39; -colorize &#39;100%%&#39; +noise Random -colorspace gray -alpha on -channel A -evaluate Set 100 \) -compose overlay -composite &#39;%s&#39;", $source, $source, $dest);    // 执行命令
    exec($cmd);

}// 原图$source = dirname(__FILE__).&#39;/source.jpg&#39;;// 生成效果图$dest = dirname(__FILE__).&#39;/dest.jpg&#39;;// 创建效果图createOldPhoto($source, $dest);// 显示原图与效果图比较echo &#39;<meta http-equiv="content-type" content="text/html;charset=utf-8">&#39;;echo &#39;<p>原图</p>&#39;;echo &#39;<p><img  src="&#39;.basename($source).&#39;" alt="Use imagemagick in php to achieve old photo effects" ></p>&#39;;echo &#39;<p>效果图</p>&#39;;echo &#39;<p><img  src="&#39;.basename($dest).&#39;" alt="Use imagemagick in php to achieve old photo effects" ></p>&#39;;?>


Comparison of the effect of the original image and the generated old photo

Use imagemagick in php to achieve old photo effects

This article explains how to achieve old photo effects through imagemagick in php. For more related content, please pay attention to the php Chinese website.

Related recommendations:

Related knowledge on how to calculate the Cartesian product of multiple sets through PHP

Developed by WeChat Share interface related content

css implementation of arrows and notched prompt boxes

The above is the detailed content of Use imagemagick in php to achieve old photo effects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn