How to draw auto fitted text on image

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
tapas.23571113
Posts: 1
Joined: 2012-12-03T04:40:57-07:00
Authentication code: 6789

How to draw auto fitted text on image

Post by tapas.23571113 »

Hello. I want to make watermark by text, in such a way that it will fill the image diagonally and dynamically. I have used

Code: Select all

convert -density 72x72 -colorspace RGB -weight bold -pointsize 20 -draw "gravity center fill '#BEBEBE' rotate 315 text 0,0 'Some Text" inputFile.jpg outputFile.jpg
And it is creating the watermark diagonally, but not auto fitting the image. Is it possible to do this?

Increasing pointsize will cover the image, but how can I determine the pointsize dynamically?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to draw auto fitted text on image

Post by snibgo »

For some versions of IM, "label:" can do automatic pointsizing. Otherwise, a two-step solution can be used. Windows script:

Code: Select all

FOR /F "tokens=1,2" %%i IN ('%IM%identify -format "%%[fx:min(w,h)*0.17]" %INFILE%') DO (
  set POINT=%%i
)

"%IMG%convert" ^
  %INFILE% ^
  -density 72 -colorspace RGB -weight bold ^
  -pointsize %POINT% ^
  -draw "gravity center fill '#FF0000' rotate 315 text 0,0 'Some Text'" ^
  outputFile.jpg
The "0.17" is a fiddle factor that works with "Some Text". It should be adjusted if the text is longer or shorter.

EDIT: I meant "label:", not "-label".
snibgo's IM pages: im.snibgo.com
Post Reply