Add text on canvas of certain size

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
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

Add text on canvas of certain size

Post by Marcel71 »

Hi,

What i am trying to do:

1) I have a text with pointsize 30 and then i resize it. For example:

Code: Select all

convert -font Arial -pointsize 30 label:"Imagemagick" -resize 140% out.png
The resulting image is 280x50. And of-course, the text is a bit blurry.

Now i would like to have the same text with that size, but then sharp.

Code: Select all

convert -font Arial -gravity center -size 280x label:"Imagemagick" out2.png
There is a slight difference in font size, however that is not my main concern.
How do i merge above two commands in 1 convert?

I hoped something like:

Code: Select all

convert -respect-parentheses ( -font arial -pointsize 30 label:"Imagemagick" -resize 140% ) ( -size %wx -font arial -gravity center label:"Imagemagick" ) -delete 0 out.png
But it does not give me the same canvas size...

Any suggestions?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Add text on canvas of certain size

Post by snibgo »

What are you trying to do?

If you want a label that has pointsize 30 * 140% = 42, the obvious way is ...

Code: Select all

convert -font Arial -pointsize 42 label:"Imagemagick" out.png
... but I don't suppose this is what you want.

(Incidentally, I don't think you can use %w in "-size".)
snibgo's IM pages: im.snibgo.com
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

Re: Add text on canvas of certain size

Post by Marcel71 »

Well, i would like for users to dynamically resize the text within my website.

So the "original" text is -pointsize 30.

Then with a 'slider' and jQuery i would like that users can resize the text bigger or smaller.
When moving the slider, the text (image) will get bigger or smaller immediatly in the preview.

However, after the text is resized with the slider, the text looks blurry in the browser. (logical, as the image has dynamically resized inside the browser)
So i want to fetch a new text after the user resized the text (image) on the website. So it looks sharp again.

You theory does not work.
As -pointsize 60 will not have doubled in size in comparison with -pointsize 30.

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

Re: Add text on canvas of certain size

Post by fmw42 »

Withdrawn. GreenKoopa's code below explains it better.
Last edited by fmw42 on 2013-06-21T10:50:27-07:00, edited 1 time in total.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Add text on canvas of certain size

Post by GreenKoopa »

Code: Select all

convert -respect-parentheses ^
( -font arial -pointsize 30 label:Imagemagick -resize 140%% ) ^
-set option:size "%%wx" +delete ^
( -font arial -gravity center label:Imagemagick ) ^
out.png
Windows script.
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

Re: Add text on canvas of certain size

Post by Marcel71 »

Thanks, i think indeed that GreenKoppa's code is the closest i can get with this issue :)
The out.png text is a bit smaller than the resized text. But i can live with that.

Thanks all...
Post Reply