MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   ImageOptimizer (https://www.mobileread.com/forums/showthread.php?t=270473)

Toxaris 02-02-2016 08:14 AM

ImageOptimizer
 
1 Attachment(s)
This is an edit plugin that should work on Windows, Linux and OSX.

It is a wrapper plugin around several image optimization programs. It can optimize optimize JPG, PNG and GIF images.

The programs used are equal to my ePUBOptimizer program, but this plugin is Python only and will not subset fonts.

Prereqs: Sigil 0.8.2 (or higher). On Sigil 0.9.3 and higher it will make use of autostart and autoclose.
Prerequisite is that on Linux the programs jpegtran/optipng/gifsicle are required. For Windows and OSX these are included. The program jpegtran is included in libjpeg-progs on Linux.

Upon first execution a preference file will be created in the plugin_prefs directory. If required another version of jpegtran can be entered or the usage of wine, and thereby the included windows executables, can be activated. By default the standard jpegtran will be used and is wine not enabled.

Current Version: "0.2.1"

roger64 02-02-2016 09:09 AM

Hi

Thank very much you for porting this plugin to Sigil. I tried it on Archlinux 64 bits with Sigil 9.2.

I installed optipng and gifsicle. However I did not find jpegtran or libjpeg-progs (they probably have other names) and so my trial for today was unconclusive (the program kept waiting left-right-left-right...).

I had good hopes since I use Imagemagick 6.9.3. but no.

Toxaris 02-02-2016 10:08 AM

Roger, a quick search for Archlinux tells me that the library libjpeg-turbo contains jpegtran. That should do the trick.

It is strange the program kept waiting, it should just report the return code if the program is not found.

eschwartz 02-02-2016 10:55 AM

roger64 -- in future, an excellent way to find needed programs on Arch Linux is to use "pkgfile". :)


libjpeg-turbo is required by qt5-base, so it is already an indirect dependency of sigil.

roger64 02-02-2016 09:35 PM

Thanks for pkgfile. I did not not know.

I installed this libjpeg-turbo to learn that.. it was already installed. So, the situation is the same: the plugin does not work for me on one valid EPUB3 file with three jpegs. It keeps "running" and never stops.

rubeus 02-03-2016 03:21 AM

Can you see in the process list the hpegtrans program running? So maybe the plugin is just waiting for the exteranl program which is waiting for whatever.

Toxaris 02-03-2016 03:48 AM

I will check again on my Linux machines.

Doitsu 02-03-2016 06:15 AM

Quote:

Originally Posted by roger64;3251189I installed [I
optipng[/I] and gifsicle. However I did not find jpegtran or libjpeg-progs (they probably have other names) and so my trial for today was unconclusive (the program kept waiting left-right-left-right...).

Can you please check the version number of jpegtran? Toxaris's plugin uses version 9, which uses a different syntax than the previous version which accepts only one file name parameter.

The old version has the following syntax:

Code:

usage: jpegtran [switches] [inputfile]
however, the new version uses the following syntax:

Code:

usage: jpegtran [switches] [inputfile] [outputfile]
If you use the new syntax with the old version, it enters an endless loop, which causes the plugin to hang.

AFAIK, libjpeg-turbo is a fork of jpegtran that uses the old syntax. I.e. you can't use it to optimize .jpeg files under Linux.

roger64 02-03-2016 06:31 AM

@Doitsu

I don't know if this answers your question. It's cryptic for me :)

Code:

[roger@anterg ~]$ jpegtran -v
libjpeg-turbo version 1.4.2 (build 20151205)
Copyright (C) 1991-2012 Thomas G. Lane, Guido Vollbeding
Copyright (C) 1999-2006 MIYASAKA Masaru
Copyright (C) 2009 Pierre Ossman for Cendio AB
Copyright (C) 2009-2015 D. R. Commander
Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2013-2014 MIPS Technologies, Inc.
Copyright (C) 2013 Linaro Limited

Emulating The Independent JPEG Group's software, version 8d  15-Jan-2012

Code:

