上次通过终端测试PHP是否能够实现PS正片叠底、滤色等效果,具体文章可以查看《Shell命令使用ImageMagic实现PS正片叠底、滤色等效果》
在确定PHP可以实现后,这边查找资料通过PHP程序来实现效果,因为需要实时的合成多张效果图,所以通过终端方法不合适,最终实现方案所下所示:
<?php
$types = [
'Normal' => \Imagick::COMPOSITE_DEFAULT,
'Multiply' => \Imagick::COMPOSITE_MULTIPLY,
'Screen' => \Imagick::COMPOSITE_SCREEN,
'Overlay' => \Imagick::COMPOSITE_OVERLAY,
'Darken' => \Imagick::COMPOSITE_DARKEN,
'Lighten' => \Imagick::COMPOSITE_LIGHTEN,
'ColorDodge' => \Imagick::COMPOSITE_COLORDODGE,
'ColorBurn' => \Imagick::COMPOSITE_COLORBURN,
'HardLight' => \Imagick::COMPOSITE_HARDLIGHT,
'SoftLight' => \Imagick::COMPOSITE_SOFTLIGHT,
'Difference' => \Imagick::COMPOSITE_DIFFERENCE,
'Exclusion' => \Imagick::COMPOSITE_EXCLUSION,
'Hue' => \Imagick::COMPOSITE_HUE,
'Saturate' => \Imagick::COMPOSITE_SATURATE,
'Colorize' => \Imagick::COMPOSITE_COLORIZE,
'Luminize' => \Imagick::COMPOSITE_LUMINIZE
];
$lists = [
"title" => "测试",
"width" => 1920,
"height" => 920,
"layers" => [
[
"index" => 1,
"lists" => [
[
"url" =>"/test/58f235f5-74-1.jpg",
"left" => 0,
"top" => 0,
"type" => 40
],
[
"url" =>"/test/66fb8712dcec.jpg",
"left" => 0,
"top" => 0,
"type" => 29
]
]
]
]
];
public function compositeImg($lists) {
foreach ($lists as $item) {
$imagick->compositeImage(new \Imagick($item['url']), $item['type'], $item['left'], $item['top']);
}
$path = "/test/{$data['info']['title']}.png"
$output = public_path() . "{$path}";
$dir = public_path() . "test";
if (!is_dir($dir)) {
mkdir($dir,0777,true);
}
$result = $imagick->writeImage($output);
return $output;
}
以下为部分混合模式生成的效果图:
排除模式  滤色模式  颜色淡减模式  色相模式  强光模式  柔光模式 
|