Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 08-13-2012, 06:42 PM   #1
shorshe
Enthusiast
shorshe began at the beginning.
 
shorshe's Avatar
 
Posts: 28
Karma: 10
Join Date: Aug 2012
Location: Munich, Germany
Device: iPad
Post Script to resize images to 2 Million Pixels

Hi all!

A friend an I cobbled together a very rough script for OSX to resize large images down to 2 Million Pixels to conform with iBookstore Asset Guide 4.7 Rev.3:
  • The maximum recommended size is 2 million pixels per image. Larger images may not appear as expected in the iBooks app.

I also used platypus to convert it to an OSX-App.

Download App here:

http://mmsizr.googlecode.com/files/MMSizr.app.zip


Usage:
  • Unzip epub.
  • Start App and drop your images Folder on main window.
  • App searches for jpg, png, gif images an resizes to 2 Million pixels if necessary.
Image names must not contain whitespaces.

Original shell-Script:
Code:
#!/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/.* //"`
    pxlnmbr=`echo "$h*$w" | bc`;
    echo "Number of Pixels in $v ($w x $h) is $pxlnmbr";
    if [[ $anzahl -gt $MAXsize ]]; then
    factor=`echo "scale=5 ; sqrt($MAXsize / $pxlnmbr) " | bc`;
    echo "factor: $factor";
    newWidth=`echo "scale=5 ; $w * $factor" | bc`;
    newHeight=`echo "scale=5 ; $h * $factor" | bc`;
    echo "$v new: $newWidth x $newHeight";
    sips -z $newHeight $newWidth $v
    echo " ";
    fi
done
yes it's rough. Please feel free to improve:
http://mmsizr.googlecode.com/files/mmsizr.sh.zip

Project page:
https://code.google.com/p/mmsizr/

--edit--

Download App here:

http://mmsizr.googlecode.com/files/MMSizr.app.zip

Consider Flattering this article, if you liked this app:
http://suntoucher.de/mmsizr-a-script...illion-pixels/

Last edited by shorshe; 09-05-2012 at 06:53 AM.
shorshe is offline   Reply With Quote
Old 08-15-2012, 12:41 PM   #2
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
imagemagick provides the Pixel Area Count Limit ('@' flag), that is useful in combination with the -resize command:

http://www.imagemagick.org/Usage/resize/#pixel

and it automatically takes care of the scaling issues (for your intended use, combine it with the '>' flag).
AlPe is offline   Reply With Quote
Old 08-15-2012, 02:34 PM   #3
shorshe
Enthusiast
shorshe began at the beginning.
 
shorshe's Avatar
 
Posts: 28
Karma: 10
Join Date: Aug 2012
Location: Munich, Germany
Device: iPad
Post

Yeah imagemagick would be great for this. But unfortunately it's not easy to install or bundle in an app. I needed a "ready to use out of the box" solution.


I tried to do a static build of imagemagick's "convert" for osx. No luck so far.

Do you have any experience in this field?
shorshe is offline   Reply With Quote
Old 08-15-2012, 02:53 PM   #4
frostschutz
Linux User
frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.frostschutz ought to be getting tired of karma fortunes by now.
 
frostschutz's Avatar
 
Posts: 2,279
Karma: 6123806
Join Date: Sep 2010
Location: Heidelberg, Germany
Device: none
surely there's already an osx port for imagemagick?
frostschutz is offline   Reply With Quote
Old 08-16-2012, 04:49 AM   #5
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
Sorry, I do not own a Mac OS box.

There are several discussions in sites like StackOverflow about compiling imagemagick from sources on OS X. You might find useful the following: http://stackoverflow.com/questions/7...x-lion-trouble
AlPe is offline   Reply With Quote
Old 08-16-2012, 11:00 AM   #6
shorshe
Enthusiast
shorshe began at the beginning.
 
shorshe's Avatar
 
Posts: 28
Karma: 10
Join Date: Aug 2012
Location: Munich, Germany
Device: iPad
Quote:
Originally Posted by frostschutz View Post
surely there's already an osx port for imagemagick?
Yes there is a port, which kann be installed via "homebrew" packet manager.

