开发者

Simulate Photoshop's Multiply in PHP with gd or ImageMagick

开发者 https://www.devze.com 2023-01-11 13:17 出处:网络
Having until now only used PHP\'s gd image library to resize, crop and greyscale images I\'m currently struggling to find a way to simulate what happens when, in Photoshop, you place a coloured layer

Having until now only used PHP's gd image library to resize, crop and greyscale images I'm currently struggling to find a way to simulate what happens when, in Photoshop, you place a coloured layer over a greyscale image and select 'multiply' from the layer effects menu. Or, as my old print lecturer would explain it, I need to make a duotone.

For some reason I had thought that all I needed to do was to simply turn the image greyscale and then drop a coloured layer with an transparency value less than 100% over the top. Once I'd done this I wondered why I ever thought I'd get anything other than washed-out.

Having then trawled the gd library documentation, all I could find was the IMG_EFFECT_OVERLAY filter to use with imagelayereffect but the result of this keeps the white of my greyscale image white rather than making it red.

I haven't used ImageMagick before (but this is one of those rare occasions where I have control over the server so I can install it if I need to) and, having glanced at the documentation in the past, I had presumed that something like Photoshop's multiply would be one of its default filters. Alas no.

My tired brain is struggling to understand what Photoshop's multiply is actually doing on a pixel by pixel basis so I don't what, if any, series of ImageMagick's (or if possible, gd's) more basic filters I could use to get the result I need.

A deadline looms and Google refuses to return an开发者_Go百科y useful results so any help here would be gratefully received.


I find this the easiest way to apply Multiply in imagemagick PHP

$print = new Imagick("blank.jpg");
$printOverlayTexture = new Imagick("overlay.jpg");
$print->compositeImage($printOverlayTexture, Imagick::COMPOSITE_MULTIPLY, 0, 0);


ImageMagick does have a multiply operation. I can't say how close it is to Photoshop's in result and quality (I don't really understand what it does either :), but be sure to try it out.


For what it's worth, here is a collection of handy-dandy ImageMagick scripts. They are not mine, but I frequently find myself referring back to them

ImageMagick Scripts

0

精彩评论

暂无评论...
验证码 换一张
取 消