Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #-----------------------------------------
- #
- # ./slicecomic.sh "FILENAME"
- #
- # This is a bash script I wrote to make
- # reading comics on my PRS-300 easier.
- # Since the zoom on the PRS-300 does
- # not scroll, I slice the pages into
- # 4-parts that are each "screen-sized"
- # effectively giving me a 4x zoom.
- # Before each set of 4 zoomed images,
- # I put in a downscaled full-page
- # so I can see the flow before I zoom
- # in to read the page.
- # Not perfect but I can enjoy a comic
- # on my e-reader fairly well this way.
- # Obviously in grayscale ;)
- #
- # Currently full of kludges but
- # it works for me. I might polish it
- # at some future date. 2022-01-31
- #
- # Removed a kludge or two on 2022-01-31
- # later in the day
- #
- #------------------------------------------
- # First, we unzip the cbz
- # or unrar the cbr
- # or convert the pdf
- # Brute-forcing try of all 3
- # one should work and the other two should fail
- # ignore the error messages. It'll keep
- # plugging along.
- echo "Extracting the images from the file..."
- unzip -j "$1" 2> /dev/null
- unrar e -ai "$1" 2> /dev/null
- convert -density 300 -trim "$1" -quality 100 tile%04d.jpg 2> /dev/null
- ls *jpg| cat -n | while read n f; do mv "$f" `printf "tile%04d.jpg" $(($n-1))`; done
- # Get the basename (without path) for later
- fname=$(basename "$1")
- # The PRS-300 has 600x800 screen
- # Setting the height to 1600 seems
- # to net me a one-page-to-4-tiles
- # result, but you may need/want
- # to adjust for your situation
- echo "Resizing the pages"
- mogrify -resize 1200x1600 *.jpg
- echo "Padding any short sided pages"
- mogrify -extent 1200x1600 -gravity Center -fill white *.jpg
- #Greyscale because the e-ink is greyscale
- echo "Converting to grayscale because e-ink"
- mogrify -colorspace gray *.jpg
- # Make a temp tiles directory
- # and slice the comic images into
- # tiles in it.
- echo "Slicing out the tiles"
- mkdir tiles
- convert *.jpg +repage -crop 600x800 ./tiles/tile%04d.jpg
- # Append a "b" into each filename
- # to allow easier "full page view"
- # integration. (see below)
- cd ./tiles
- rename 's/\.jpg$/b\.jpg/' *jpg
- cd ../
- # Shove full pages into every 4th position
- # This lets you look at the whole
- # page for reference of how it
- # flows before looking at the
- # zoomed in sections.
- # Convert to screen size first
- mogrify -resize 600x800 *.jpg
- fcount=0
- for filename in ./*.jpg
- do
- fmovename=$(printf "tile%04d" "$fcount")
- echo $fmovename.jpg
- cp $filename ./tiles/$fmovename.jpg
- fcount=$((fcount+4))
- done
- # Zip the tiles into a cbz with a similar
- # name to the original
- zip -j "Sliced-$fname.cbz" ./tiles/*.jpg
- # Clean up the images
- rm -Rf tiles
- rm *.jpg
- # ebook-convert to LRF
- # which I find is smooth on my
- # Sony PRS-300
- ebook-convert "Sliced-$fname.cbz" "Sliced-$fname.lrf"
- # remove the cbz (or comment this out to keep it)
- # after the lrf is made.
- rm "Sliced-$fname.cbz"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement