From 0d11e6ae5ade42b64fa4b0994cb31c48720c68e9 Mon Sep 17 00:00:00 2001 From: Alex Xu Date: Fri, 7 Jan 2022 19:23:49 -0800 Subject: [PATCH] only crop top and bottom of pages --- mangle/image.py | 10 +++++++++- mangle/ui/options.ui | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mangle/image.py b/mangle/image.py index 2fe18b4..3b91425 100644 --- a/mangle/image.py +++ b/mangle/image.py @@ -135,6 +135,13 @@ def quantizeImage(image, palette): @protect_bad_image def scaleCropImage(image, size): + widthDev, heightDev = size + widthImg, heightImg = image.size + + # don't crop 2 page spreads. + if (float(widthImg) / float(heightImg)) > (float(widthDev) / float(heightDev)): + return resizeImage(image, size) + return ImageOps.fit(image, size, Image.ANTIALIAS) @@ -184,11 +191,12 @@ def orientImage(image, size): # by inverting colors, and asking a bounder box ^^ @protect_bad_image def autoCropImage(image): + w, h = image.size try: x0, y0, xend, yend = ImageChops.invert(image).getbbox() except TypeError: # bad image, specific to chops return image - image = image.crop((x0, y0, xend, yend)) + image = image.crop((0, y0, w, yend)) return image diff --git a/mangle/ui/options.ui b/mangle/ui/options.ui index 29cedbb..08cc082 100644 --- a/mangle/ui/options.ui +++ b/mangle/ui/options.ui @@ -217,7 +217,7 @@ - Scale and crop images to fill the screen + Scale and crop images to fill screen width