-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOldPhotoEffect.php
More file actions
45 lines (41 loc) · 1.19 KB
/
OldPhotoEffect.php
File metadata and controls
45 lines (41 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* php调用imagemagick实现老照片效果
* 依赖 ImageMagick
*
* @author fdipzone
* @DateTime 2023-03-19 11:30:23
*
*/
class OldPhotoEffect
{
/**
* 生成老照片效果图
*
* @author fdipzone
* @DateTime 2023-03-19 11:31:30
*
* @param string $source 原图
* @param string $dest 老照片效果图
* @return boolean
*/
public static function create(string $source, string $dest):bool
{
// 判断原图是否存在
if(!file_exists($source))
{
throw new \Exception('source file not exists');
}
// 检查是否已安装ImageMagick
if(strstr(shell_exec('convert -version'),'Version: ImageMagick')=='')
{
throw new \Exception('ImageMagick not installed');
}
// 命令行
$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);
// 判断是否创建成功
return file_exists($dest)? true : false;
}
}