Imagemagick fonts not found in OSX - macos

When trying to add annotations to images in ImageMagick, It failed with the following message:
convert: unable to read font `(null)' # error/annotate.c/RenderFreetype...
How do I make Imagemagick find these fonts?

The solution that worked for me was given by Neville in this post:
Create an imagemagick configuration folder: mkdir ~/.magick
Save this Perl script as /tmp/script.pl
Make the script executable: chmod +x /tmp/script.pl
Run the script locally and redirect the output to the file type.xml in ~/.magick: /tmp/script.pl > ~/.magick/type.xml
This solved the fonts problem, while installing fondu, the imagemagick pkg file and some other tricks didn't.
Great! Now I can annotate some flickr cats with the image size and resolution (I want this for finding the optimal resolution for an app I'm working on).

Adopting Adam Matan's answer, here's how I got this to work with imagemagick 7+ on macOS 10.12+ installed with homebrew. (This also assumes you have perl installed.)
Download the perl script and save it to /usr/local/bin/imagick_type_gen
Make the script executable:
chmod +x /usr/local/bin/imagick_type_gen
Find the font path for imagemagick by running convert -list font | grep Path. This should return where imagemagick is looking for fonts. The Apple path for me was this:
/usr/local/Cellar/imagemagick/7.0.7-22/etc/ImageMagick-7/type-apple.xml
Run imagick_type_gen and direct the output to the path above:
imagick_type_gen > /usr/local/Cellar/imagemagick/7.0.7-22/etc/ImageMagick-7/type-apple.xml
Run convert -list font | less to see the font names imagemagick will use, e.g., some fonts will be labeled as GeorgiaB instead of Georgia Bold. (hit q to quit)
imagemagick should now see the fonts you have installed on the your system.

The easiest way to solve this issue is copying the font you need to a ~/ folder, or anywhere your script is, then give the direct path:
convert -font "~/MyFont.ttc"

Related

So I have a folder which contains around 300 png files and I want to convert all of them to jpg files

i have a access to a Ubuntu server and a macOS installation
I’ve searched only but haven’t found anything
install imagemagick and rename
sudo apt install imagemagick rename
go in the folder to be safe
cd /dir/with/pngs
convert them all in a for/do/done loop
for png in $(ls -1 *.png); do
convert "$png" "${png/png/jpg}"
done
You win one million fire emojiis.

A terminal command (Mac) to change the extension of all the files in a folder

I'll try to make this as short as possible.
I have a folder that contains 9000 images (almost). But the extension of these images is png. I would like to change the extension of all these images in one command so they all become .jpg
If someone knows a way to do that can you please share it?
Thank you for your help.
If they are PNG images that you are trying to turn into jpgs, I'd recommend installing Imagemagick (via homebrew), and using the "mogrify" command to change them (see https://www.imagemagick.org/script/mogrify.php):
magick mogrify -format jpg *.png
If they are all actually jpegs, and you've ended up with the wrong file extension, you can do something like:
ls | grep \.png$ | sed 'p;s/\.png/\.jpg/' | xargs -n2 mv
See: Batch renaming files in command line and Xargs (even though it's linux, these tools are all available in the OSX default install)
I did it by using a virtual machine (Windows)
In the cmd I used this command : ren *.* *.jpg and it worked. Although I guess on Mac it's a bit harder.

Install .ttf font using command line

On OS X you can install .ttf font files by double clicking them. This is a hassle when dealing with multiple files. Is there a command to install font files using the Terminal app ?
You could copy the fonts using
cp myfont.ttf /Library/Fonts/
or multiple files
cp fontsFolder/*.ttf /Library/Fonts/
Install fonts with the following command line. Replace BRLNSR with your font and add in more lines if you need more fonts.
cd ~/Library/Fonts && { curl -O 'https://github.com/bloomberg/scatteract/raw/master/fonts/BRLNSR.TTF' ; cd -; }
This code does the following:
cd into the fonts directory
curl downloads the font
pops back to the original directory
This relies on the very nice bloomberg fonts github repo with a bunch of fonts stored - but you could change the curl url to wherever the font you want is located online.
The clever way the cd into a directory, download and pop out again came from user Atle's answer here.
To make the newly copied fonts available to applications requires activating them (for the process, for the user, or for the whole system). This you can do programmatically through various CoreText commands, depending on what you want to do with the font(s). I’m not sure if there’s a way to do this from the command line without turning on auto-activation for everything. See atsutil man pages for (scant) details.

Via command line: convert (.tif and .pdf) to .jpg or .png

anyone know a free, stable commandline tool (besides ImageMagick) to convert .tif files and .pdf files to either .jpg or .png?
thanks Michelle
I prefer Imagemagick for Windows stuff, but IrfanView performs well, too. It looks like it has switches for command-line conversion of image formats, as well. See the "/convert" option.
tiff2png
On mac os x:
$ brew install tiff2png
$ tiff2png -compression 9 *.tif

Extract Images from an Excel Document

I am doing some data mapping from an .xls excel document, and I am trying to write a quick script to pull images out excel document.
What is the quickest, simplest way to do this programatically?
I am running Ubuntu 10.10 and I would prefer to user python if possible.
a XLSX file is a compressed file.
$ unzip file.xlsx
in xl/media/ are all pictures. This is not true for older .XLS files, but you can convert them to XLSX with a modern version of MS Office.
If you don't have MS Office, you can do the same thing with LibreOffice. Convert the file to .ods and then open it as a zip file and it will be in the Pictures folder.
I hate to answer my own question, but the best method I found only required two commands at the command line (assuming you have the right software installed).
First, use unoconv to convert the .xls to .pdf:
http://dag.wieers.com/home-made/unoconv/
On Ubuntu 10.10 command line:
sudo apt-get install unoconv
unoconv -f pdf file.xls
Then extract the images from the pdf using pdfimages (which seems to come bundled with Ubuntu):
http://en.wikipedia.org/wiki/Pdfimages
Back on the command line:
pdfimages file.pdf fileimage
And done! All of the images in the .xls are now in separate files in the directory. This could be done very easily on most Linux systems using your language of choice. In python, for example:
import subprocess
subprocess.call(['unoconv','-f','pdf','file.xls'])
subprocess.call(['pdfimages','file.pdf','fileimage'])
I would love to hear a simpler solution if somebody has one.

Resources