Unwanted semi-transparent and inverted color of text

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
elektryk
Posts: 7
Joined: 2014-10-10T16:37:06-07:00
Authentication code: 6789

Unwanted semi-transparent and inverted color of text

Post 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'));
Image

Other example:

Code: Select all

$text->setFillColor(new ImagickPixel('#000000'));
Image

What I want to achieve:
Image

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted semi-transparent and inverted color of text

Post by fmw42 »

It would help to see the source image.
elektryk
Posts: 7
Joined: 2014-10-10T16:37:06-07:00
Authentication code: 6789

Re: Unwanted semi-transparent and inverted color of text

Post 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:
Image

The color space off all images is Euroscale Coated v2.

Thanks for helping :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted semi-transparent and inverted color of text

Post 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.
snibgo's IM pages: im.snibgo.com
elektryk
Posts: 7
Joined: 2014-10-10T16:37:06-07:00
Authentication code: 6789

Re: Unwanted semi-transparent and inverted color of text

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted semi-transparent and inverted color of text

Post by snibgo »

I don't use PHP, but you might try:

Code: Select all

$text->setFillColor(new ImagickPixel('#00000000'));
snibgo's IM pages: im.snibgo.com
elektryk
Posts: 7
Joined: 2014-10-10T16:37:06-07:00
Authentication code: 6789

Re: Unwanted semi-transparent and inverted color of text

Post by elektryk »

#00000000 is totally transparent. #000000ff on the other hand gives the same effect as #000000. :/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted semi-transparent and inverted color of text

Post 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.
snibgo's IM pages: im.snibgo.com
elektryk
Posts: 7
Joined: 2014-10-10T16:37:06-07:00
Authentication code: 6789

Re: Unwanted semi-transparent and inverted color of text

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Unwanted semi-transparent and inverted color of text

Post by snibgo »

"IMagick" is the name of this PHP interface to ImageMagick. It has its own forum: viewforum.php?f=18
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted semi-transparent and inverted color of text

Post 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.
elektryk
Posts: 7
Joined: 2014-10-10T16:37:06-07:00
Authentication code: 6789

Re: Unwanted semi-transparent and inverted color of text

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Unwanted semi-transparent and inverted color of text

Post 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
elektryk
Posts: 7
Joined: 2014-10-10T16:37:06-07:00
Authentication code: 6789

Re: Unwanted semi-transparent and inverted color of text

Post by elektryk »

Your command works like a charm :) I'm executing it via the PHP shell_exec() function. Thanks for help :)
Post Reply