Home > Backend Development > PHP Tutorial > How to call php imagemagick to achieve old photo effect

How to call php imagemagick to achieve old photo effect

jacklove
Release: 2023-03-31 06:12:02
Original
1752 people have browsed it

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 &#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="How to call php imagemagick to achieve old photo effect" ></p>&#39;;echo &#39;<p>效果图</p>&#39;;echo &#39;<p><img  src="&#39;.basename($dest).&#39;" alt="How to call php imagemagick to achieve old photo effect" ></p>&#39;;?>
Copy after login


Comparison of the original image and the generated old photo effect

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
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template