But I would love to give the users a self-contained app, without any extra installs. This would require to statically compile imagemagick and bundle it inside the app. A Static compile of imagemagick seems to be a tricky task:
--- Edit -----
http://www.imagemagick.org/discourse...ic.php?t=13145
--------------

Apart from that I don't even know if the license of every dependency would allow that.

Last edited by shorshe; 08-22-2012 at 09:24 AM.
shorshe is offline   Reply With Quote
Old 08-20-2012, 07:17 AM   #7
AlPe
Digital Amanuensis
AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.AlPe ought to be getting tired of karma fortunes by now.
 
AlPe's Avatar
 
Posts: 727
Karma: 1446357
Join Date: Dec 2011
Location: Turin, Italy
Device: Several eReaders and tablets
Quote:
Originally Posted by shorshe View Post
Yes there is a port, which kann be installed via "homebrew" packet manager.

But I would love to give the users a self-contained app, without any extra installs. This would require to statically compile imagemagick and bundle it inside the app. A Static compile of imagemagick seems to be a tricky task.

Apart from that I don't even know if the license of every dependency would allow that.
I see. I am not familiar with OS X, so I cannot ponder the question throughfully. If "sips" is a standard utility of OS X (as it seems to me), then your script is a very adequate solution.

It is a shame it lacks many powerful options already included in imagemagick, though.
AlPe is offline   Reply With Quote
Old 06-07-2013, 11:36 PM   #8
sueneu
eBook Designer
sueneu began at the beginning.
 
sueneu's Avatar
 
Posts: 26
Karma: 10
Join Date: Jun 2010
Location: New Jersey
Device: ipad, nook, kindle
Wow. This script just made my night. Thanks.
sueneu is offline   Reply With Quote
Old 06-14-2013, 10:42 AM   #9
shorshe
Enthusiast
shorshe began at the beginning.
 
shorshe's Avatar
 
Posts: 28
Karma: 10
Join Date: Aug 2012
Location: Munich, Germany
Device: iPad
nice

nice
shorshe is offline   Reply With Quote
Old 06-14-2013, 01:16 PM   #10
Lancelot
Enthusiast
Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!Lancelot , Klaatu Barada Niktu!
 
Posts: 28
Karma: 5010
Join Date: Apr 2011
Device: none
Why do you need a script for this? Can you control the re-sampling quality? Image quality is horrible in most epubs. I understand the need for automation but you give up so much on quality. I especially hate how InDesign export images!

My process is simply create a Photoshop action (all the quality control I want) and then check it again quickly via Bridge in metadata view.
Lancelot is offline   Reply With Quote
Old 06-14-2013, 03:01 PM   #11
SBT
Fanatic
SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.
 
SBT's Avatar
 
Posts: 580
Karma: 810184
Join Date: Sep 2010
Location: Norway
Device: prs-t1, tablet, Nook Simple, assorted kindles, iPad
Not sure if you consider this an improvement – oh well...
Code:
#!/bin/bash
MAXsize=1900000;
while read v; do
    h=`sips -g pixelHeight "$v" | sed -n '${s/.* //;p}'`
    w=`sips -g pixelWidth "$v" | sed -n '${s/.* //;p}'`
    pxlnmbr=$(( $h * $w));
    echo "Number of Pixels in $v ($w x $h) is $pxlnmbr";
    if [[ $pxlnmbr -gt $MAXsize ]]; then
    factor=`echo "sqrt($MAXsize *100^2/ $pxlnmbr) " | bc`;
    echo "factor: $factor%";
    newWidth=$(( $w * $factor / 100 ))
    newHeight=$(( $w * $factor / 100 ))
    echo "$v new: $newWidth x $newHeight";
    sips -z $newHeight $newWidth "$v"
    echo " ";
    fi
done < <(find $1/ -name "*.jpeg" -or -name "*.jpg" -or -name "*.gif" -or -name "*.png")
($anzahl should be replaced by $pxlnumber, nicht so?)
By using a while loop instead of a for loop, file names with spaces are permitted (can't remember if they're permitted according to ePub specs, though), and enclose $v in "".
Sticking the find clause at the end is for a very good reason, but a very complicated technical one that I cannot recall just at the moment...

