Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 11-25-2021, 02:29 PM   #1
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
[Plugin] PNGOptimizer - Lossless/lossy image optimization

Released: November 26, 2021
Current Version: "0.1.2"

This plugin uses optipng for lossless optimization and pngquant for lossy optimization of PNG files.

Disclaimer: Since this plugin will replace the images in your ebook with optimized images, you might want to save your ePub or create a checkpoint before running this plugin.

Credits

BeckyEbook created the plugin icon.

System requirements

This plugin requires at least Sigil 0.9.8. If you uncheck the Use Bundled Python option, you'll also need to install Python 3. Linux users will also need to install optipng (Debian Arch) and pngquant, (Debian, Arch).

Installation

1. Select Manage Plugins from the Plugins menu and enable the Use Bundled Python option, if it isn't already enabled (or grayed out).
2. Click Add Plugin and select PNGOptimizer_v0.1.2.zip. This will install the plugin, which you can select via Plugins > Edit > PNGOptimizer.

Settings

To turn on lossy optimization, edit PNGOptimizer.json and change the lossless value to false:

Code:
  "lossless": false,
You can also define minimum/maximum quality settings via the quality value:

Code:
  "quality": "0-100",
To display the folder that contains PNGOptimizer.json select Edit > Preferences > Open Preferences Location. Then double-click plugins_prefs and PNGOptimizer.
Windows users can also press WIN+R, paste %localappdata%\sigil-ebook\sigil\plugins_prefs\PNGOptimizer into the Run dialog box and hit Enter.

License: GNU General Public License v3 (GPL-3)
Attached Files
File Type: zip PNGOptimizer_v0.1.2.zip (889.2 KB, 676 views)

Last edited by Doitsu; 11-26-2021 at 02:30 PM.
Doitsu is offline   Reply With Quote
Old 11-26-2021, 11:02 AM   #2
bravosx
Connoisseur
bravosx began at the beginning.
 
Posts: 99
Karma: 10
Join Date: Jun 2014
Location: Poland, Żory
Device: Prestigio PER3464B, Onyx Lynx, Lenovo S5000 i Tab4-8"
I installed the JPEGOptimizer and PNGOptimizer plugins and they didn't work properly.
I have received such reports:

- for the JPEGOptimizer

Status: failed
Lossless optimization: cover.jpeg ...
Original file size: 144.70KB
Traceback (most recent call last):
File "C:\Program Files\Sigil\plugin_launchers\python\launcher.py", line 142, in launch
self.exitcode = target_script.run(container)
File "C:\Users\xxxx\AppData\Local\sigil-ebook\sigil\plugins\JPEGOptimizer\plugin.py", line 119, in run
stdout, stderr, returncode = jo_wrapper(*args)
File "C:\Users\xxxx\AppData\Local\sigil-ebook\sigil\plugins\JPEGOptimizer\plugin.py", line 35, in jo_wrapper
return stdout.decode('utf-8'), stderr.decode('utf-8'), returncode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 14: invalid start byte
Error: 'utf-8' codec can't decode byte 0xb3 in position 14: invalid start byte

- for the PNGOptimizer

Status: failed
Lossless processing: exlibris.png ...
Original file size: 11.21KB
Traceback (most recent call last):
File "C:\Program Files\Sigil\plugin_launchers\python\launcher.py", line 142, in launch
self.exitcode = target_script.run(container)
File "C:\Users\xxxx\AppData\Local\sigil-ebook\sigil\plugins\PNGOptimizer\plugin.py", line 159, in run
stdout, stderr, returncode = png_wrapper(*args)
File "C:\Users\xxxx\AppData\Local\sigil-ebook\sigil\plugins\PNGOptimizer\plugin.py", line 51, in png_wrapper
return stdout.decode('utf-8'), stderr.decode('utf-8'), returncode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 29: invalid start byte
Error: 'utf-8' codec can't decode byte 0xb3 in position 29: invalid start byte

I have Sigil 1.8 and Windows 10 Home installed. My mother tongue is polish.
Doitsu, can you help me?
I apologize for my poor English, but I have a translator.
bravosx
bravosx is offline   Reply With Quote
Advert
Old 11-26-2021, 11:09 AM   #3
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
A guess ... your stdin and stdout are not set to use the utf-8 character encoding but instead is set to some other encoding? Perhaps the encoding for an image file name? But just guessing here based on the error message. I am not a Windows person so I do not know how cross process stdin/stdout io is done.
KevinH is offline   Reply With Quote
Old 11-26-2021, 11:09 AM   #4
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
Added to the Sigil Plugin Index.
KevinH is offline   Reply With Quote
Old 11-26-2021, 11:16 AM   #5
bravosx
Connoisseur
bravosx began at the beginning.
 
