Duplicate Photoshop Luminosity and Color blends with opacity

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
kqwil
Posts: 2
Joined: 2017-02-23T07:57:23-07:00
Authentication code: 1151

Duplicate Photoshop Luminosity and Color blends with opacity

Post by kqwil » 2017-02-23T08:07:45-07:00

I've a pretty simple Photoshop document that I want te replicate using IMagick. Have been trying all day but can't figure it out. I'm not very familiar with image processing. I hope you guys can help me out.

In Photoshop I've 2 images. The bottom layer contains images 1. The second layer consists of the image 2 and the blend 'Luminosity' with an opacity of 55%. The third layer consist of image 2 again, but this time with the blend 'Color'.

Thus Layers:
[image 2 - color]
[image 2 - luminosity 55%]
[image 1]

Let me know if this is not clear.

So far I only got a composition of the two images with an opacity and a colorize. This gives a result similar to what I've in Photoshop, however this is not sufficient and I would like to duplicate my Photoshop as good as possible.

Code: Select all

$image1 = new Imagick('image1.png');
$image2 = new Imagick('image2.png');

$image1->modulateImage(100 , 0 ,100);

/*
 * opacity
 */
//$image2->setImageOpacity(0.5); //Doesn't work for some reason

$opacity = new Imagick();
$opacity->newPseudoImage(
    $image1->getImageHeight(),
    $image1->getImageWidth(),
    "canvas:gray(75%)"
);

$image2->compositeImage($opacity, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$image1->compositeImage($image2, Imagick::COMPOSITE_ATOP, 0, 0);

/*
 * colorize
 */
$image2 = new Imagick('wallframe.png');
$image1->compositeImage($image2, Imagick::COMPOSITE_COLORIZE, 0, 0);

$image1->writeImage ("result.png");
Last edited by kqwil on 2017-02-23T08:30:12-07:00, edited 1 time in total.

snibgo
Posts: 9404
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by snibgo » 2017-02-23T08:24:07-07:00

So, you have two images (image 1 and image 2). You combine them once with blend mode "Luminosity", and then with "Color".

According to http://www.simplefilter.de/en/basics/mixmods.html , these are simple modes that use HSL or similar colorspace, taking L from one image and HS from the other.

I don't have Photoshop. To help us help you, can you link to URLs of:

1) image 1
2) image 2
3) images 1 and 2 blended 100% with "Luminosity"
4) images 1 and 2 blended 100% with "Color"

Please make these fairly small (eg 200x200 pixels), not lossy compressed (so not JPEG). PNG is fine.

You can upload images to somewhere like dropbox.com and paste the URLs here.
snibgo's IM pages: im.snibgo.com

kqwil
Posts: 2
Joined: 2017-02-23T07:57:23-07:00
Authentication code: 1151

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by kqwil » 2017-02-23T08:44:55-07:00

Correct, I think the only magic Photoshop does that I can reproduce is the luminosity blend with 55% opacity. Which I guess means that it doesn't take the entire L from image 2 but combines the two in some way.

Anyways you seem to understand it better then me, so correct me if I'm wrong.

The images you suggested:

https://www.dropbox.com/s/g1bm2fpysk31w ... 1.png?dl=0
https://www.dropbox.com/s/urie05u9yws7b ... 2.png?dl=0
https://www.dropbox.com/s/dv94p955jxyvm ... y.png?dl=0
https://www.dropbox.com/s/z1nivabfg699k ... r.png?dl=0

And the result I would like to have:

https://www.dropbox.com/s/nhktukzznthck ... r.png?dl=0

snibgo
Posts: 9404
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by snibgo » 2017-02-23T09:26:13-07:00

The answer is as I said, but the IM colorspace isn't HSL, but HCLp. Windows BAT syntax. For bash, replace each ^ with \

Code: Select all

convert psimage2.png psimage1.png ^
  -colorspace HCLp ^
  -separate ^
  -delete 2-4 ^
  -combine ^
  -set colorspace HCLp ^
  x4_col.png

convert psimage1.png psimage2.png ^
  -colorspace HCLp ^
  -separate ^
  -delete 2-4 ^
  -combine ^
  -set colorspace HCLp ^
  x4_lum.png
x4_col.png is the same as your image_1_and_2_blended_100_color.png.

x4_lum.png is almost the same as your image_1_and_2_blended_100_luminosity.png, but the luminosity from image 2 behind the grid is shifted by one pixel. I suspect you accidentally nudged the image when you created it.

Does that solve your problem? Can you get the 55% opacity? If not, then please post the result from PS of luminosity with 55% opacity.
snibgo's IM pages: im.snibgo.com

stewartm82
Posts: 3
Joined: 2017-10-26T21:26:57-07:00
Authentication code: 1151

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by stewartm82 » 2017-10-26T21:29:25-07:00

