Image size for font 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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image size for font size

Post by fmw42 »

Yes, probably needed to put quotes around %w.

Try:

convert logo: -format "%w" info:

It should tell you the width of the logo: image

this should be the same

echo `convert logo: -format "%w" info:`

or

echo $(convert logo: -format "%w" info:)

or

echo $(convert logo: -format "%[fx:w]" info:)

The latter is more useful.

Lets say that you want to resize an image by half and get its new size without knowing what it was to start:

convert logo: -resize 50% -write logo_half_a.gif -format "%w x %h" info:
320 x 240

But you can also do the following (in a stupid way) to make the image half size without knowing how big it is to start: (Using +clone gave errors and probably is correct as there is really no original image defined the way I was trying to use it as we are starting new convert statements).

convert logo: -resize $(convert logo: -format "%[fx:w/2]" info:)x$(convert logo: -format "%[fx:h/2]" info:) logo_half_b.gif

A more compact method of using fx escapes and string formats for arguments would be a nice future enhancement.
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Image size for font size

Post by stevepugh »

Nice! I'll have to dig into those approaches, thanks!

I was looking into the '-geometry' option, and from the docs it SOUNDS like it should be able to spoof a right-justify:
-geometry widthxheight{+-}x{+-}y

preferred size and location of the image.

If the x is negative, the offset is measured leftward from the right edge of the screen to the right edge of the image being displayed.


That sounds like if I give it a negative x value, it will measure in from the right edge - since my text labels are sized to fit the text, this ought to let me line up their right edges, yes? Unfortunately, it doesn't - it appears to move the text label offscreen, measuring from the left side of screen to the left side of the label.

So close! So CLOSE!!!

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

Re: Image size for font size

Post by fmw42 »

Sorry, I had to leave before I finished my post.

What I was doing in:

convert logo: -resize $(convert logo: -format "%[fx:w/2]" info:)x$(convert logo: -format "%[fx:h/2]" info:) logo_half_b.gif

is basically setting up variables in place for the width and height. The above is the same as:

halfwidth=$(convert logo: -format "%[fx:w/2]" info:)
halfheight=$(convert logo: -format "%[fx:h/2]" info:)
convert logo: -resize ${halfwidth}x${halfheight} logo_half_b.gif

I also tried to use mpr: in place of clone, but that did not work. The only way I can avoid restating the image file is as follows:

infile="logo:"
convert $infile -resize $(convert $infile -format "%[fx:w/2]" info:)x$(convert $infile -format "%[fx:h/2]" info:) logo_small2.gif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image size for font size

Post by fmw42 »

I was looking into the '-geometry' option, and from the docs it SOUNDS like it should be able to spoof a right-justify:
-geometry widthxheight{+-}x{+-}y

preferred size and location of the image.

If the x is negative, the offset is measured leftward from the right edge of the screen to the right edge of the image being displayed.

I don't think so. All it will do is shift the image up and to the left of the upper left corner of the background and so some pixels will be cropped off. Perhaps it is broke as the docs agree with your statement. (IM 6.4.3-5) Try the following and you will see:

convert -size 100x100 xc:white rose: -geometry -10-10 -composite tmp.png

likewise:

convert -size 100x100 xc:white rose: -geometry 70x46-10-10 -composite tmp.png


If you want right justify, then why not just use -gravity in stead of -geometry?
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Image size for font size

Post by stevepugh »

Re: -gravity -- I'm trying, believe me ;-)

The sticky wicket is that I don't want to right-justify to my final destination image, I want to right-align six bits of text down the middle of that image - let's see if I can recreate here...of course the font won't totally line up:

Date: 28-Aug-2008
Artist: Steve Pugh
VFX Shot No.: VFX001-01
Version: v02

The trouble kicks in when my user sets their project up to call shots "Scene:" instead of "VFX Shot No.:", otherwise I could hardcode all this stuff.

So, I can line up everything *after* the colons to be left-justified and gorgeous. The stuff *before* the colons wants to be right-justified, and there's my issue.

Also, I tried using -gravity and writing into a large 'container' image and positioning that container where I need it, but since my -pointsize options appear to be ignored, I get variations in font size depending on the text I'm writing. Wheeeeeeeee!!!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Image size for font size

Post by anthony »

stevepugh wrote: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.
The best idea may be to generate seperate images of each of the fields and then append them together into one image per column then append them into the final image.

