Advertisement
howtophil

Slice Comics (CBZ,CBR,PDF) for Sony PRS-300

Jan 31st, 2022 (edited)
1,644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.86 KB | None | 0 0
  1. #!/bin/bash
  2. #-----------------------------------------
  3. #
  4. # ./slicecomic.sh "FILENAME"
  5. #
  6. # This is a bash script I wrote to make
  7. # reading comics on my PRS-300 easier.
  8. # Since the zoom on the PRS-300 does
  9. # not scroll, I slice the pages into
  10. # 4-parts that are each "screen-sized"
  11. # effectively giving me a 4x zoom.
  12. # Before each set of 4 zoomed images,
  13. # I put in a downscaled full-page
  14. # so I can see the flow before I zoom
  15. # in to read the page.
  16. # Not perfect but I can enjoy a comic
  17. # on my e-reader fairly well this way.
  18. # Obviously in grayscale ;)
  19. #
  20. # Currently full of kludges but
  21. # it works for me. I might polish it
  22. # at some future date. 2022-01-31
  23. #
  24. # Removed a kludge or two on 2022-01-31
  25. # later in the day
  26. #
  27. #------------------------------------------
  28.  
  29. # First, we unzip the cbz
  30. # or unrar the cbr
  31. # or convert the pdf
  32. # Brute-forcing try of all 3
  33. # one should work and the other two should fail
  34. # ignore the error messages. It'll keep
  35. # plugging along.
  36. echo "Extracting the images from the file..."
  37. unzip -j "$1" 2> /dev/null
  38. unrar e -ai "$1" 2> /dev/null
  39. convert -density 300 -trim "$1" -quality 100 tile%04d.jpg 2> /dev/null
  40.  
  41. ls *jpg| cat -n | while read n f; do mv "$f" `printf "tile%04d.jpg" $(($n-1))`; done
  42.  
  43. # Get the basename (without path) for later
  44. fname=$(basename "$1")
  45.  
  46. # The PRS-300 has 600x800 screen
  47. # Setting the height to 1600 seems
  48. # to net me a one-page-to-4-tiles
  49. # result, but you may need/want
  50. # to adjust for your situation
  51. echo "Resizing the pages"
  52. mogrify -resize 1200x1600 *.jpg
  53. echo "Padding any short sided pages"
  54. mogrify -extent 1200x1600 -gravity Center -fill white *.jpg
  55.  
  56. #Greyscale because the e-ink is greyscale
  57. echo "Converting to grayscale because e-ink"
  58. mogrify -colorspace gray *.jpg
  59.  
  60. # Make a temp tiles directory
  61. # and slice the comic images into
  62. # tiles in it.
  63. echo "Slicing out the tiles"
  64. mkdir tiles
  65. convert *.jpg +repage -crop 600x800 ./tiles/tile%04d.jpg
  66.  
  67. # Append a "b" into each filename
  68. # to allow easier "full page view"
  69. # integration. (see below)
  70. cd ./tiles
  71. rename 's/\.jpg$/b\.jpg/' *jpg
  72. cd ../
  73.  
  74. # Shove full pages into every 4th position
  75. # This lets you look at the whole
  76. # page for reference of how it
  77. # flows before looking at the
  78. # zoomed in sections.
  79. # Convert to screen size first
  80. mogrify -resize 600x800 *.jpg
  81. fcount=0
  82. for filename in ./*.jpg
  83. do
  84.     fmovename=$(printf "tile%04d" "$fcount")
  85.     echo $fmovename.jpg
  86.     cp $filename ./tiles/$fmovename.jpg
  87.     fcount=$((fcount+4))
  88. done
  89.  
  90. # Zip the tiles into a cbz with a similar
  91. # name to the original
  92. zip -j "Sliced-$fname.cbz" ./tiles/*.jpg
  93.  
  94. # Clean up the images
  95. rm -Rf tiles
  96. rm *.jpg
  97.  
  98. # ebook-convert to LRF
  99. # which I find is smooth on my
  100. # Sony PRS-300
  101. ebook-convert "Sliced-$fname.cbz" "Sliced-$fname.lrf"
  102.  
  103. # remove the cbz (or comment this out to keep it)
  104. # after the lrf is made.
  105. rm "Sliced-$fname.cbz"
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement