1

I want to combine two images, one of which is a pattern image and another is color mask.

My problem is the color I get does not match the one I want to receive.

This is my "pattern image" $image:

enter image description here

I then use

$image->compositeImage($ribbon, Imagick::COMPOSITE_COLORBURN, 0, 0);

to combine it with 'color' image

enter image description here

I am expecting the output similar to this:

enter image description here

but what I get is:

enter image description here

The lighter and darker areas come from pattern image, but in general this different color than I would expect. I also tried every other option, including Imagick::COMPOSITE_HARDLIGHT, Imagick::COMPOSITE_OVERLAY etc.

What do I miss here? Maybe I need to make some preparation for $image first? Or use different method of merging images together?

UPD: If I use COMPOSITE_COLORIZE I also don't get the color I need, but much lighter instead enter image description here

2
  • Did you try COMPOSITE_COLORIZE
    – fmw42
    Apr 24, 2018 at 16:52
  • Yes I did try that. Updated my post with the image I get in that case Apr 25, 2018 at 4:06

1 Answer 1

1

Sorry, I do not code Imagick well. But you can try the following in Imagemagick (unix syntax). First, I make the image so that white becomes transparent. Then I trim the white off of the pattern image and tile it out. Then I extract the alpha channel of the image. Then I do a compose multiply using all 3 images where the alpha channel is used as a mask.

convert \( image.png -alpha off -colorspace gray \
-fuzz 2% -transparent white \) \
\( pattern.png -fuzz 20% -trim +repage -write mpr:pattern \
+delete -size 200x152 tile:mpr:pattern \) \
\( -clone 0 -alpha extract \) \
-alpha off -compose multiply -composite result.png

enter image description here

Alternately, doing each step separately and saving the results, which may be easier to convert to Imagick, you can do:

convert image.png -alpha off -colorspace gray grayimage.png
convert pattern.png -fuzz 20% -trim +repage trimpattern.png 
convert -size 200x152 tile:trimpattern.png tiledpattern.png
convert grayimage.png tiledpattern.png -compose multiply -composite multipliedimage.png
convert grayimage.png -fuzz 2% -transparent white -alpha extract alphaimage.png
convert multipliedimage.png alphaimage.png -alpha off -compose copy_opacity -composite -compose over -background white -flatten result2.png

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.