When creating ePub files I often got an error message from apple: Image exceeds 2 million pixels.
I did not find any ready to use solutions to this problem.
A friend of mine and I created this shell script for OSX to do this automagically. It uses the preinstalled command line tools »bc« and »sips«.
I used Platypus to make a (very basic) GUI-App for this script. Just drag your image folder on the apps main window and every JPG, GIF an PNG will be resized if necessary.
Download app here:
MMsizr App
Feel free to suggest any improvements.
#!/bin/sh MAXsize=1900000; for v in `find $1/*.jpeg $1/*.jpg $1/*.gif $1/*.png`; do h=`sips -g pixelHeight $v | tail -1 | sed "s/.* //"` w=`sips -g pixelWidth $v | tail -1 | sed "s/.* //"` anzahl=`echo "$h*$w" | bc`; echo "Anzahl Pixel in $v ($w x $h) ist $anzahl"; if [[ $anzahl -gt $MAXsize ]]; then factor=`echo "scale=5 ; sqrt($MAXsize / $anzahl) " | bc`; echo "Faktor: $factor"; newWidth=`echo "scale=5 ; $w * $factor" | bc`; newHeight=`echo "scale=5 ; $h * $factor" | bc`; echo "$v Neu: $newWidth x $newHeight"; sips -z $newHeight $newWidth $v echo " "; fi done
Scaling is computed the following way:
$latex scaling=\sqrt{\frac{1900000}{NumberOfPixels}}$
Hello, I noticed that when I drop a folder onto this app, if there are any spaces in the folder name or folder path, it doesn’t work. Is this fixable? Thanks so much!
Hi Madeline!
I can’t offer you a solution right now, just a workaround. If you drag the images folder onto your desktop, then on mmsizer it should work. This is how I do it.
Afterwards drag it back into the epub folder.
First of all: thank you for this very handy utility!!
My question is: could/would you be willing to make a new version where the maximum number of pixels becomes 4.000.000 instead of 2.000.000? Because this has become the new standard for Apple after introducing the Retina displays! Thanks in advance!
Boele (the Netherlands)
Hi Boele!
No Problem at all. I’ll get to it shortly.
In my searches I found a limit of 3.200.000 Million pixels. Up from 2.000.000. Do you have a link?