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
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:
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:
@ -100,7 +100,7 @@ To upgrade such installations, just run:
If you want to run dosage directly from the source code, you should install
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
mode of operation is discouraged, since dependencies might be missing.

View file

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

View file

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

View file

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

View file

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