Thanks for this answer it's exactly what I wanted however I'm not sure how to set the opacity for just the top layer. How would I apply this to the above script?

snibgo
Posts: 9404
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by snibgo » 2017-10-26T22:49:04-07:00

Which script? I didn't exactly understand what the OP meant by opacity, nor what you mean. Please explain your problem, with examples.

Please also say what version of IM you use, on what platform.
snibgo's IM pages: im.snibgo.com

stewartm82
Posts: 3
Joined: 2017-10-26T21:26:57-07:00
Authentication code: 1151

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by stewartm82 » 2017-10-30T15:13:11-07:00

Thanks for your reply. I'm attempting to recreate blending in the same way that photoshop's luminosity layer works. Here is an example of what I am trying to recreate.
Screen Shot 2017-10-31 at 8.58.04 am.png
Screen Shot 2017-10-31 at 8.58.04 am.png (191.37 KiB) Viewed 400 times
This image consists of two photoshop layers. The uppermost layer is set to luminosity with an opacity of 60%. The bottom layer in this case is a pink colour fill however it will be swapped out for a different image on the fly. The idea being to superimpose the top layer on to any other image using the photoshop luminosity blend to create a realistic condensation effect. The layers reset back to the normal filter with an opacity of 100% appear as follows.

Screen Shot 2017-10-31 at 9.10.50 am.png
Screen Shot 2017-10-31 at 9.10.50 am.png (241.53 KiB) Viewed 400 times
The bottom layer is just a colour fill but this will be dynamic
Screen Shot 2017-10-31 at 9.12.04 am.png
Screen Shot 2017-10-31 at 9.12.04 am.png (21.18 KiB) Viewed 400 times
The following is how the designer has setup the photoshop layers
Screen Shot 2017-10-31 at 8.59.13 am.png
Screen Shot 2017-10-31 at 8.59.13 am.png (16.56 KiB) Viewed 400 times
I was hoping to recreate this in imagemagick and I can for the most part with convert scrips that where posted above however I can't seem to recreate the opacity of the luminosity layer.

I'm using
Version: ImageMagick 7.0.7-8 Q16 x86_64
but a this point I'm flexible with the IM version as I am building my own from source.

User avatar
fmw42
Posts: 22107
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by fmw42 » 2017-10-30T15:22:06-07:00

Please post your images not screen snaps.

Using your screen snaps, compare

Without 60% luminosity

Code: Select all

convert pink.png image.png -compose luminize -composite result1.png
Image


With 60% luminosity

Code: Select all

convert pink.png image.png \( -clone 1 -fill "gray(60%)" -colorize 100 \) -compose luminize -composite result2.png
Image


Is that what you want? If not, then swap the two inputs and colorize or luminize

Code: Select all

convert image.png pink.png \( -clone 1 -fill "gray(60%)" -colorize 100 \) -compose colorize -composite result3.png
Image

Code: Select all

convert image.png pink.png \( -clone 1 -fill "gray(60%)" -colorize 100 \) -compose luminize -composite result4.png
Image

ImageMagick may be using HSL colorspace or some other colorspace when luminizing and colorizing than Photoshop. If that is the case, , which is likely, then you will need to use snibgo's method of separating channels in the desired colorspace and then recombine the appropriate combination.

snibgo
Posts: 9404
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by snibgo » 2017-10-30T15:52:04-07:00

I can see the images.

Windows BAT syntax.

Code: Select all

convert ^
  bottleCol.png ^
  bottle.png ^
  -gravity Center -crop 320x370+0+0 +repage ^
  -colorspace HCLp ^
  -separate ^
  ( -clone 2,5 ^
    -compose Blend -define compose:args=25 -composite ^
  ) ^
  -delete 2-5 ^
  -combine ^
  -set colorspace HCLp ^
  -colorspace sRGB ^
  bottleBlnd.png
Image

Explanation: I renamed your images: bottleCol is the solid-colour image. Your images are different sizes, so I have crudely cropped both to the same size. I work in HCLp space, taking H and C from the solid colour image, and L as a blend of the L from both images.

This works fine in v6.9.5-3. In v7.0.3-6 using "magick", the blending doesn't work. I suppose there was a bug which may have now been fixed.
snibgo's IM pages: im.snibgo.com

stewartm82
Posts: 3
Joined: 2017-10-26T21:26:57-07:00
Authentication code: 1151

Re: Duplicate Photoshop Luminosity and Color blends with opacity

Post by stewartm82 » 2017-10-30T21:23:04-07:00

Perfect! Thanks so much! That's exactly what I was hoping for. I can confirm the opacity issue in 7.0.7-8 so it must not have been fixed yet.

Post Reply