0

How do I rotate a text and then draw in graphicsmagick? It a simple question, but I couldn't understand it from the API.

Help would be appreciated. Thank you. I am using gm by the way, but doing it from the command line is enough also.

Also, there is an open issue about this subject. https://github.com/aheckmann/gm/issues/660

OpenCV or Imagemagick alternative is possible, if we can not do it with graphicsmagick.

fmw42
  • 46,825
  • 10
  • 62
  • 80
Ali Somay
  • 585
  • 8
  • 20

2 Answers2

1

I agree with Mark Setchell. The question is ambiguous. In ImageMagick, you can draw rotated text in a number of ways. The -annotate function will do that via its arguments. You can also create a new text image using label: and then rotate that and compose it over your background image. See http://www.imagemagick.org/Usage/text/ and http://www.imagemagick.org/script/command-line-options.php#annotate

Input:

enter image description here

convert logo.jpg -font Arial -pointsize 64 -fill red -gravity center -annotate 20x20+0+0 "TESTING" logo_test.jpg

or alternately using -draw

convert logo.jpg -font Arial -pointsize 64 -fill red -gravity center -draw "rotate 20 text 0,0 'TESTING'" logo_test2.jpg

enter image description here

Sorry, I do not know GraphicsMagick, but it should have a similar operator to -annotate and perhaps the same name.

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • In GraphicsMagick's node.js port i found this function `.draw(["rotate -14 text 0,0 " + yourText])` you can give a string of arguments to it, like using the command line tool. This answer pointed me to find this function which didn't cought my eye before. Thank you. – Ali Somay Nov 22 '17 at 20:41
  • Of course your text should contain escaped or single quotes in it if you will be using a variable. ex. `var yourText = "\"sample text\""` – Ali Somay Nov 22 '17 at 20:46
0

As specified here: http://www.graphicsmagick.org/GraphicsMagick.html#details-draw you can specify additional transformation primitives to -draw option of graphicsmagick.

"Rotate" primitive is the thing that you need in this case. You need to specify this primitive before "text" options to get this work.

Example:

gm convert -font arial -fill white -gravity Center -draw "rotate 45 text 0,0 'Some text'" img1.jpg img2.jpg

Very important to place "rotate {degrees}" primitive before text statement to get this work.