None of the rest can strictly be called improvements, rather just a demonstration of "there's more than one way to do it", and my own preferences (or prejudices?) for making scripts compact (or do I mean unreadable?)

For simple integer arithmetic, this can be done directly in the shell within
$(( ... )) parenthesis, I therefore express the resizing factor as a %; two-digit accuracy should be sufficient for the intended purpose.

Don't have a fruit machine, so I haven't been able to test it properly.
SBT is offline   Reply With Quote
Old 06-21-2013, 03:56 AM   #12
shorshe
Enthusiast
shorshe began at the beginning.
 
shorshe's Avatar
 
Posts: 28
Karma: 10
Join Date: Aug 2012
Location: Munich, Germany
Device: iPad
Quote:
Originally Posted by Lancelot View Post
Why do you need a script for this? Can you control the re-sampling quality? Image quality is horrible in most epubs. I understand the need for automation but you give up so much on quality. I especially hate how InDesign export images!
Depends on how much time i'm able to invest and depending on the content. I usually export from ID in a very high dpi setting. I'm glad the images are already cropped, like in the original work.

But you are right. Quality can always be improved. As long as you get paid for it...

Last edited by shorshe; 06-24-2013 at 03:55 AM.
shorshe is offline   Reply With Quote
Old 06-21-2013, 04:10 AM   #13
shorshe
Enthusiast
shorshe began at the beginning.
 
shorshe's Avatar
 
Posts: 28
Karma: 10
Join Date: Aug 2012
Location: Munich, Germany
Device: iPad
Quote:
Originally Posted by SBT View Post
Not sure if you consider this an improvement – oh well...
Don't have a fruit machine, so I haven't been able to test it properly.
Thanks for your Update!
I just gave it a quick try on my fruitmachine and got


Code:
sed: 1: "${s/.* //;p}": extra characters at the end of p command
sed: 1: "${s/.* //;p}": extra characters at the end of p command
mmsizr_new.sh: line 6: * : syntax error: operand expected (error token is "* ")
shorshe is offline   Reply With Quote
Old 06-21-2013, 06:11 AM   #14
SBT
Fanatic
SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.SBT ought to be getting tired of karma fortunes by now.
 
SBT's Avatar
 
Posts: 580
Karma: 810184
Join Date: Sep 2010
Location: Norway
Device: prs-t1, tablet, Nook Simple, assorted kindles, iPad
Ah, the delights of non-standard standards...
Apparently, OSX sed, unlike GNU sed, does not interpret ';' as a newline.
To get it to work, either
Code:
sed -n -e '${' -e 's/.* //' -e p -e '}'
or
Code:
sed -n '${
s/.* //
p
}'
may work. However, your original solution for these lines now definitely
win out in terms of elegance.
Oh well, I've demonstrated there's more than one way to do it, at any rate. And you can do some mighty cool stuff with multi-line sed...
SBT is offline   Reply With Quote
Old 06-28-2013, 01:35 PM   #15
sueneu
eBook Designer
sueneu began at the beginning.
 
sueneu's Avatar
 
Posts: 26
Karma: 10
Join Date: Jun 2010
Location: New Jersey
Device: ipad, nook, kindle
Photoshop Action

Quote:
Originally Posted by Lancelot View Post
Why do you need a script for this? Can you control the re-sampling quality? Image quality is horrible in most epubs. I understand the need for automation but you give up so much on quality. I especially hate how InDesign export images!

My process is simply create a Photoshop action (all the quality control I want) and then check it again quickly via Bridge in metadata view.
Lancelot, Can you see the total number of pixels in Bridge's metadata view?
sueneu is offline   Reply With Quote
Reply

Tags
2 million pixels, apple, apple ibookstore, epub

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for freeware to batch resize images. GoldThreader Workshop 10 04-23-2012 01:58 PM
resize images ? cybmole Sigil 5 04-03-2011 09:27 AM
Linux script for images to Kindle Screensaver soymicmic Kindle Developer's Corner 4 01-28-2011 12:20 PM
Images Folder - Resize files Fossil Sigil 9 07-24-2010 12:36 PM


All times are GMT -4. The time now is 12:44 AM.


MobileRead.com is a privately owned, operated and funded community.