Posts: 99
Karma: 10
Join Date: Jun 2014
Location: Poland, Żory
Device: Prestigio PER3464B, Onyx Lynx, Lenovo S5000 i Tab4-8"
Quote:
Originally Posted by KevinH View Post
A guess ... your stdin and stdout are not set to use the utf-8 character encoding but instead is set to some other encoding? Perhaps the encoding for an image file name? But just guessing here based on the error message. I am not a Windows person so I do not know how cross process stdin/stdout io is done.
Thank you @KevinH, maybe Doitsu will help?

bravosx
bravosx is offline   Reply With Quote
Advert
Old 11-26-2021, 11:21 AM   #6
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,645
Karma: 5433388
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by bravosx View Post
Thank you @KevinH, maybe Doitsu will help?

bravosx
I am sure he will. He knows much more about Windows than I do.

A simple test is to create a small epub using images file names with ascii characters only and see if that avoids the error.
KevinH is offline   Reply With Quote
Old 11-26-2021, 12:21 PM   #7
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by bravosx View Post
I installed the JPEGOptimizer and PNGOptimizer plugins and they didn't work properly.
The plugin(s) might fail, if the image file name contains non-ASCII characters and/or you're running a very old Windows version.

I'll run some tests and try to update the code to fix this issue.

In the meantime, try changing the following part in both plugin files:

Code:
return stdout.decode('utf-8'), stderr.decode('utf-8'), returncode
to:

Code:
return stdout.decode('utf-8', 'ignore'), stderr.decode('utf-8', 'ignore'), returncode
This should display the error messages returned by the utilities.

Last edited by Doitsu; 11-26-2021 at 12:47 PM.
Doitsu is offline   Reply With Quote
Old 11-26-2021, 01:09 PM   #8
bravosx
Connoisseur
bravosx began at the beginning.
 
Posts: 99
Karma: 10
Join Date: Jun 2014
Location: Poland, Żory
Device: Prestigio PER3464B, Onyx Lynx, Lenovo S5000 i Tab4-8"
Quote:
Originally Posted by Doitsu View Post
The plugin(s) might fail, if the image file name contains non-ASCII characters and/or you're running a very old Windows version.

I'll run some tests and try to update the code to fix this issue.

In the meantime, try changing the following part in both plugin files:

Code:
return stdout.decode('utf-8'), stderr.decode('utf-8'), returncode
to:

Code:
return stdout.decode('utf-8', 'ignore'), stderr.decode('utf-8', 'ignore'), returncode
This should display the error messages returned by the utilities.
@Doitsu
In the PNGOptimizer plug, I changed the line as you suggested and it worked fine. I received this message:
Status: success


Lossless processing: exlibris.png ...
Original file size: 11.21KB
Optimized file size: 9.73KB (86.75%)
Image replaced with optimized image.

Lossless processing: logo_mon.png ...
Original file size: 3.12KB
Optimized file size: 2.02KB (64.63%)
Image replaced with optimized image.

Processing time: 0:00:00.15

Total reduction: 2.59KB

Done.
Click OK to close the Plugin Runner window.

The JPEGOptomizer plug also worked (I made a mistake before). I have received a feedback report:
Status: success


Lossless optimization: cover.jpg ...
Original file size: 137.45KB
Optimized file size: 129.08KB (93.90%)
Image replaced with optimized image.

Total reduction: 8.38KB

Done.
Click OK to close the Plugin Runner window.


I am using Windows 10 Home 21H1 OS build 19043.1348

Thank you very much, your prescription helped.

regards
bravosx

Last edited by bravosx; 11-26-2021 at 01:40 PM.
bravosx is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] JPEGOptimizer - Lossless image optimization Doitsu Plugins 5 12-06-2022 12:03 PM
Strange behavior of image lossless compression since it has been "fixed" Francois_C Editor 2 05-18-2018 03:23 AM
Using image in plugin code Jellby Development 7 03-11-2014 10:56 PM
Conversion Lossy or Lossless? KrowNB Conversion 6 03-11-2011 08:31 AM
Image optimization for Kindle 2 thelostemperor Amazon Kindle 10 03-13-2009 05:34 PM


All times are GMT -4. The time now is 05:27 PM.


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