Text Rotate + Alpha

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
KandisZZ
Posts: 21
Joined: 2011-02-13T05:47:57-07:00
Authentication code: 8675308

Text Rotate + Alpha

Post by KandisZZ »

Hello Forum.
Im searching for hours, with no good results.
Two Questions:

Code: Select all

convert -background none -gravity $align -font Fonts/$font -pointsize $arg[3] -size $arg[0]x$arg[1] -fill '#$arg[4]'  -rotate $arg[8]  caption:'$text' PNG:-
1. Text Rotating
I want to rotate the text on its own position. If I apply the location +0+0 operator, it won't work.
Want it like the Text 4, 5 and 6.
Image
(Picture from http://www.html46.com/Annotate_at_IM.html)

2. Transparency
I get an Hex Color Code for the fill operator. So I cant use the fill RGBA.
How can i use transparency either? Perfectly in percent from 0 - 100;

Greetings and much thx for helping me :)

Marc.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text Rotate + Alpha

Post by fmw42 »

I cannot answer question 1, but for question 2:

you can use hex colors for fill, they just get converted internally by IM to rgb(a), see http://www.imagemagick.org/script/color.php
e.g. -fill "#ffaacc" but be sure to enclose the hex value in quotes.

as for the transparency, you can use hex in your transparent color values again see http://www.imagemagick.org/script/color.php
alternately, you must use rgba(r%,g%,b%,x) or rgba(r,g,b,x) where x is between 0 and 1 again see http://www.imagemagick.org/script/color.php

so just divide your transparency in percent by 100 to get values between 0 and 1.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Text Rotate + Alpha

Post by anthony »

The real problem is that currently IM uses -gravity for BOTH positioning, and justification at that position.

However there is a way out of this problem, look at -draw with gravity. The examples for this is a little odd as it actually even pre-dates IM Examples!
IM Examples, Annotating, Text Positioning with Rotation
http://www.imagemagick.org/Usage/annota ... t_rotation

Until we get a proper justification setting for positioning both text and images on another image, that is the bast that can directly.

Indirectly is another matter! You can
  • render your text into a separate image, with whatever justification, (gravity) you want in that box
  • Now distort that image using SRT, with scale, rotation and more importantally translation to place the text where you want
  • and finally 'layer' the image onto the background.
The only problem with this technique is that you can't position or translate the image with 'gravity' you need to do this yourself by using some equations in the distort string.

I am sure a complete textual/image positioning system could be worked out using SRT distortion.
http://www.imagemagick.org/Usage/distort/SRT
It's arguments was designed with full positioning controls in mind, though only with absolute offsets. However as you can use % escapes you can make your own offsets, relative to the original image, or with some extra work even relative to some other (final destination) image. Also unlike other methods (direct compose) the positioning can be to a sub-pixel level.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
KandisZZ
Posts: 21
Joined: 2011-02-13T05:47:57-07:00
Authentication code: 8675308

Re: Text Rotate + Alpha

Post by KandisZZ »

Thx for your help.

To the Color Thing:
I can only work with Hex Codes.
Theres a way to convert it in php with an external function, but its too slow.

Is there no way to add a alpha value direct to the hex (#123456).
Or add one to the command line (-alpha 50%).


thx again.
indiego
Posts: 75
Joined: 2010-10-16T06:35:10-07:00
Authentication code: 8675308

Re: Text Rotate + Alpha

Post by indiego »

I use

... -fill xc:#FFFFFFD0

to fill some boxes with a transparent color. Donno if this works for you.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text Rotate + Alpha

Post by fmw42 »

Hex colors with alpha values are explained in the link I gave above at http://www.imagemagick.org/script/color.php Your hex values will be eight characters after the #. The last two are the alpha values. If you want 16-bit RGBA, you can do that as well, see the link above.

The questions is will your php code accept those hex values with alpha included?
Post Reply