can not make font size adjust itself

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?".
dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

can not make font size adjust itself

Post by dav22 »

I have problem to make my code works that the text fill the area with proper font size,
if I want to make an image out of only text the font size is automatically adjusted when size of image is provided,

but here I want to extend an image to have some extra space to have text on it, in this case the font size does not adjust itself,
images are varied in sizes so i make them all with width of 227 pixel, and extend the whole image lengthwise to 504 pixel, here is my code, so the output image is: 227*504, but it seems that IM does not recognize it as image size for whatever reason.

Code: Select all

magick  image1.jpg  -resize 227 -gravity  south -background lightblue -extent 0x504 -fill black  -font C:/Windows/Fonts/FontsHeebo-ExtraBold.TTF ^
-gravity northwest  -annotate 0x0+0+25  @text.txt   image-resized1.jpg
thanks for help;

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: can not make font size adjust itself

Post by snibgo »

"-annotate" won't automatically set the pointsize.

"label:" and "caption:", which create new images, can automatically set the pointsize.

So you can create a new image with whatever "-size" you want, using "label:" or "caption:", and composite that over your input image.
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

Re: can not make font size adjust itself

Post by dav22 »

thanks for the reply;
I have already tested with caption: and label: as well as reading from file,
so it does not work the way I put it in above code in one go, I have to make the image first from my text, then write another code to put together the text image and actual image,
thanks

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: can not make font size adjust itself

Post by snibgo »

For example:

Code: Select all

magick in.pdf {...} -set option:MYSIZE %wx%h ( -size %[MYSIZE] label:"Hello" ) -composite out.png
.. where {...} is any operations you want.
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

Re: can not make font size adjust itself

Post by dav22 »

thank you for your respond;
I can not make it work,
here is how I put my example code into your code:

Code: Select all

magick image1.jpg { -resize 227 -gravity  south -background lightblue -extent 0x504 -fill black -gravity northwest  -annotate 0x0+0+25} -set option:MYSIZE %wx%h ( -size %[MYSIZE] label:"This is sample text" ) -composite out.jpg
thanks

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: can not make font size adjust itself

Post by snibgo »

Remove the curly brackets {}.

Remove "-annotate 0x0+0+25".
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

Re: can not make font size adjust itself

Post by dav22 »

thank you for your respond,
an output image is created,
1- the output image is the right size, but no image has been added, it suppose to add my image to it.
2- the text show up very small, and it does not wrap , long text is cut off.

Code: Select all

magick image1.jpg -resize 227 -gravity  south -background lightblue -extent 0x504 -fill black -gravity northwest  -set option:MYSIZE %wx%h ( -size %[MYSIZE] label:"This is sample text This is sample text This is sample text This is sample text This is sample text This is sample text This is sample text" ) -composite out.jpg
thanks.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: can not make font size adjust itself

Post by fmw42 »

-extent 0x504
Why is the width of your -extent zero?

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: can not make font size adjust itself

Post by snibgo »

1. You have "-background lightblue". I suggest you insert "-background none" before "label:" or "caption:".

2. If you want word-wrapping, I suggest you use "caption:".
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

Re: can not make font size adjust itself

Post by dav22 »

Thank you for respond;
I had this with my older image creation, I copied somewhere from this forum I assume, and that was set to zero, I did not noticed anything wrong with it, so I copied it with new coding, this time I want to use longer text so trying to use this method, because I don't want to use font size, because it takes time to adjust font size, for every setting I have.
so I just copy my working code and tried it,
anyhow I put the value 727x504, and did not make any changes, same result.

thanks

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: can not make font size adjust itself

Post by snibgo »

If it doesn't do what you want, please tell us what you do want.

Also please tell us what version of IM you use, on what platform.
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

Re: can not make font size adjust itself

Post by dav22 »

Thank you for your respond;

I use ImageMagick-7.0.9-Q16 on Windows 7 64bit
I want to resize and extend an image lengthwise and put some text on the extended area.
I have already made the exact code which works fine, but it is for short text, I use font size for the output I want, and it works fine.
but now, I want to have longer text instead, so when I remove the font size, it suppose to adjust the font size and do the text wrapping, but it does not work that way, and it shows one line of text and cut the rest of it.
I have used caption: and Label: but the caption and label will be printed as well,

Here is the code that works fine with short text:

Code: Select all

magick  image1.jpg  -resize 227 -gravity  south -background black -extent 0x404  -fill yellow -pointsize  22X -gravity  north -annotate 0x0+0+60  "some short text here, some short text here, "  image1-output.jpg
thanks

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: can not make font size adjust itself

Post by snibgo »

Code: Select all

magick toes.png  -resize 227 -gravity south -background lightblue -extent 0x504 -fill black -gravity northwest -set option:MYSIZE %wx%h ( -size %[MYSIZE] -background None caption:"This is sample text dsads   gfd gfd gf fd ggf gf gf gf gf g" ) -composite caption_over.jpg
Image
snibgo's IM pages: im.snibgo.com

dav22
Posts: 29
Joined: 2020-02-05T09:22:25-07:00
Authentication code: 1152

Re: can not make font size adjust itself

Post by dav22 »

thank your for respond and your code, now it is working,

I have a longer text than example and text goes over image.
is there a way to prevent text not go over image,
in a way to limit the text, to fill in certain length.
thanks

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: can not make font size adjust itself

Post by snibgo »

dav22 wrote:is there a way to prevent text not go over image,
What do you want to happen instead? Perhaps the text becomes clipped. Or perhaps the extended area grows to contain all the text. Or perhaps the font size decreases.
snibgo's IM pages: im.snibgo.com

Locked