05-25-2022, 10:04 PM | #1 |
Connoisseur
Posts: 62
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
|
NickelMenu script for fixing Pocket images
As you may know, the current Pocket implementation in Kobo readers struggles with images other than JPEG. JPEGs will be displayed fine, but all other image types, like PNG, SVG or GIF simply won't be displayed.
As I grew tired of seeing the "image not found" icon - too many articles using png files and the like - I wrote a small script for NickelMenu to convert these images to JPEG on the fly. Add a line like this one to your NickelMenu config: Code:
menu_item :library :Fix Pocket Images :cmd_spawn :quiet:/bin/sh /mnt/onboard/.adds/pocket/fix.sh chain_success :dbg_toast :Done The script currently supports the following formats: GIF, PNG, SVG, WEBP. Ps. You might need to reboot your Kobo if the article already was cached. Changelog: 2022-05-28:
2022-06-08:
2022-06-08:
Last edited by qkqw; 07-06-2022 at 06:11 PM. |
05-31-2022, 12:11 AM | #2 |
Zealot
Posts: 108
Karma: 67444
Join Date: Dec 2018
Device: Kobo Clara HD
|
Hi there! Thank you for this excellent add on! Any reason why it's png only for now?
Can it be expanded to other file formats? |
Advert | |
|
05-31-2022, 05:34 AM | #3 |
Resident Curmudgeon
Posts: 76,492
Karma: 136564766
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
But how does the website code know to pick up the converted images given that they will now have a different file extension?
|
05-31-2022, 06:04 AM | #4 | |
Zealot
Posts: 108
Karma: 67444
Join Date: Dec 2018
Device: Kobo Clara HD
|
Quote:
If you have a look at .kobo/articles directory, you can see that the images are stored as a UID filename with no extension. The article file (index.html) makes a call to the filename only. If it's JPG encoded, it displays, else it fails. What this script does is to make an in-place replacement of the PNG file with a JPG one. Since the filename remains, the call to the image should still be valid and will display correctly. What I want to check though is whether this can be used as a catch-all for any image type. |
|
05-31-2022, 07:46 AM | #5 | |
Connoisseur
Posts: 62
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
|
Quote:
Also, @NiLuJe's ImageMagick only seems to support Jpg, Jfif and Png at this time, but I could cross compile a version with support for more file types if needed. |
|
Advert | |
|
05-31-2022, 07:49 AM | #6 | |
Connoisseur
Posts: 62
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
|
Quote:
To use a catch-all, you'd just need to change this line Code:
if [ "$FORMAT" == "PNG" ]; then to this Code:
if [ "$FORMAT" != "JPG" ]; then |
|
06-05-2022, 07:08 AM | #7 |
Zealot
Posts: 108
Karma: 67444
Join Date: Dec 2018
Device: Kobo Clara HD
|
Just thinking out loud, but is there a timeout for this?
Is there a possibility that it might get hung up on an image and keep eating battery? |
06-06-2022, 06:50 PM | #8 |
Connoisseur
Posts: 62
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
|
|
06-07-2022, 07:07 PM | #9 |
BLAM!
Posts: 13,497
Karma: 26047188
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
IM has a builtin fairly complex limits framework that can be set up to avoid issues in degenerate use-cases (because you can't be 100% sure one weird bug on specific input wouldn't cause a long busy loop).
(at a minima, passing something like -limit time 60 might not be entirely stupid). |
06-08-2022, 03:51 AM | #10 |
Zealot
Posts: 108
Karma: 67444
Join Date: Dec 2018
Device: Kobo Clara HD
|
Thank you, @NiLuJe! That's the fringe case example I was thinking of.
@qkqw, will adding -limit time 60 to the variables CONVERT & IDENTIFY work? Code:
#!/bin/sh ARTICLES="/mnt/onboard/.kobo/articles" CONVERT="/mnt/onboard/.adds/pocket/convert -limit time 60" IDENTIFY="/mnt/onboard/.adds/pocket/identify -quiet -limit time 60" LD_LIBRARY_PATH="/mnt/onboard/.adds/pocket/lib:${LD_LIBRARY_PATH}" export LD_LIBRARY_PATH for i in $(find $ARTICLES -type f -not -iname "*.html"); do FORMAT=$($IDENTIFY -format "%m" "$i") if [ "$FORMAT" == "PNG" ]; then $CONVERT "$i" "$i.jpg" mv "$i.jpg" "${i%.jpg}" fi done |
06-08-2022, 01:18 PM | #11 |
Connoisseur
Posts: 62
Karma: 143000
Join Date: Apr 2022
Device: Kobo Libra 2
|
|
06-08-2022, 04:46 PM | #12 |
Zealot
Posts: 108
Karma: 67444
Join Date: Dec 2018
Device: Kobo Clara HD
|
|
06-12-2022, 03:37 AM | #13 |
Zealot
Posts: 108
Karma: 67444
Join Date: Dec 2018
Device: Kobo Clara HD
|
I've been scratching my head over this.
The below NM config displays Done when the script process is spawned and not when the Pocket image conversions are done. Code:
menu_item:library:Fix Pocket Images:cmd_spawn:quiet:/bin/sh /mnt/onboard/.adds/pocket/fix.sh chain_success:dbg_toast:Done Code:
menu_item:library:Fix Pocket Images:cmd_output:500:/bin/sh /mnt/onboard/.adds/pocket/fix.sh chain_success:dbg_toast:Done Code:
#!/bin/sh ARTICLES="/mnt/onboard/.kobo/articles" CONVERT="/mnt/onboard/.adds/pocket/convert -limit time 60" IDENTIFY="/mnt/onboard/.adds/pocket/identify -limit time 60 -quiet" PROCESSED="0" LD_LIBRARY_PATH="/mnt/onboard/.adds/pocket/lib:${LD_LIBRARY_PATH}" export LD_LIBRARY_PATH for i in $(find $ARTICLES -type f -not -iname "*.html"); do FORMAT=$($IDENTIFY -format "%m" "$i") if [ "$FORMAT" == "PNG" ]; then $CONVERT "$i" "$i.jpg" if [ $? -eq 0 ]; then mv "$i.jpg" "${i%.jpg}" (($PROCESSED)) || PROCESSED="1"; fi fi done if [ "$PROCESSED" == "1" ]; then echo "DONE: Pocket articles optimised"; else echo "NOTE: Pocket articles not/already optimised"; fi Any idea what I'm doing wrong? |
06-12-2022, 07:03 AM | #14 | |
Guru
Posts: 869
Karma: 2676800
Join Date: Sep 2008
Location: Taranaki - NZ
Device: Kobo Aura H2O, Kobo Forma
|
Quote:
Code:
cmd_output Code:
:cmd_output :500:command A better option would be to use a program such as FBInk to output messages to the screen. You may have to hunt for precompiled binaries, though it is available in NiLuJe's stuff pack. Alternatively, another way to output messages is my own NickelDBus. Of the two, FBInk isn't as intrusive, as it doesn't hook itself into the Kobo software in any manner. |
|
06-12-2022, 01:55 PM | #15 |
Zealot
Posts: 108
Karma: 67444
Join Date: Dec 2018
Device: Kobo Clara HD
|
Thank you for the feedback, @sherman!
Seems like this might be more than I can chew with very little pay-off. I'll look into both FBInk & NickelDBus to see if I can make sense of them. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
fixing images? | PandathePanda | Workshop | 8 | 11-15-2017 04:49 AM |
Script to resize images to 2 Million Pixels | shorshe | ePub | 14 | 06-28-2013 01:35 PM |
Creation of Complex Script E-Book Using Images for Every Word? | sungkhum | Conversion | 8 | 10-26-2011 05:20 PM |
Script for fixing covers on B&N Nook Color | jmricker | Devices | 0 | 06-28-2011 02:45 PM |
Linux script for images to Kindle Screensaver | soymicmic | Kindle Developer's Corner | 4 | 01-28-2011 12:20 PM |