Page 1 of 1
Unwanted semi-transparent and inverted color of text
Posted: 2014-10-10T16:57:45-07:00
by elektryk
Hi, I'm using ImageMagick to copy some images and add text to them.
The problem is that I want to make a solid, not transparent white text. What I get is something different.
Example:
Code: Select all
$text->setFillColor(new ImagickPixel('#ffffff'));
Other example:
Code: Select all
$text->setFillColor(new ImagickPixel('#000000'));
What I want to achieve:
Full code can be found here:
http://pastebin.com/Ra9tjVEJ
Any idea what's wrong with my code? Or maybe it's a bug in IM?
OS: Ubuntu 12.04.2 LTS
API: PHP 5.3.10
ImageMagick 6.6.9-7
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-10T20:38:05-07:00
by fmw42
It would help to see the source image.
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T01:06:14-07:00
by elektryk
bg.tif - Base image. Making an empty image using IM cause the copied image to become lighter. Maybe it's a problem with semi-transparency too?
u.tif The image which is copied many times and which is a background for the text.
Additonally, here are the saving settings:
The color space off all images is
Euroscale Coated v2.
Thanks for helping

Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T03:53:25-07:00
by snibgo
Your source images are CMYK. I expect the lightest white would come from no ink at all, thus zero in all four channels.
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T04:51:07-07:00
by elektryk
Yeah, I know that my images are in CMYK. that's why I'm using ImageMagick in PHP, not GD library. But can you explaine me how to fix the text color?
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T05:14:46-07:00
by snibgo
I don't use PHP, but you might try:
Code: Select all
$text->setFillColor(new ImagickPixel('#00000000'));
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T05:18:05-07:00
by elektryk
#00000000 is totally transparent. #000000ff on the other hand gives the same effect as #000000. :/
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T05:31:09-07:00
by snibgo
Okay. This is IMagick, which is even further outside my expertise. Instead of '#00000000' you might try 'cmyk(0,0,0,0)' or some other variation.
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T05:45:21-07:00
by elektryk
IMagick is just a shortcut for ImageMagick

I used
Code: Select all
$text->setFillColor(new ImagickPixel('cmyk(255,255,255,255)'));
but the text is still semi-transparent. What about good news is that the colors are now not inverted!
Maybe something is wrong with merging the text and the image?
EDIT:
Or maybe, by default, annotations are make as watermarks?
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T06:11:52-07:00
by snibgo
"IMagick" is the name of this PHP interface to ImageMagick. It has its own forum:
viewforum.php?f=18
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T10:05:23-07:00
by fmw42
IM cannot add text in CMYK space (it does not process colors properly). You need to convert to sRGB, then add text and then convert back to CMYK if you really need to do the latter. This works perfectly fine for me in command line IM 6.8.9.8 Q16 Mac OSX
convert u2.tif -profile /users/fred/images/profiles/sRGB.icc -fill white -font Verdana -pointsize 100 -gravity center -annotate +0+0 "Marcin" result.png
Also png does not support cmyk, so if you really need cmyk for the output, you will need to save as tif or jpg.
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T14:23:15-07:00
by elektryk
Yes, I need it in CMYK because the images will be printed so the color space is important.
For now I found a dirty workaround which have a second one workaround inside. Speaking short: rendering black text work good so I'm making a black text on a transparent background and then I'm using it as a mask on a white background to cut off the white letters.
I don't know if I have enough energy to rework it now

Yes,
I'm losing the font smoothness, but the image is in 300ppi, so after printing it should look good.
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-11T14:30:47-07:00
by fmw42
This works for me and produces CMYK output in tiff format.
Code: Select all
convert u2.tif -profile /users/fred/images/profiles/sRGB.icc \
-fill white -font Verdana -pointsize 100 -gravity center -annotate +0+0 "Marcin" \
-profile /users/fred/images/profiles/USWebCoatedSWOP.icc u2_letters.tif
Re: Unwanted semi-transparent and inverted color of text
Posted: 2014-10-13T13:50:02-07:00
by elektryk
Your command works like a charm

I'm executing it via the PHP shell_exec() function. Thanks for help
