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 problem.

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 necessary.

MMSizr_Icon

Down­load app here:
MMsizr App

Feel free to sug­gest 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

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

 

4 Gedanken zu „MMsizr a Script/App to resize images to 2 million pixels“

  1. Hel­lo, I noti­ced that when I drop a fol­der onto this app, if the­re are any spaces in the fol­der name or fol­der path, it doesn’t work. Is this fix­able? Thanks so much!

    1. Hi Made­li­ne!
      I can’t offer you a solu­ti­on right now, just a work­a­round. If you drag the images fol­der onto your desk­top, then on mmsi­zer it should work. This is how I do it.
      After­wards drag it back into the epub folder.

  2. First of all: thank you for this very han­dy utility!!

    My ques­ti­on is: could/would you be wil­ling to make a new ver­si­on whe­re the maxi­mum num­ber of pixels beco­mes 4.000.000 ins­te­ad of 2.000.000? Becau­se this has beco­me the new stan­dard for Apple after intro­du­cing the Reti­na dis­plays! Thanks in advance!
    Boe­le (the Netherlands)

    1. Hi Boe­le!

      No Pro­blem at all. I’ll get to it shortly.
      In my sear­ches I found a limit of 3.200.000 Mil­li­on pixels. Up from 2.000.000. Do you have a link?

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.