[roger@anterg ~]$ locate jpegtran
/home/roger/.local/share/sigil-ebook/sigil/plugins/ImageOptimizer/osx/jpegtran
/home/roger/.local/share/sigil-ebook/sigil/plugins/ImageOptimizer/win/jpegtran.exe
/home/roger/.local/share/sigil-ebook/sigil/plugins/ePUBOptimizer/osx/jpegtran
/home/roger/.local/share/sigil-ebook/sigil/plugins/ePUBOptimizer/win/jpegtran.exe
/opt/calibre/bin/jpegtran
/usr/bin/jpegtran
/usr/share/man/man1/jpegtran.1.gz
[roger@anterg ~]$

I noted that the jpegtran in /usr has a 31k size, while the same in /opt has a 493k size. Should I exchange one for another?

Toxaris 02-03-2016 07:01 AM

Quote:

Originally Posted by Doitsu (Post 3251888)
Can you please check the version number of jpegtran? Toxaris's plugin uses version 9, which uses a different syntax than the previous version which accepts only one file name parameter.

The old version has the following syntax:

Code:

usage: jpegtran [switches] [inputfile]
however, the new version uses the following syntax:

Code:

usage: jpegtran [switches] [inputfile] [outputfile]
If you use the new syntax with the old version, it enters an endless loop, which causes the plugin to hang.

AFAIK, libjpeg-turbo is a fork of jpegtran that uses the old syntax. I.e. you can't use it to optimize .jpeg files under Linux.

That is useful info, thanks! I can probably work with that. I haven't been able to test it myself, I spent all morning building Sigil 0.9.3 on my Linux machine and it still doesn't work (my fault probably...).

Doitsu 02-03-2016 07:18 AM

@roger64: The jpegtran version that you've installed is the fork that I mentioned that still uses the old syntax and will most likely not work.

I'd recommend the following workaround:

1. Install the Wine windows emulator, if you haven't already done so.
2. Change lines 83 and 85 in plugin.py as follows:

old version:

Code:

            exe_path = 'jpegtran'
               
        args = [exe_path]

new version:

Code:

            exe_path = os.path.join(SCRIPT_DIR,'win', 'jpegtran.exe')
               
        args = ['wine', exe_path]

Make sure not to mess with the indentation otherwise Python will display some cryptic error messages.

DiapDealer 02-03-2016 08:57 AM

Why not allow the user to override paths to external programs via the prefs json?

Code:

prefs = bk.get_prefs()
#Default to none
if 'jpegtrans_path' not in prefs
    prefs['jpegtran_path'] = None
# Default to false
if 'use_wine' not in prefs
    prefs['use_wine'] = False

Then somewhere in your platform logic:
Code:

islinux = sys.platform.startswith('linux')

if islinux and prefs['jpegtran_path'] is not None:
    exe_path = prefs['jpegtran_path']
else:
    exe_path = 'jpegtran'
if islinux and prefs['use_wine']:
    args = ['wine', path_to_included_windows_exe]
else:
    args = [exe_path]

''' Plugin processing '''

# Need a call to savePrefs so the json file gets created after first run
bk.savePrefs(prefs)

Or something similar. I've not actually looked at the plugin code.

That way the user can just modify the json prefs file to 1) point to a newer version of jpegtran (which I'm betting calibre's is); or 2) use wine to run the included Windows version.

roger64 02-03-2016 09:14 AM

1 Attachment(s)
Quote:

Originally Posted by Doitsu (Post 3251920)
@roger64: The jpegtran version that you've installed is the fork that I mentioned that still uses the old syntax and will most likely not work

This is to report success. :thumbsup:
The images went from
146 to 127k
334 to 244k
863 to 812k

DiapDealer 02-03-2016 09:29 AM

Quote:

Originally Posted by roger64 (Post 3251973)
This is to report success. :thumbsup:
The images went from
146 to 127k
334 to 244k
863 to 812k

Keep in mind that your code changes will be lost if you ever re-install the plugin or upgrade.

roger64 02-03-2016 10:23 AM

Quote:

Originally Posted by DiapDealer (Post 3251985)
Keep in mind that your code changes will be lost if you ever re-install the plugin or upgrade.

OK Thanks again.


All times are GMT -4. The time now is 08:30 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.