paintOpaqueImage() making edges rough

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
halichu
Posts: 5
Joined: 2014-09-22T06:03:40-07:00
Authentication code: 6789

paintOpaqueImage() making edges rough

Post by halichu »

This is the code I have:

Code: Select all

<?php
header('Content-type: image/png');

$oldColor = '#000000';
$baseColor = '#f9d9c4';

$base = new Imagick('assets/background.png');
$image = new Imagick('assets/lop-base2.png');
$color = new Imagick('assets/lop-color2.png');

$base->thumbnailImage(200, 0);
$color->thumbnailImage(200, 0);
$image->thumbnailImage(200, 0);

// Set base color
$color->paintOpaqueImage($oldColor, $baseColor, 255);
$color->paintTransparentImage($baseColor, .80, 100);

// Place layer on image
$base->compositeImage($image, Imagick::COMPOSITE_DEFAULT, 0, 0);
$base->compositeImage($color, Imagick::COMPOSITE_DEFAULT, 0, 0);

// Let's merge all layers (it is not mandatory).
$base->flattenImages();

echo $base;

?>
This has a background, layers the shading on top, and then layers the overlay on it (the base color of the bunny).

This is the overlay image ($color):

Image

And this is what it produces:

Image

It's not coloring the very edges because the edges are very soft and they aren't #000000.. I thought that's what the tolerance was for though (3rd parameter in paintOpaqueImage()).. I have it set at it's highest and it still won't color the edges softly... I can't have it all ridged like because of the style of the art and especially when the markings come into play. I just don't want it looking all pixeled. Is there anyway to solve this?

I've tried:

Code: Select all

$color->colorizeImage($baseColor, 100);
$color->paintTransparentImage($baseColor, .80, 100);
but that doesn't take opacity into consideration. It just ignores it. I tried putting .8 as the second parameter, but it colors the entire canvas and it doesn't do a good job since it's lifting from black to whatever the base color is... I need the base color 100% opacity and then drop that down to .80 opacity if you know what I'm trying to say..

Thank you.

I've also tried this:

Code: Select all

$color->colorizeImage($baseColor, 1);
$color->setImageOpacity(.80);
And it displays this:

Image

I only wanted the silhouette part to be faded.. But instead the setImageOpacity gets rid of the silhouette completely and just fills the entire square and sets the opacity..
Last edited by halichu on 2014-09-22T09:57:41-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: paintOpaqueImage() making edges rough

Post by snibgo »

I don't do PHP, and don't fully understand what you want.

I think you want to turn that silhouette pink. It it currently entirely black, with varying alpha. The "-opaque" operator only works on fully opaque pixels. I expect paintOpaqueImage() is the same.

The "-colorize" operator does what you want.

Code: Select all

convert convert DRDNiwx.png -fill #f9d9c4 -colorize 100 b.png
I suppose the PHP function is colorizeImage().
snibgo's IM pages: im.snibgo.com
halichu
Posts: 5
Joined: 2014-09-22T06:03:40-07:00
Authentication code: 6789

Re: paintOpaqueImage() making edges rough

Post by halichu »

Yeah if you look at my second example, I did do colorizeImage() and it works perfectly.. but unfortunately, the opacity doesn't work the way I wanted it to when I set it to .8 instead of 1. I have an image preview of what it's showing when I do that.

I'm looking to paint the entire thing at 100% of the base color and then lower the opacity. But I can't seem to do that...

EDIT:

I just tried doing this, but it won't color over it.. I was saying if I would have more control this way:

Code: Select all

$draw = new ImagickDraw();
$baseColor2 = new ImagickPixel($baseColor);
$draw->setFillColor($baseColor2);
$draw->setFillOpacity(.8);
$color->drawImage( $draw );
It just shows the black silhouette that was there initially.

EDIT:

Figured out something very important.... I noticed colorizeImage() wasn't coloring it the exact color I told it to.

Here is my code:

Code: Select all

$color->colorizeImage($baseColor, 1);
$color->paintTransparentImage('#f3b997', .8, 6553);
The $baseColor holds the value of '#f9d9c4' but I did a print screen and highlighted the color it was painting it and it was actually f3b997.. so now I don't really know what to do because I can't get the color image because I won't know the exact y and x values of where the color actually appears in the canvas.

Any further assistance in this area?
Last edited by halichu on 2014-09-22T10:16:50-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: paintOpaqueImage() making edges rough

Post by snibgo »

The image starts with opacity that varies from 0 to 100%. If you set it to 80%, then it will have a constant opacity of 80%.

Perhaps you want to multiply the opacity by 0.8. Then the opacity will vary between 0 and 80%. At the command line, this would be:

Code: Select all

... -channel A -evaluate multiply 0.8 +channel ...
snibgo's IM pages: im.snibgo.com
halichu
Posts: 5
Joined: 2014-09-22T06:03:40-07:00
Authentication code: 6789

Re: paintOpaqueImage() making edges rough

Post by halichu »

snibgo.. thank you so much. I can't believe I didn't think of setting it at 80% opacity in Photoshop and just colorizing it from there.. I was going to go down the route I posted in my edit, but it's tough trying to get the color of the image without knowing the position.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: paintOpaqueImage() making edges rough

Post by snibgo »

I suspect (but I'm not sure) you can also get what you want by replacing

Code: Select all

$draw->setFillOpacity(.8);
... by ...

Code: Select all

$draw->evaluateImage (EVALUATE_MULTIPLY, .8, COLOR_OPACITY);
snibgo's IM pages: im.snibgo.com
Post Reply