Page 1 of 1

How to draw auto fitted text on image

Posted: 2012-12-03T05:25:42-07:00
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?

Re: How to draw auto fitted text on image

Posted: 2012-12-03T08:00:25-07:00
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".