hi i have an image on which i want to put a rotated text(rotated from its center point) here is the command i am using:
C:\imagemagick>convert.exe c:\qr.png -draw "fill #ff0000 text 100,100 mahdi" -distort SRT 45 c:\qr1.png
i dont want the background image to be rotated. I only want text to be rotated on its axis (i.e. center of the text)
text rotation problem
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: text rotation problem
You have to put the text in a separate image, then rotate that. Afterwards you will place the text on the image.
Annotate can rotate text, but it rotates around the placement handle, which depends on Gravity.
You want to center some rotated text on the left edge directly -- forget it. It is simplier to rotate the image place the text and rotate back.
{rant on}
Gravity is used for placement, but it also defines the 'handle' with in the object that is being placed. Typically this is the justification position. The two are different, and yet in IMv6 they are controled by the same variable. IMv7 to-do includes separation of these two items
{rant off}
Distort is particually good for placing rotated text using a handle. that is because, you can define the handle in terms of a position both in the original and final text.
This will be a future IM Example...
Distorted Placement of Text
Okay some text is added to image (using a layers method) at top left corner.
Lets rotate it using distort (layers varient) -- Not the use of parenthesis to limit what image we distort!
Note that the text position was NOT changed! All that happens was that in layers mode the text was simply rotated around the default handle, the center point.
The next step is to move that handle, but for this we need to use almost the FULL SRT distort specification.
http://www.imagemagick.org/Usage/distort/#srt
Because we need to define the 'center handle' as well we need to use some percent escapes,
http://imagemagick.org/script/escape.php
specifically FX percent escapes
http://imagemagick.org/script/fx.php
So lets place the center at +100+100 in the background image
Better, but what if you want to place a 90 degree rotated test on the right edge.
The handle of the text to rotate around and position will be the center bottom: %[fx:w/2],%h
But to get the center left edge: 0,%[fx:h/2] we need to get it from the background image which distort does not have access to.
This needs a special trick to extract information from other images....
http://www.imagemagick.org/Usage/transform/#fx_other
Here is the solution
The "my:" string can be anything that does nto clash with existing prefixes, and is used to keep MY settings, separate to other settings ImageMagick may use for coders or specific options. "my:" is a good choice.
This is purely string substitutions. and in fact we could generate the whole Distort option as a string. The only problem is you can not do math on strings, at least not in IMv6, so any math much be does before hand.
This has been added to IM Examples at...
http://www.imagemagick.org/Usage/annotating/#distort
Annotate can rotate text, but it rotates around the placement handle, which depends on Gravity.
You want to center some rotated text on the left edge directly -- forget it. It is simplier to rotate the image place the text and rotate back.
{rant on}
Gravity is used for placement, but it also defines the 'handle' with in the object that is being placed. Typically this is the justification position. The two are different, and yet in IMv6 they are controled by the same variable. IMv7 to-do includes separation of these two items
{rant off}
Distort is particually good for placing rotated text using a handle. that is because, you can define the handle in terms of a position both in the original and final text.
This will be a future IM Example...
Distorted Placement of Text
Code: Select all
convert logo: -pointsize 36 -background none label:'Some Text' \
-flatten show:
Lets rotate it using distort (layers varient) -- Not the use of parenthesis to limit what image we distort!
Code: Select all
convert logo: \( -pointsize 36 -background none label:'Some Text' \
+distort SRT 70 \
\) -flatten show:
The next step is to move that handle, but for this we need to use almost the FULL SRT distort specification.
http://www.imagemagick.org/Usage/distort/#srt
Because we need to define the 'center handle' as well we need to use some percent escapes,
http://imagemagick.org/script/escape.php
specifically FX percent escapes
http://imagemagick.org/script/fx.php
So lets place the center at +100+100 in the background image
Code: Select all
convert logo: \( -pointsize 36 -background none label:'Some Text' \
+distort SRT '%[fx:w/2],%[fx:h/2] 1 70 100,100' \
\) -flatten show:
The handle of the text to rotate around and position will be the center bottom: %[fx:w/2],%h
But to get the center left edge: 0,%[fx:h/2] we need to get it from the background image which distort does not have access to.
This needs a special trick to extract information from other images....
http://www.imagemagick.org/Usage/transform/#fx_other
Here is the solution
Code: Select all
convert logo: -set option:my:left_edge '0,%[fx:h/2]' \
\( -pointsize 36 -background none label:'Some Text' \
+distort SRT '%[fx:w/2],%h 1 90 %[my:left_edge]' \
\) -flatten show:
This is purely string substitutions. and in fact we could generate the whole Distort option as a string. The only problem is you can not do math on strings, at least not in IMv6, so any math much be does before hand.
This has been added to IM Examples at...
http://www.imagemagick.org/Usage/annotating/#distort
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: text rotation problem
hi actually i am trying to convert svg text to raster image manually. For example i have a free transformed text in SVG like this:
<text style="text-anchor: middle; font: 12px "Arial"; opacity: 1;" x="100" y="100" text-anchor="middle" font="10px Arial" stroke="none" fill="#ff0000" font-size="12px" opacity="1" font-weight="normal" font-style="normal" transform="matrix(0.9848,0.1736,-0.1736,0.9848,-11.1008,206.9808)"><tspan dy="4.5">This is my Text</tspan></text>
for example it was written on some 390x390 svg image. Now i want to convert this text to raster image on same or resized image, say 390x390, 1000x1000, 2000x2000
I am new to imagemagick and really confused how to do so.
<text style="text-anchor: middle; font: 12px "Arial"; opacity: 1;" x="100" y="100" text-anchor="middle" font="10px Arial" stroke="none" fill="#ff0000" font-size="12px" opacity="1" font-weight="normal" font-style="normal" transform="matrix(0.9848,0.1736,-0.1736,0.9848,-11.1008,206.9808)"><tspan dy="4.5">This is my Text</tspan></text>
for example it was written on some 390x390 svg image. Now i want to convert this text to raster image on same or resized image, say 390x390, 1000x1000, 2000x2000
I am new to imagemagick and really confused how to do so.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: text rotation problem
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/