diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index a92c2351f..96ad05933 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -425,21 +425,24 @@ class TestFileTiff(PillowTestCase): infile = "Tests/images/tiff_strip_raw.tif" im = Image.open(infile) - self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png") + self.assert_image_equal_tofile(im, + "Tests/images/tiff_adobe_deflate.png") def test_strip_planar_raw(self): # gdal_translate -of GTiff -co INTERLEAVE=BAND tiff_strip_raw.tif tiff_strip_planar_raw.tiff infile = "Tests/images/tiff_strip_planar_raw.tif" im = Image.open(infile) - self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png") + self.assert_image_equal_tofile(im, + "Tests/images/tiff_adobe_deflate.png") def test_strip_planar_raw_with_overviews(self): # gdaladdo tiff_strip_planar_raw2.tif 2 4 8 16 infile = "Tests/images/tiff_strip_planar_raw_with_overviews.tif" im = Image.open(infile) - self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png") + self.assert_image_equal_tofile(im, + "Tests/images/tiff_adobe_deflate.png") def test_tiled_planar_raw(self): # gdal_translate -of GTiff -co TILED=YES -co BLOCKXSIZE=32 -co BLOCKYSIZE=32 -co INTERLEAVE=BAND \ @@ -447,7 +450,8 @@ class TestFileTiff(PillowTestCase): infile = "Tests/images/tiff_tiled_planar_raw.tif" im = Image.open(infile) - self.assert_image_equal_tofile(im, "Tests/images/tiff_adobe_deflate.png") + self.assert_image_equal_tofile(im, + "Tests/images/tiff_adobe_deflate.png") def test_tiff_save_all(self): import io diff --git a/src/PIL/FtexImagePlugin.py b/src/PIL/FtexImagePlugin.py index 08ce0e006..b2161595c 100644 --- a/src/PIL/FtexImagePlugin.py +++ b/src/PIL/FtexImagePlugin.py @@ -20,7 +20,14 @@ has the following structure: {format_directory} {data} Where: -{header} = { u32:magic, u32:version, u32:width, u32:height, u32:mipmap_count, u32:format_count } +{header} = { + u32:magic, + u32:version, + u32:width, + u32:height, + u32:mipmap_count, + u32:format_count +} * The "magic" number is "FTEX". * "width" and "height" are the dimensions of the texture. diff --git a/src/PIL/Image.py b/src/PIL/Image.py index ca801accb..0ce3f7f49 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1047,7 +1047,8 @@ class Image(object): 2 = fast octree 3 = libimagequant :param kmeans: Integer - :param palette: Quantize to the palette of given :py:class:`PIL.Image.Image`. + :param palette: Quantize to the palette of given + :py:class:`PIL.Image.Image`. :returns: A new image """ @@ -1773,11 +1774,10 @@ class Image(object): if self.mode in ("1", "P"): resample = NEAREST - if self.mode == 'LA': - return self.convert('La').resize(size, resample, box).convert('LA') - - if self.mode == 'RGBA': - return self.convert('RGBa').resize(size, resample, box).convert('RGBA') + if self.mode in ['LA', 'RGBA']: + im = self.convert(self.mode[:-1]+'a') + im = im.resize(size, resample, box) + return im.convert(self.mode) self.load() @@ -1849,7 +1849,8 @@ class Image(object): else: post_trans = translate if center is None: - rotn_center = (w / 2.0, h / 2.0) # FIXME These should be rounded to ints? + # FIXME These should be rounded to ints? + rotn_center = (w / 2.0, h / 2.0) else: rotn_center = center @@ -1864,7 +1865,8 @@ class Image(object): return a*x + b*y + c, d*x + e*y + f matrix[2], matrix[5] = transform(-rotn_center[0] - post_trans[0], - -rotn_center[1] - post_trans[1], matrix) + -rotn_center[1] - post_trans[1], + matrix) matrix[2] += rotn_center[0] matrix[5] += rotn_center[1] @@ -1887,7 +1889,8 @@ class Image(object): matrix) w, h = nw, nh - return self.transform((w, h), AFFINE, matrix, resample, fillcolor=fillcolor) + return self.transform((w, h), AFFINE, matrix, resample, + fillcolor=fillcolor) def save(self, fp, format=None, **params): """ @@ -2154,8 +2157,8 @@ class Image(object): :param fill: If **method** is an :py:class:`~PIL.Image.ImageTransformHandler` object, this is one of the arguments passed to it. Otherwise, it is unused. - :param fillcolor: Optional fill color for the area outside the transform - in the output image. + :param fillcolor: Optional fill color for the area outside the + transform in the output image. :returns: An :py:class:`~PIL.Image.Image` object. """ diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 27205cfff..ac549790a 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -406,7 +406,9 @@ def floodfill(image, xy, value, border=None, thresh=0): except (ValueError, IndexError): return # seed point outside image edge = {(x, y)} - full_edge = set() # use a set to keep record of current and previous edge pixels to reduce memory consumption + # use a set to keep record of current and previous edge pixels + # to reduce memory consumption + full_edge = set() while edge: new_edge = set() for (x, y) in edge: # 4 adjacent method diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index 5384a725b..227294925 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -203,7 +203,7 @@ class FreeTypeFont(object): size=self.size if size is None else size, index=self.index if index is None else index, encoding=self.encoding if encoding is None else encoding, - layout_engine=self.layout_engine if layout_engine is None else layout_engine + layout_engine=layout_engine or self.layout_engine ) diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index 809226847..058447b68 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -441,7 +441,10 @@ def fit(image, size, method=Image.NEAREST, bleed=0.0, centering=(0.5, 0.5)): crop_left = bleed_pixels[0] + (live_size[0]-crop_width) * centering[0] crop_top = bleed_pixels[1] + (live_size[1]-crop_height) * centering[1] - crop = (crop_left, crop_top, crop_left + crop_width, crop_top + crop_height) + crop = ( + crop_left, crop_top, + crop_left + crop_width, crop_top + crop_height + ) # resize the image and return it return image.resize(size, method, box=crop) diff --git a/src/PIL/ImageQt.py b/src/PIL/ImageQt.py index e60261360..bdfe3886c 100644 --- a/src/PIL/ImageQt.py +++ b/src/PIL/ImageQt.py @@ -185,8 +185,8 @@ if qt_is_installed: An PIL image wrapper for Qt. This is a subclass of PyQt's QImage class. - :param im: A PIL Image object, or a file name (given either as Python - string or a PyQt string object). + :param im: A PIL Image object, or a file name (given either as + Python string or a PyQt string object). """ im_data = _toqclass_helper(im) # must keep a reference, or Qt will crash! diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 1e9a028a7..52f997954 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -32,7 +32,8 @@ def _accept(prefix): if is_riff_file_format and is_webp_file and is_valid_vp8_mode: if not SUPPORTED: - return "image file could not be identified because WEBP support not installed" + return "image file could not be identified " \ + "because WEBP support not installed" return True @@ -253,7 +254,8 @@ def _save_all(im, fp, filename): rawmode = ims.mode if ims.mode not in _VALID_WEBP_MODES: alpha = 'A' in ims.mode or 'a' in ims.mode \ - or (ims.mode == 'P' and 'A' in ims.im.getpalettemode()) + or (ims.mode == 'P' and + 'A' in ims.im.getpalettemode()) rawmode = 'RGBA' if alpha else 'RGB' frame = ims.convert(rawmode)