How to save to multiple copy but changing font each time?

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
Ethernety
Posts: 2
Joined: 2015-12-16T14:20:14-07:00
Authentication code: 1151

How to save to multiple copy but changing font each time?

Post by Ethernety »

Hi!

I am new to this. I have searched exemples of scrips to understand it all, but i need to figure out 2 things.

The idea is to make multiple copy of the same (white) word, centered on a black background.
But i would like to use all the fonts in my font folder in windows.
A different font for each image every time till i used all fonts available.
The i need to save the files with different names so the don't overwrite each other.
(To include the font name in the saved file would be awsome but not mandatory)

So, i'm only looking for the code to say *all fonts available*. Like a wildcard when you make a search (*.*) ; Instead of writing the font name itself.

Thanks for the help!
Peace to all!
Ethernety
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to save to multiple copy but changing font each time?

Post by fmw42 »

So, i'm only looking for the code to say *all fonts available*. Like a wildcard when you make a search (*.*) ; Instead of writing the font name itself.
As far as I know, Imagemagick has no way to do that natively. You can write a script to loop over the type.xml file (or your font directory) to find all the font names or font files and then write a loop over your text image processing to substitute each font.
Ethernety
Posts: 2
Joined: 2015-12-16T14:20:14-07:00
Authentication code: 1151

Re: How to save to multiple copy but changing font each time?

Post by Ethernety »

Thanks a lot for the fast reply!!

I'll try that!! My nose is bleeding already!

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

Re: How to save to multiple copy but changing font each time?

Post by fmw42 »

(To include the font name in the saved file would be awsome but not mandatory)
Where do you want to save it? As part of the image underneath or in the meta data, which can be saved as a comment or label. You can also write the output filename as the font name.

See
http://www.imagemagick.org/Usage/annotating/#anno_below
http://www.imagemagick.org/Usage/basics/#attributes
http://www.imagemagick.org/Usage/basics/#set
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to save to multiple copy but changing font each time?

Post by Bonzo »

I have some php code if you can use a localhost on this page - it is quite old but should still work. If you can not use the php you might be able to modify it into a batch script or similar.

I believe Anthony has a version on his website somewhere which will not be php: http://www.imagemagick.org/Usage
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to save to multiple copy but changing font each time?

Post by fmw42 »

Anthony has a show_fonts script at http://www.imagemagick.org/Usage/scripts/show_fonts, but it is a Unix shell script and so won't work on Windows without Cygwin.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: How to save to multiple copy but changing font each time?

Post by GeeMack »

ImageMagick will list all the fonts it sees currently installed on your Windows system with this command...

Code: Select all

convert -list font
A very small batch file run from a Windows cmd.exe prompt can parse that list, use just the font names, and make a set of small JPG files, each with your word in white on black. The images are saved with a file name that is the same as the font name. I made a batch file named fontjpgs.bat in a temp directory on my Windows 7 64, then I ran it to create the images in that directory. This is what the batch program looks like...

Code: Select all

@echo off

setlocal

set WORD=Your word here.

for /F "tokens=1,2 delims=: " %%I in ( 'convert -list font' ) do (
   if %%I == Font (
      convert ^
      -background black ^
      -bordercolor black ^
      -fill white ^
      -gravity center ^
      -font "%%J" ^
      -pointsize 36 ^
      label:"%WORD%" ^
      -border 36x36 ^
      -quality 100 ^
      "%%J.jpg"
   )
)
It will miss any fonts that ImageMagick can't see or use. A couple of my fonts made images with little squares instead of the font characters. I also don't know how it might handle any font names that might have characters that aren't legal for making file names. Maybe something like this will get you started.
Last edited by GeeMack on 2015-12-17T21:41:12-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to save to multiple copy but changing font each time?

Post by fmw42 »

You can edit the type.xml file to add any allowed fonts to the file so that the above command will list those fonts as well.
Post Reply