Image size for font size
Image size for font size
I hove some text, a font and size of the font. Now i need to put this text on the white rectangle (or simply square), but it's important that this rectangle is filled out by the text with no white spaces on sides. For that i need to calculate the widht and height of the image depending on the font and font size.
Can imagemagick do it automatically (on command line)????
Can imagemagick do it automatically (on command line)????
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Image size for font size
label: by default (no -size setting) sizes the image to fit the text, font and pointsize.
If you leave out the -pointsize but set -size instead, IM resizes the text to best fit that size.
It is all explained in the link fmw42 gave.
If you leave out the -pointsize but set -size instead, IM resizes the text to best fit that size.
It is all explained in the link fmw42 gave.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Image size for font size
Thank you guys!!!anthony wrote:label: by default (no -size setting) sizes the image to fit the text, font and pointsize.
But another one question: OK the image will be resized to fit the text, but can i influence the ratio of sides? For example, i would like an image with 4:3 ratio (or just square) and that fits to the text - is it possible?? I ask just, because it's maybe possible, that an image for one sentence will be generated as a long line (width: 1000px, heigt: pointsize) - is it possible?? Or i don't have to think about that and imagemagick generates just squares per default???
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Image size for font size
I don't know any way to get the aspect ratio as desired, except to use -resize afterwards, but that would distort the text.
Note that caption will draw text to multiple line.
Note that caption will draw text to multiple line.
Re: Image size for font size
Great!
Everything works!!!!
Last one question: Can i influence the line heigth (margin between lines) and char-spacing??
Everything works!!!!
Last one question: Can i influence the line heigth (margin between lines) and char-spacing??
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Image size for font size
Not that I am aware (other than by choice of font) in MVG, but see the specs at http://www.imagemagick.org/script/magic ... aphics.php
also see if SVG is more forgiving at http://www.w3.org/TR/SVG/index.html
read Anthony's examples at http://www.imagemagick.org/Usage/draw/
also see if SVG is more forgiving at http://www.w3.org/TR/SVG/index.html
read Anthony's examples at http://www.imagemagick.org/Usage/draw/
Re: Image size for font size
Or PostScript - it could be used, too...I suppose
But, i think, i will choose MVG or SVG
Thanks!
But, i think, i will choose MVG or SVG
Thanks!
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Image size for font size
Not simply.vadimiron wrote:i would like an image with 4:3 ratio (or just square) and that fits to the text - is it possible??
The best way is to set a large image -size that is 4:3 ratio, use caption: to word wrap the given text into an image of that size (without a -pointsize setting. Then resize it to the size needed.
If you know the final size in advanced, you could just generate it directly.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Image size for font size
Hi all,
This looked like a good post to hijack as I have a related question (and the original poster might benefit from my angst
I am using label: to generate six or seven blocks of text for a slate generator, and the variables being populated look great - the date, artist, scene, etc. are all left-justified and evenly spaced, which is cool.
The actual 'descriptors', though ("Date:", "Artist:", "Shot No.:", etc.) are variable length and they want to be right-justified so that the slates look as pretty as possible. Of *course* I want my users to be able to make slates that read "Shot:" or "Scene Name:" depending on preference, so now I have to figure out how to make it look nice with a variety of text widths.
Presently these captions are written with image stacks thusly:
So far so good.
My question, how can I capture the width of the resulting image, so that I can offset the -geometry +200 so that they all line up along their rightmost edges? If I can get that width on the same commandline, I'll be grinning like...well, like a grinning thing.
Many thanks,
Steve
This looked like a good post to hijack as I have a related question (and the original poster might benefit from my angst
I am using label: to generate six or seven blocks of text for a slate generator, and the variables being populated look great - the date, artist, scene, etc. are all left-justified and evenly spaced, which is cool.
The actual 'descriptors', though ("Date:", "Artist:", "Shot No.:", etc.) are variable length and they want to be right-justified so that the slates look as pretty as possible. Of *course* I want my users to be able to make slates that read "Shot:" or "Scene Name:" depending on preference, so now I have to figure out how to make it look nice with a variety of text widths.
Presently these captions are written with image stacks thusly:
Code: Select all
( -background transparent -fill White -stroke grey -font Arial -pointsize 40 -size x70 -gravity east label:Date: ) -geometry +200+500 -compose over -composite ( -background transparent -fill White -stroke grey -font Arial -pointsize 40 -size x70 -gravity east label:Artist Name: ) -geometry +200+600 -compose over -composite
My question, how can I capture the width of the resulting image, so that I can offset the -geometry +200 so that they all line up along their rightmost edges? If I can get that width on the same commandline, I'll be grinning like...well, like a grinning thing.
Many thanks,
Steve
Re: Image size for font size
Steve, I've been working w/ IM for a long time and have not found any good ways to get font metrics... at least with the command line.
I believe there is a way in the magic++, but, I don't use that.
There are so many uses I could have if there was an easy way to get the size and spacing of the fonts.
I believe there is a way in the magic++, but, I don't use that.
There are so many uses I could have if there was an easy way to get the size and spacing of the fonts.
Re: Image size for font size
Right on, I poked around the docs enough to figure that actual font metrics were outside the realm of the feasible.
However, I'm still hopeful that I can deduce the width of the "stack" image generated by ( -size x70 -gravity east label:"Artist Name: " ) and calculate based on that.
I was initially thinking I could draw the label with a fixed pointsize in a box wide enough to cover any text, and then use that width to calculate my offset (make an 800-pixel wide label with right-justified text and composite it at a -200 x offset so that all of the right edges line up at 600 pixels), but the -compose operation apparently doesn't respect the -pointsize parameter, so there goes that.
Ever onward, ever upward!
Steve
However, I'm still hopeful that I can deduce the width of the "stack" image generated by ( -size x70 -gravity east label:"Artist Name: " ) and calculate based on that.
I was initially thinking I could draw the label with a fixed pointsize in a box wide enough to cover any text, and then use that width to calculate my offset (make an 800-pixel wide label with right-justified text and composite it at a -200 x offset so that all of the right edges line up at 600 pixels), but the -compose operation apparently doesn't respect the -pointsize parameter, so there goes that.
Ever onward, ever upward!
Steve
Re: Image size for font size
ImageMagick reports the font metrics when you use the -debug annotate option. The patch will be available sometime tomorrow from the ImageMagick subversion trunk.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Image size for font size
It is kind of long, but have you tried
... -geometry $(+clone -format %w info:)x$(+clone -format %h info:)+200+500 ...
I have not tested it.
But if possible for IM to allow more use of fx escapes and string formats as arguments (perhaps in a simpler way) that would be great. If it is already available, I would appreciate further information.
I look forward to the -font-metric in any case.
... -geometry $(+clone -format %w info:)x$(+clone -format %h info:)+200+500 ...
I have not tested it.
But if possible for IM to allow more use of fx escapes and string formats as arguments (perhaps in a simpler way) that would be great. If it is already available, I would appreciate further information.
I look forward to the -font-metric in any case.
Re: Image size for font size
I'm intrigued by and looking forward to the font metrics availability - would that allow me to get the width in pixels of my text strings for nefarious purposes like this? Yay!
fmw42, I dropped your code right into my commandline and am trying to get it to work (I suspect I need to escape the '%' characters on my Windows machine), but I'll keep on it. Can you tell me more about what that line *ought* to do? I can see where -format %w info: might give me the width of the text image, but I'm not sure what it's doing otherwise
Many thanks again,
Steve
fmw42, I dropped your code right into my commandline and am trying to get it to work (I suspect I need to escape the '%' characters on my Windows machine), but I'll keep on it. Can you tell me more about what that line *ought* to do? I can see where -format %w info: might give me the width of the text image, but I'm not sure what it's doing otherwise
Many thanks again,
Steve