English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
imagemagick introduction
imagemagick is an image processing software with powerful image processing capabilities. This article uses PHP to call imagemagick to achieve the effect of converting images to old photos.
imagemagick address: www.imagemagick.org
imagemagick installation
You need to install imagemagick, the installation method is as follows: Click to view
To generate the old photo effect using imagemagick, you need to perform the following steps
1.Use sepia to process the input image-process with the tone filter
2.Generate a white mask, fill with random noise, convert to grayscale, and add an alpha channel
3.The steps1and the following steps2The result is composed using the overlay method
The code is as follows:
<?php /** * PHP call imagemagick to implement the old photo effect * Date: 2016-12-31 * Author: fdipzone * Ver: 1.0 */ /** * Call imagemagick to implement the old photo effect * @param String $source Source Image * @param String $dest Destination Image */ function createOldPhoto($source, $dest){ // Command Line $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); // Execute Command exec($cmd); } // Original Image $source = dirname(__FILE__).'/source.jpg'; // Generate Effect Image $dest = dirname(__FILE__).'/dest.jpg'; // Create Effect Image createOldPhoto($source, $dest); // Display comparison of original image and effect image echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">; echo '<p>Original Image</p>'; echo '<p><img src="'.basename($source).'"></p>'; echo '<p>Effect Image</p>'; echo '<p><img src="'.basename($dest).'"></p>'; ?>
Comparison of Original Image and Generated Old Photo Effect
Summary
That's all about using PHP to call imagemagick to achieve the effect of old photos. I hope the content of this article can bring some help to everyone's learning or using PHP. If you have any questions, you can leave a message for communication.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email for reporting, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.)