View Single Post
Old 02-10-2008, 01:24 PM   #13
myelinator
Junior Member
myelinator began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Feb 2008
Device: kindle
Quote:
Originally Posted by wallcraft View Post
The maximum image size in a MOBI file on the Kindle appears to be 640 by 520.
You are right, wallcraft, the maximum image is 640x520. I'm glad that we have the right number now (it makes my document conversion look even better, thanks!). What a waste of screenspace (and an odd aspect ratio 16:13)!

Apologies to lovebeta - I thought I was seeing something that I wasn't. I was confused by the margins on the articles I was converting using this technique (before I started trimming them off).

Anyway the correct script code would now be:
Code:
#!/bin/bash

for FILE in "$@"; do
FILEPATH=${FILE%/*}
FILENAME=${FILE##*/}
FILEBASE=${FILENAME%%.*}
FILEEXT=${FILENAME#*.}
IMGEXT=jpg

# if my experiments are right then the size of the Kindle screen is 525x700
# (a 4:3 aspect ratio) as one might expect

# use imagemagick to do all the needed conversions:
# -density              166x166 to get the right dpi
# -trim                 off the margins (do it before you resize!)
# -resize 700           to get the width of the pages maximized
# -rotate -90           to maximize the use of the screen
# -colorspace gray      self explanatory
# -type Grayscale       self explanatory
# -level                darken the image
# +dither               turn off dither
# -level 34%,100%,1.2   darken the image
# -map kindle.gif       a four color gif with the allowed shades of gray
echo "**********************************************************************"
echo "* Converting to $FILE to $IMGEXT files... please be patient..."
echo "**********************************************************************"
convert -density 166x166  "${FILEBASE}.pdf" -trim +repage -resize 640 -rotate -90 -colorspace gray -type Grayscale -level 34%,100%,1.2 +dither -map kindle.gif "${FILEBASE}.${IMGEXT}"

echo "Dividing the $IMGEXT page images..."
for PAGE in "${FILEBASE}"*.${IMGEXT}
  do
    PAGEBASE=${PAGE%%.*}
    echo $PAGEBASE
    convert "${PAGEBASE}.${IMGEXT}" -crop 520x640+0 +repage "${PAGEBASE}-01.${IMGEXT}"
    convert "${PAGEBASE}.${IMGEXT}" -crop 520x640+450 +repage "${PAGEBASE}-02.${IMGEXT}"
    convert "${PAGEBASE}.${IMGEXT}" -crop 520x640+900 +repage "${PAGEBASE}-03.${IMGEXT}"
    rm "${PAGE}"
done

echo "Writing the HTML file..."
cat > "${FILEBASE}.html" <<HEAD
<html><head><guide></guide></head><body>
HEAD
for IMG in "${FILEBASE}"*.${IMGEXT}
  do
    echo "<img src='${IMG}'/><mbp:pagebreak/>" >> "${FILEBASE}.html"
  done
echo "</body></html>" >> "${FILEBASE}.html"

echo "Converting HTML to MOBI..."
html2mobi --title "${FILEBASE}" --author "BBB" "${FILEBASE}.html"

#echo "Cleaning up..."
rm "${FILEBASE}.html" "${FILEBASE}"*.${IMGEXT}
done
You probably should also modify MobiPerl/Util.pm again to reflect the 640x520 dimension when you are converting other documents with html2mobi, etc.
myelinator is offline   Reply With Quote