Use imagesize instead of Pillow to get image sizes

This commit is contained in:
Tobias Gruetzmacher 2020-01-04 15:56:35 +01:00
parent a8ab66f781
commit c48d96d5e3
5 changed files with 24 additions and 17 deletions

View file

@ -85,11 +85,11 @@ Windows users can download a complete binary (including Python) from the
The simplest way to install and upgrade dosage is with [pipx]. To install the The simplest way to install and upgrade dosage is with [pipx]. To install the
newest stable version with all optional features use: newest stable version with all optional features use:
pipx install --spec dosage[css,dimensions,bash] dosage pipx install --spec dosage[css,bash] dosage
To install the newest development version, use: To install the newest development version, use:
pipx install --spec "dosage[css,dimensions,bash] @ git+https://github.com/webcomics/dosage.git" dosage pipx install --spec "dosage[css,bash] @ git+https://github.com/webcomics/dosage.git" dosage
To upgrade such installations, just run: To upgrade such installations, just run:
@ -100,7 +100,7 @@ To upgrade such installations, just run:
If you want to run dosage directly from the source code, you should install If you want to run dosage directly from the source code, you should install
it in "[editable]" mode, preferable in a [virtual environment]: it in "[editable]" mode, preferable in a [virtual environment]:
pip install -e .[css,dimensions,bash] pip install -e .[css,bash]
You can invoke Dosage directly from the source code as `./dosage`, but this You can invoke Dosage directly from the source code as `./dosage`, but this
mode of operation is discouraged, since dependencies might be missing. mode of operation is discouraged, since dependencies might be missing.

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
# Copyright (C) 2012-2014 Bastian Kleineidam # Copyright (C) 2012-2014 Bastian Kleineidam
# Copyright (C) 2015-2017 Tobias Gruetzmacher # Copyright (C) 2015-2020 Tobias Gruetzmacher
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
@ -11,6 +11,8 @@ from six.moves.urllib.parse import quote as url_quote
import codecs import codecs
import json import json
import imagesize
from . import rss, util, configuration from . import rss, util, configuration
from .output import out from .output import out
@ -134,18 +136,24 @@ class RSSEventHandler(EventHandler):
def getDimensionForImage(filename, maxsize): def getDimensionForImage(filename, maxsize):
"""Return scaled image size in (width, height) format. """Return scaled image size in (width, height) format.
The scaling preserves the aspect ratio. The scaling preserves the aspect ratio."""
If PIL is not found returns None."""
try: try:
from PIL import Image origsize = imagesize.get(filename)
except ImportError: except Exception as e:
out.warn("Could not get image size of {}: {}".format(os.path.basename(filename), e))
return None return None
img = Image.open(filename)
width, height = img.size width, height = origsize
if width > maxsize[0] or height > maxsize[1]: if width > maxsize[0]:
img.thumbnail(maxsize) height = max(round(height * maxsize[0] / width), 1)
out.info("Downscaled display size from %s to %s" % ((width, height), img.size)) width = round(maxsize[0])
return img.size if height > maxsize[1]:
width = max(round(width * maxsize[1] / height), 1)
height = round(maxsize[1])
if width < origsize[0] or height < origsize[1]:
out.info("Downscaled display size from %s to %s" % (origsize, (width, height)))
return (width, height)
class HtmlEventHandler(EventHandler): class HtmlEventHandler(EventHandler):

View file

@ -1,4 +1,5 @@
colorama colorama
imagesize
lxml lxml
requests>=2.0 requests>=2.0
six six

View file

@ -35,6 +35,7 @@ python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
packages = find: packages = find:
install_requires = install_requires =
colorama colorama
imagesize
lxml lxml
requests>=2.0 requests>=2.0
six six
@ -50,8 +51,6 @@ console_scripts =
[options.extras_require] [options.extras_require]
css = css =
cssselect cssselect
dimensions =
Pillow
bash = bash =
argcomplete argcomplete
test = test =

View file

@ -20,7 +20,6 @@ deps =
# Also install extra dependencies for tests. # Also install extra dependencies for tests.
extras = extras =
css css
dimensions
test test
[testenv:flake8] [testenv:flake8]