MMsizr a Script/App to resize images to 2 million pixels

When crea­ting ePub-files I often got an error messa­ge from apple: Image exceeds 2 mil­li­on pixels.

I did not find any ready to use solu­ti­ons to this pro­blem.

A fri­end of mine an I crea­ted this shell script for osx to do this auto­ma­gi­cal­ly. It uses the pre­instal­led com­mandli­ne tools »bc« and »sips«.

I used Pla­ty­pus to make a (very basic) GUI-App for this script. Just drag your image fol­der on the apps main win­dow and every JPG, GIF an PNG will be resi­zed if necessa­ry.

MMSizr_Icon

Down­load app here:
MMsizr App

Feel free to sug­gest any impro­ve­ments.

#!/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

Sca­ling is com­pu­ted the fol­lo­wing way:
$latex scaling=\sqrt{\frac{1900000}{NumberOfPixels}}$