In IM Examples on Append are methods of left/center/right justified forms of append (not always simple :-( ) whcih should get what you want.

Also by doing trial runs of appending the generated label images, you can determine the maximum length of the each 'column' which then allows you to alyout your images better

Alternatively generate your images, and feed it into montage, to generate a concatenated array of images, however it makes each and every 'cell' of the array the same final size. So that may not work too well.

Whatever your solution, or ideas. please feed them back to us!


---THE FUTURE---

At this time the "convert" command is short of options for multiple image appending and arrary generation, though ideas for this has been added to the IM Examples, Development, Future page.

These ideas are designed to slowly build on each other eventually allow users to generate image arrays in a highly controlled way, including the alignment of font baselines. But that is all they are at this time, ideas. Until someone gets time and inclination to work on them and develop them, that is all they will ever be.

I myself am already working on a lot of new additions to IM, in image distortions, sparse-color mapping, symbol drawing, image registration and spatial morphing animations. I doubt I will get to this myself any time soon.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Image size for font size

Post by anthony »

stevepugh wrote: Date: 28-Aug-2008
Artist: Steve Pugh
VFX Shot No.: VFX001-01
Version: v02
Assuming you will fill in data as appropriate, and font height is the same size (force it using -size if needed)

Code: Select all

convert label:'Date:' label:'Artist:' \
               label:'VFX Shot No.:' label:'Version:' \
               -append   column1.png
convert label:'28-Aug-2008' label:'Steve Pugh' \
               label:'VFX001-01' label:'v02' \
               -append   column2.png
convert column1.png column2.png +append result.png
For right justification change -append to -flop -append -flop

PS: you may like to add some extra spacing after each label string due to an existing BUG involving labels cutting off the last 'pixel' column.

Of course with parenthesis you can do this in one convert command (see the append link I gave in previous email).

However by pre-generating individual and temporary 'cell' and 'column' images you can read the width and height information als allow you to adjust things by using -extent with -gravity and then just directly -append the images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Image size for font size

Post by stevepugh »

I'm still fine-tuning, Anthony, but it appears that your recommendation of using -append and +append is going to be the bee's knees! I will definitely post the final results, but this is definitely giving me the look I was hoping for. Now to experiment with sticking a "-caption"'ed label at the end so that my "Notes:" field can be word-wrapped automatically....whoohoo!!

Many thanks,
Steve
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Image size for font size

Post by stevepugh »

Success! Thank you everyone, I've learned a LOT about Imagemagick over the course of this particular project, to say the least :-)

For the curious, here's my final command-line to generate a slate image with an offset thumbnail, centered slate info header/data, and a word-wrapped "Notes" entry. Your mileage may vary (this is set up for a 1920*1080 image, I'm still plugging in the bits that scale and reposition based on the supplied "thumbnail" image resolution) :

Code: Select all

convert.exe GenericSlate_R01.tga -depth 8 -fill White -background transparent -font Arial -pointsize 40 ( ( label:"Show : " label:"Episode : " label:"Scene : " label:"Artist(s) : " label:"Frames : " label:"Date : " label:"Notes : " -flop -append -flop )  ( label:"Some Cool Movie " label:" " label:"vfx03-01 " label:"Steve Pugh " label:"48 " label:"8/29/2008 " ( -size 700x260 -background transparent -fill White -font Arial -pointsize 40 -gravity northwest caption:"This version features an automatically generated slate.  Yay." ) -append ) +append ) -geometry +768+450 -compose over -composite  ( -resize 450 -bordercolor white -border 3 SomeSpecifiedThumbnail.tga ) -geometry +150+500 -compose over -composite  MyDesiredSlateOutputFrame.tga
Thanks again for your help, I hope someday to give a little back to the community but I doubt I know enough yet to be much more than a pretty face ;-)

Best,
Steve
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Image size for font size

Post by anthony »

can you include an image of your solution. Your command is using extra images people do not have.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Image size for font size

Post by stevepugh »

Sure thing, Anthony - I had renamed the 'real' images with generic placeholders since I knew people wouldn't have access to my source files. What's the procedure for posting image files to the server? They're currently HD resolution, so it's a bit bulky for throwing around the forums.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Image size for font size

Post by anthony »

Just a smaller 'test' image. nothing large!
Demonstration of what you achieved, and the command does.

IM examples for instance very very rarely uses a large image to demonstrate any technique.

You can post a link from some image/photo/personal server, it can be web or ftp.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Image size for font size

Post by stevepugh »

Here's an example of the output from that command:
http://picasaweb.google.com/swpugh0902/ ... 0186580626

Also in that album are my sample thumbnail and starting (empty) slate image. I'm happy with the output, I've got a little work to do to handle various sourcefile resolutions and aspect ratios, but this meets my needs quite nicely.

I had toyed with using the "-polaroid" option for the thumbnail, but it was a bit gimmicky. Plain ol' thumbnail works well enough.

Steve
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Image size for font size

Post by anthony »

Thanks. It is a very pretty result.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Image size for font size

Post by stevepugh »

Resurrecting my own post? How shameless.

I just found out this morning that the code I pasted a few posts back works dandy when the 'thumbnail' image is Linear colorspace (Targa, PNG, Linear DPX have all been tested), but when the thumbnail image is a Logarithmic DPX file then it appears to ignore the coordinates passed in '-geometry +768+450 -compose over -composite' - the thumbnail drops down to the bottom of the frame.

Does anyone have any idea why this might be happening with Log files?

Many thanks,
Steve
Post Reply