From 54f3dc60063c81669c67c56b1d8bf4efd6df3145 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 8 Feb 2020 00:34:53 +0300 Subject: [PATCH] Math functions return int in Python 3 --- src/PIL/GifImagePlugin.py | 5 ++--- src/PIL/Image.py | 4 ++-- src/PIL/ImageOps.py | 2 +- src/PIL/JpegImagePlugin.py | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index 63a0f662b..1d94fc7c7 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -25,6 +25,7 @@ # import itertools +import math import os import subprocess @@ -701,14 +702,12 @@ def _get_optimize(im, info): def _get_color_table_size(palette_bytes): # calculate the palette size for the header - import math - if not palette_bytes: return 0 elif len(palette_bytes) < 9: return 1 else: - return int(math.ceil(math.log(len(palette_bytes) // 3, 2))) - 1 + return math.ceil(math.log(len(palette_bytes) // 3, 2)) - 1 def _get_header_palette(palette_bytes): diff --git a/src/PIL/Image.py b/src/PIL/Image.py index f37209335..dec94f2d0 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2015,8 +2015,8 @@ class Image: x, y = transform(x, y, matrix) xx.append(x) yy.append(y) - nw = int(math.ceil(max(xx)) - math.floor(min(xx))) - nh = int(math.ceil(max(yy)) - math.floor(min(yy))) + nw = math.ceil(max(xx)) - math.floor(min(xx)) + nh = math.ceil(max(yy)) - math.floor(min(yy)) # We multiply a translation matrix from the right. Because of its # special form, this is the same as taking the image of the diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index 930f19ddc..e4e0840b8 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -298,7 +298,7 @@ def scale(image, factor, resample=Image.BICUBIC): elif factor <= 0: raise ValueError("the factor must be greater than 0") else: - size = (int(round(factor * image.width)), int(round(factor * image.height))) + size = (round(factor * image.width), round(factor * image.height)) return image.resize(size, resample) diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index e8bee4210..9cba544de 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -614,7 +614,7 @@ def _save(im, fp, filename): info = im.encoderinfo - dpi = [int(round(x)) for x in info.get("dpi", (0, 0))] + dpi = [round(x) for x in info.get("dpi", (0, 0))] quality = info.get("quality", 0) subsampling = info.get("subsampling", -1)