mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Further health fixes
This commit is contained in:
parent
b33642c361
commit
ee34d6843b
|
@ -288,7 +288,7 @@ class EpsImageFile(ImageFile.ImageFile):
|
|||
|
||||
if s[:11] == "%ImageData:":
|
||||
# Encoded bitmapped image.
|
||||
[x, y, bi, mo, z3, z4, en, id] = s[11:].split(None, 7)
|
||||
x, y, bi, mo = s[11:].split(None, 7)[:4]
|
||||
|
||||
if int(bi) != 8:
|
||||
break
|
||||
|
|
|
@ -39,8 +39,8 @@ class GbrImageFile(ImageFile.ImageFile):
|
|||
|
||||
width = i32(self.fp.read(4))
|
||||
height = i32(self.fp.read(4))
|
||||
bytes = i32(self.fp.read(4))
|
||||
if width <= 0 or height <= 0 or bytes != 1:
|
||||
color_depth = i32(self.fp.read(4))
|
||||
if width <= 0 or height <= 0 or color_depth != 1:
|
||||
raise SyntaxError("not a GIMP brush")
|
||||
|
||||
comment = self.fp.read(header_size - 20)[:-1]
|
||||
|
|
|
@ -94,7 +94,7 @@ def read_32(fobj, start_length, size):
|
|||
|
||||
def read_mk(fobj, start_length, size):
|
||||
# Alpha masks seem to be uncompressed
|
||||
(start, length) = start_length
|
||||
start = start_length[0]
|
||||
fobj.seek(start)
|
||||
pixel_size = (size[0] * size[2], size[1] * size[2])
|
||||
sizesq = pixel_size[0] * pixel_size[1]
|
||||
|
|
|
@ -322,6 +322,7 @@ class Parser:
|
|||
image = None
|
||||
data = None
|
||||
decoder = None
|
||||
offset = 0
|
||||
finished = 0
|
||||
|
||||
def reset(self):
|
||||
|
|
|
@ -454,13 +454,13 @@ def _getmp(self):
|
|||
data = self.info["mp"]
|
||||
except KeyError:
|
||||
return None
|
||||
file = io.BytesIO(data)
|
||||
head = file.read(8)
|
||||
file_contents = io.BytesIO(data)
|
||||
head = file_contents.read(8)
|
||||
endianness = '>' if head[:4] == b'\x4d\x4d\x00\x2a' else '<'
|
||||
mp = {}
|
||||
# process dictionary
|
||||
info = TiffImagePlugin.ImageFileDirectory(head)
|
||||
info.load(file)
|
||||
info.load(file_contents)
|
||||
for key, value in info.items():
|
||||
mp[key] = _fixup(value)
|
||||
# it's an error not to have a number of images
|
||||
|
|
|
@ -54,9 +54,9 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
|
|||
# best way to identify MIC files, but what the... ;-)
|
||||
|
||||
self.images = []
|
||||
for file in self.ole.listdir():
|
||||
if file[1:] and file[0][-4:] == ".ACI" and file[1] == "Image":
|
||||
self.images.append(file)
|
||||
for path in self.ole.listdir():
|
||||
if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image":
|
||||
self.images.append(path)
|
||||
|
||||
# if we didn't find any images, this is probably not
|
||||
# an MIC file.
|
||||
|
|
|
@ -194,7 +194,7 @@ class _PyAccessI16_L(PyAccess):
|
|||
pixel = self.pixels[y][x]
|
||||
try:
|
||||
color = min(color, 65535)
|
||||
except:
|
||||
except TypeError:
|
||||
color = min(color[0], 65535)
|
||||
|
||||
pixel.l = color & 0xFF
|
||||
|
|
|
@ -48,7 +48,7 @@ def isInt(f):
|
|||
return 1
|
||||
else:
|
||||
return 0
|
||||
except:
|
||||
except ValueError:
|
||||
return 0
|
||||
|
||||
iforms = [1, 3, -11, -12, -21, -22]
|
||||
|
@ -173,11 +173,11 @@ class SpiderImageFile(ImageFile.ImageFile):
|
|||
|
||||
# returns a byte image after rescaling to 0..255
|
||||
def convert2byte(self, depth=255):
|
||||
(min, max) = self.getextrema()
|
||||
(minimum, maximum) = self.getextrema()
|
||||
m = 1
|
||||
if max != min:
|
||||
m = depth / (max-min)
|
||||
b = -m * min
|
||||
if maximum != minimum:
|
||||
m = depth / (maximum-minimum)
|
||||
b = -m * minimum
|
||||
return self.point(lambda i, m=m, b=b: i * m + b).convert("L")
|
||||
|
||||
# returns a ImageTk.PhotoImage object, after rescaling to 0..255
|
||||
|
@ -271,7 +271,7 @@ def _save(im, fp, filename):
|
|||
|
||||
def _save_spider(im, fp, filename):
|
||||
# get the filename extension and register it with Image
|
||||
fn, ext = os.path.splitext(filename)
|
||||
ext = os.path.splitext(filename)[1]
|
||||
Image.register_extension("SPIDER", ext)
|
||||
_save(im, fp, filename)
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
#
|
||||
|
||||
try:
|
||||
from tkinter import *
|
||||
from tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL
|
||||
except ImportError:
|
||||
from Tkinter import *
|
||||
from Tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL
|
||||
|
||||
from PIL import Image, ImageTk, ImageEnhance
|
||||
import sys
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#
|
||||
|
||||
try:
|
||||
from tkinter import *
|
||||
from tkinter import Tk, Canvas, NW
|
||||
except ImportError:
|
||||
from Tkinter import *
|
||||
from Tkinter import Tk, Canvas, NW
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
import sys
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
from __future__ import print_function
|
||||
|
||||
try:
|
||||
from tkinter import *
|
||||
from tkinter import Tk, Label
|
||||
except ImportError:
|
||||
from Tkinter import *
|
||||
from Tkinter import Tk, Label
|
||||
|
||||
from PIL import Image, ImageTk
|
||||
|
||||
|
|
|
@ -169,6 +169,7 @@ post patch:
|
|||
test_output = BytesIO()
|
||||
im.save(test_output, "JPEG", exif=exif)
|
||||
|
||||
def test_base_save(self):
|
||||
"""
|
||||
base case:
|
||||
MB
|
||||
|
@ -195,8 +196,6 @@ base case:
|
|||
0 +----------------------------------------------------------------------->Gi
|
||||
0 7.882
|
||||
"""
|
||||
|
||||
def test_base_save(self):
|
||||
im = hopper('RGB')
|
||||
|
||||
for _ in range(iterations):
|
||||
|
|
|
@ -58,10 +58,10 @@ class TestBmpReference(PillowTestCase):
|
|||
}
|
||||
|
||||
def get_compare(f):
|
||||
(head, name) = os.path.split(f)
|
||||
name = os.path.split(f)[1]
|
||||
if name in file_map:
|
||||
return os.path.join(base, 'html', file_map[name])
|
||||
(name, ext) = os.path.splitext(name)
|
||||
name = os.path.splitext(name)[0]
|
||||
return os.path.join(base, 'html', "%s.png" % name)
|
||||
|
||||
for f in self.get_files('g'):
|
||||
|
|
|
@ -5,14 +5,14 @@ from PIL import Image
|
|||
# sample ppm stream
|
||||
# created as an export of a palette image from Gimp2.6
|
||||
# save as...-> hopper.fli, default options.
|
||||
file = "Tests/images/hopper.fli"
|
||||
data = open(file, "rb").read()
|
||||
test_file = "Tests/images/hopper.fli"
|
||||
data = open(test_file, "rb").read()
|
||||
|
||||
|
||||
class TestFileFli(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
im = Image.open(file)
|
||||
im = Image.open(test_file)
|
||||
im.load()
|
||||
self.assertEqual(im.mode, "P")
|
||||
self.assertEqual(im.size, (128, 128))
|
||||
|
|
|
@ -36,9 +36,9 @@ class TestFileGif(PillowTestCase):
|
|||
|
||||
def test_bilevel(optimize):
|
||||
im = Image.new("1", (1, 1), 0)
|
||||
file = BytesIO()
|
||||
im.save(file, "GIF", optimize=optimize)
|
||||
return len(file.getvalue())
|
||||
test_file = BytesIO()
|
||||
im.save(test_file, "GIF", optimize=optimize)
|
||||
return len(test_file.getvalue())
|
||||
|
||||
self.assertEqual(test_grayscale(0), 800)
|
||||
self.assertEqual(test_grayscale(1), 38)
|
||||
|
@ -49,8 +49,8 @@ class TestFileGif(PillowTestCase):
|
|||
from io import BytesIO
|
||||
|
||||
im = Image.frombytes("L", (16, 16), bytes(bytearray(range(256))))
|
||||
file = BytesIO()
|
||||
im.save(file, "GIF", optimize=True)
|
||||
test_file = BytesIO()
|
||||
im.save(test_file, "GIF", optimize=True)
|
||||
self.assertEqual(im.mode, "L")
|
||||
|
||||
def test_roundtrip(self):
|
||||
|
|
|
@ -5,8 +5,8 @@ from PIL import Image
|
|||
import sys
|
||||
|
||||
# sample icon file
|
||||
file = "Tests/images/pillow.icns"
|
||||
data = open(file, "rb").read()
|
||||
test_file = "Tests/images/pillow.icns"
|
||||
data = open(test_file, "rb").read()
|
||||
|
||||
enable_jpeg2k = hasattr(Image.core, 'jp2klib_version')
|
||||
|
||||
|
@ -16,7 +16,7 @@ class TestFileIcns(PillowTestCase):
|
|||
def test_sanity(self):
|
||||
# Loading this icon by default should result in the largest size
|
||||
# (512x512@2x) being loaded
|
||||
im = Image.open(file)
|
||||
im = Image.open(test_file)
|
||||
im.load()
|
||||
self.assertEqual(im.mode, "RGBA")
|
||||
self.assertEqual(im.size, (1024, 1024))
|
||||
|
@ -39,11 +39,11 @@ class TestFileIcns(PillowTestCase):
|
|||
def test_sizes(self):
|
||||
# Check that we can load all of the sizes, and that the final pixel
|
||||
# dimensions are as expected
|
||||
im = Image.open(file)
|
||||
im = Image.open(test_file)
|
||||
for w, h, r in im.info['sizes']:
|
||||
wr = w * r
|
||||
hr = h * r
|
||||
im2 = Image.open(file)
|
||||
im2 = Image.open(test_file)
|
||||
im2.size = (w, h, r)
|
||||
im2.load()
|
||||
self.assertEqual(im2.mode, 'RGBA')
|
||||
|
|
|
@ -23,10 +23,10 @@ class TestFileJpeg(PillowTestCase):
|
|||
def roundtrip(self, im, **options):
|
||||
out = BytesIO()
|
||||
im.save(out, "JPEG", **options)
|
||||
bytes = out.tell()
|
||||
test_bytes = out.tell()
|
||||
out.seek(0)
|
||||
im = Image.open(out)
|
||||
im.bytes = bytes # for testing only
|
||||
im.bytes = test_bytes # for testing only
|
||||
return im
|
||||
|
||||
def test_sanity(self):
|
||||
|
|
|
@ -22,10 +22,10 @@ class TestFileJpeg2k(PillowTestCase):
|
|||
def roundtrip(self, im, **options):
|
||||
out = BytesIO()
|
||||
im.save(out, "JPEG2000", **options)
|
||||
bytes = out.tell()
|
||||
test_bytes = out.tell()
|
||||
out.seek(0)
|
||||
im = Image.open(out)
|
||||
im.bytes = bytes # for testing only
|
||||
im.bytes = test_bytes # for testing only
|
||||
im.load()
|
||||
return im
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ class TestFileLibTiff(LibTiffTestCase):
|
|||
self._assert_noerr(im)
|
||||
|
||||
def test_g4_large(self):
|
||||
file = "Tests/images/pport_g4.tif"
|
||||
im = Image.open(file)
|
||||
test_file = "Tests/images/pport_g4.tif"
|
||||
im = Image.open(test_file)
|
||||
self._assert_noerr(im)
|
||||
|
||||
def test_g4_tiff_file(self):
|
||||
|
|
|
@ -18,8 +18,8 @@ class TestFileLibTiffSmall(LibTiffTestCase):
|
|||
def test_g4_hopper_file(self):
|
||||
"""Testing the open file load path"""
|
||||
|
||||
file = "Tests/images/hopper_g4.tif"
|
||||
with open(file, 'rb') as f:
|
||||
test_file = "Tests/images/hopper_g4.tif"
|
||||
with open(test_file, 'rb') as f:
|
||||
im = Image.open(f)
|
||||
|
||||
self.assertEqual(im.size, (128, 128))
|
||||
|
@ -28,9 +28,9 @@ class TestFileLibTiffSmall(LibTiffTestCase):
|
|||
def test_g4_hopper_bytesio(self):
|
||||
"""Testing the bytesio loading code path"""
|
||||
from io import BytesIO
|
||||
file = "Tests/images/hopper_g4.tif"
|
||||
test_file = "Tests/images/hopper_g4.tif"
|
||||
s = BytesIO()
|
||||
with open(file, 'rb') as f:
|
||||
with open(test_file, 'rb') as f:
|
||||
s.write(f.read())
|
||||
s.seek(0)
|
||||
im = Image.open(s)
|
||||
|
@ -41,8 +41,8 @@ class TestFileLibTiffSmall(LibTiffTestCase):
|
|||
def test_g4_hopper(self):
|
||||
"""The 128x128 lena image failed for some reason."""
|
||||
|
||||
file = "Tests/images/hopper_g4.tif"
|
||||
im = Image.open(file)
|
||||
test_file = "Tests/images/hopper_g4.tif"
|
||||
im = Image.open(test_file)
|
||||
|
||||
self.assertEqual(im.size, (128, 128))
|
||||
self._assert_noerr(im)
|
||||
|
|
|
@ -17,10 +17,10 @@ class TestFileMpo(PillowTestCase):
|
|||
# Note that for now, there is no MPO saving functionality
|
||||
out = BytesIO()
|
||||
im.save(out, "MPO", **options)
|
||||
bytes = out.tell()
|
||||
test_bytes = out.tell()
|
||||
out.seek(0)
|
||||
im = Image.open(out)
|
||||
im.bytes = bytes # for testing only
|
||||
im.bytes = test_bytes # for testing only
|
||||
return im
|
||||
|
||||
def test_sanity(self):
|
||||
|
|
|
@ -31,8 +31,8 @@ class TestFilePcx(PillowTestCase):
|
|||
def test_pil184(self):
|
||||
# Check reading of files where xmin/xmax is not zero.
|
||||
|
||||
file = "Tests/images/pil184.pcx"
|
||||
im = Image.open(file)
|
||||
test_file = "Tests/images/pil184.pcx"
|
||||
im = Image.open(test_file)
|
||||
|
||||
self.assertEqual(im.size, (447, 144))
|
||||
self.assertEqual(im.tile[0][1], (0, 0, 447, 144))
|
||||
|
|
|
@ -19,9 +19,9 @@ MAGIC = PngImagePlugin._MAGIC
|
|||
|
||||
|
||||
def chunk(cid, *data):
|
||||
file = BytesIO()
|
||||
PngImagePlugin.putchunk(*(file, cid) + data)
|
||||
return file.getvalue()
|
||||
test_file = BytesIO()
|
||||
PngImagePlugin.putchunk(*(test_file, cid) + data)
|
||||
return test_file.getvalue()
|
||||
|
||||
o32 = PngImagePlugin.o32
|
||||
|
||||
|
@ -56,37 +56,37 @@ class TestFilePng(PillowTestCase):
|
|||
self.assertRegexpMatches(
|
||||
Image.core.zlib_version, "\d+\.\d+\.\d+(\.\d+)?$")
|
||||
|
||||
file = self.tempfile("temp.png")
|
||||
test_file = self.tempfile("temp.png")
|
||||
|
||||
hopper("RGB").save(file)
|
||||
hopper("RGB").save(test_file)
|
||||
|
||||
im = Image.open(file)
|
||||
im = Image.open(test_file)
|
||||
im.load()
|
||||
self.assertEqual(im.mode, "RGB")
|
||||
self.assertEqual(im.size, (128, 128))
|
||||
self.assertEqual(im.format, "PNG")
|
||||
|
||||
hopper("1").save(file)
|
||||
im = Image.open(file)
|
||||
hopper("1").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
|
||||
hopper("L").save(file)
|
||||
im = Image.open(file)
|
||||
hopper("L").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
|
||||
hopper("P").save(file)
|
||||
im = Image.open(file)
|
||||
hopper("P").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
|
||||
hopper("RGB").save(file)
|
||||
im = Image.open(file)
|
||||
hopper("RGB").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
|
||||
hopper("I").save(file)
|
||||
im = Image.open(file)
|
||||
hopper("I").save(test_file)
|
||||
im = Image.open(test_file)
|
||||
|
||||
def test_broken(self):
|
||||
# Check reading of totally broken files. In this case, the test
|
||||
# file was checked into Subversion as a text file.
|
||||
|
||||
file = "Tests/images/broken.png"
|
||||
self.assertRaises(IOError, lambda: Image.open(file))
|
||||
test_file = "Tests/images/broken.png"
|
||||
self.assertRaises(IOError, lambda: Image.open(test_file))
|
||||
|
||||
def test_bad_text(self):
|
||||
# Make sure PIL can read malformed tEXt chunks (@PIL152)
|
||||
|
@ -167,16 +167,16 @@ class TestFilePng(PillowTestCase):
|
|||
|
||||
def test_interlace(self):
|
||||
|
||||
file = "Tests/images/pil123p.png"
|
||||
im = Image.open(file)
|
||||
test_file = "Tests/images/pil123p.png"
|
||||
im = Image.open(test_file)
|
||||
|
||||
self.assert_image(im, "P", (162, 150))
|
||||
self.assertTrue(im.info.get("interlace"))
|
||||
|
||||
im.load()
|
||||
|
||||
file = "Tests/images/pil123rgba.png"
|
||||
im = Image.open(file)
|
||||
test_file = "Tests/images/pil123rgba.png"
|
||||
im = Image.open(test_file)
|
||||
|
||||
self.assert_image(im, "RGBA", (162, 150))
|
||||
self.assertTrue(im.info.get("interlace"))
|
||||
|
@ -184,8 +184,8 @@ class TestFilePng(PillowTestCase):
|
|||
im.load()
|
||||
|
||||
def test_load_transparent_p(self):
|
||||
file = "Tests/images/pil123p.png"
|
||||
im = Image.open(file)
|
||||
test_file = "Tests/images/pil123p.png"
|
||||
im = Image.open(test_file)
|
||||
|
||||
self.assert_image(im, "P", (162, 150))
|
||||
im = im.convert("RGBA")
|
||||
|
@ -195,8 +195,8 @@ class TestFilePng(PillowTestCase):
|
|||
self.assertEqual(len(im.split()[3].getcolors()), 124)
|
||||
|
||||
def test_load_transparent_rgb(self):
|
||||
file = "Tests/images/rgb_trns.png"
|
||||
im = Image.open(file)
|
||||
test_file = "Tests/images/rgb_trns.png"
|
||||
im = Image.open(test_file)
|
||||
|
||||
self.assert_image(im, "RGB", (64, 64))
|
||||
im = im.convert("RGBA")
|
||||
|
@ -209,22 +209,22 @@ class TestFilePng(PillowTestCase):
|
|||
in_file = "Tests/images/pil123p.png"
|
||||
im = Image.open(in_file)
|
||||
|
||||
file = self.tempfile("temp.png")
|
||||
im.save(file)
|
||||
test_file = self.tempfile("temp.png")
|
||||
im.save(test_file)
|
||||
|
||||
def test_save_p_single_transparency(self):
|
||||
in_file = "Tests/images/p_trns_single.png"
|
||||
im = Image.open(in_file)
|
||||
|
||||
file = self.tempfile("temp.png")
|
||||
im.save(file)
|
||||
test_file = self.tempfile("temp.png")
|
||||
im.save(test_file)
|
||||
|
||||
def test_save_l_transparency(self):
|
||||
in_file = "Tests/images/l_trns.png"
|
||||
im = Image.open(in_file)
|
||||
|
||||
file = self.tempfile("temp.png")
|
||||
im.save(file)
|
||||
test_file = self.tempfile("temp.png")
|
||||
im.save(test_file)
|
||||
|
||||
# There are 559 transparent pixels.
|
||||
im = im.convert('RGBA')
|
||||
|
@ -234,8 +234,8 @@ class TestFilePng(PillowTestCase):
|
|||
in_file = "Tests/images/caption_6_33_22.png"
|
||||
im = Image.open(in_file)
|
||||
|
||||
file = self.tempfile("temp.png")
|
||||
im.save(file)
|
||||
test_file = self.tempfile("temp.png")
|
||||
im.save(test_file)
|
||||
|
||||
def test_load_verify(self):
|
||||
# Check open/load/verify exception (@PIL150)
|
||||
|
@ -329,8 +329,8 @@ class TestFilePng(PillowTestCase):
|
|||
# Check writing and reading of tRNS chunks for RGB images.
|
||||
# Independent file sample provided by Sebastian Spaeth.
|
||||
|
||||
file = "Tests/images/caption_6_33_22.png"
|
||||
im = Image.open(file)
|
||||
test_file = "Tests/images/caption_6_33_22.png"
|
||||
im = Image.open(test_file)
|
||||
self.assertEqual(im.info["transparency"], (248, 248, 248))
|
||||
|
||||
# check saving transparency by default
|
||||
|
|
|
@ -3,14 +3,14 @@ from helper import unittest, PillowTestCase
|
|||
from PIL import Image
|
||||
|
||||
# sample ppm stream
|
||||
file = "Tests/images/hopper.ppm"
|
||||
data = open(file, "rb").read()
|
||||
test_file = "Tests/images/hopper.ppm"
|
||||
data = open(test_file, "rb").read()
|
||||
|
||||
|
||||
class TestFilePpm(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
im = Image.open(file)
|
||||
im = Image.open(test_file)
|
||||
im.load()
|
||||
self.assertEqual(im.mode, "RGB")
|
||||
self.assertEqual(im.size, (128, 128))
|
||||
|
|
|
@ -3,14 +3,14 @@ from helper import unittest, PillowTestCase
|
|||
from PIL import Image
|
||||
|
||||
# sample ppm stream
|
||||
file = "Tests/images/hopper.psd"
|
||||
data = open(file, "rb").read()
|
||||
test_file = "Tests/images/hopper.psd"
|
||||
data = open(test_file, "rb").read()
|
||||
|
||||
|
||||
class TestImagePsd(PillowTestCase):
|
||||
|
||||
def test_sanity(self):
|
||||
im = Image.open(file)
|
||||
im = Image.open(test_file)
|
||||
im.load()
|
||||
self.assertEqual(im.mode, "RGB")
|
||||
self.assertEqual(im.size, (128, 128))
|
||||
|
|
|
@ -41,12 +41,12 @@ class TestFileWebpMetadata(PillowTestCase):
|
|||
image = Image.open(file_path)
|
||||
expected_exif = image.info['exif']
|
||||
|
||||
buffer = BytesIO()
|
||||
test_buffer = BytesIO()
|
||||
|
||||
image.save(buffer, "webp", exif=expected_exif)
|
||||
image.save(test_buffer, "webp", exif=expected_exif)
|
||||
|
||||
buffer.seek(0)
|
||||
webp_image = Image.open(buffer)
|
||||
test_buffer.seek(0)
|
||||
webp_image = Image.open(test_buffer)
|
||||
|
||||
webp_exif = webp_image.info.get('exif', None)
|
||||
self.assertTrue(webp_exif)
|
||||
|
@ -76,12 +76,12 @@ class TestFileWebpMetadata(PillowTestCase):
|
|||
image = Image.open(file_path)
|
||||
expected_icc_profile = image.info['icc_profile']
|
||||
|
||||
buffer = BytesIO()
|
||||
test_buffer = BytesIO()
|
||||
|
||||
image.save(buffer, "webp", icc_profile=expected_icc_profile)
|
||||
image.save(test_buffer, "webp", icc_profile=expected_icc_profile)
|
||||
|
||||
buffer.seek(0)
|
||||
webp_image = Image.open(buffer)
|
||||
test_buffer.seek(0)
|
||||
webp_image = Image.open(test_buffer)
|
||||
|
||||
webp_icc_profile = webp_image.info.get('icc_profile', None)
|
||||
|
||||
|
@ -98,12 +98,12 @@ class TestFileWebpMetadata(PillowTestCase):
|
|||
image = Image.open(file_path)
|
||||
self.assertTrue('exif' in image.info)
|
||||
|
||||
buffer = BytesIO()
|
||||
test_buffer = BytesIO()
|
||||
|
||||
image.save(buffer, "webp")
|
||||
image.save(test_buffer, "webp")
|
||||
|
||||
buffer.seek(0)
|
||||
webp_image = Image.open(buffer)
|
||||
test_buffer.seek(0)
|
||||
webp_image = Image.open(test_buffer)
|
||||
|
||||
self.assertFalse(webp_image._getexif())
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ class TestFontBdf(PillowTestCase):
|
|||
|
||||
def test_sanity(self):
|
||||
|
||||
file = open(filename, "rb")
|
||||
font = BdfFontFile.BdfFontFile(file)
|
||||
test_file = open(filename, "rb")
|
||||
font = BdfFontFile.BdfFontFile(test_file)
|
||||
|
||||
self.assertIsInstance(font, FontFile.FontFile)
|
||||
self.assertEqual(len([_f for _f in font.glyph if _f]), 190)
|
||||
|
|
|
@ -17,8 +17,8 @@ class TestFontPcf(PillowTestCase):
|
|||
self.skipTest("zlib support not available")
|
||||
|
||||
def save_font(self):
|
||||
file = open(fontname, "rb")
|
||||
font = PcfFontFile.PcfFontFile(file)
|
||||
test_file = open(fontname, "rb")
|
||||
font = PcfFontFile.PcfFontFile(test_file)
|
||||
self.assertIsInstance(font, FontFile.FontFile)
|
||||
self.assertEqual(len([_f for _f in font.glyph if _f]), 192)
|
||||
|
||||
|
|
|
@ -41,8 +41,8 @@ class TestImage(PillowTestCase):
|
|||
im.paste(0, (0, 0, 100, 100))
|
||||
self.assertFalse(im.readonly)
|
||||
|
||||
file = self.tempfile("temp.ppm")
|
||||
im._dump(file)
|
||||
test_file = self.tempfile("temp.ppm")
|
||||
im._dump(test_file)
|
||||
|
||||
def test_comparison_with_other_type(self):
|
||||
# Arrange
|
||||
|
|
|
@ -76,10 +76,10 @@ class TestImageFilter(PillowTestCase):
|
|||
# 0 1 2
|
||||
# 3 4 5
|
||||
# 6 7 8
|
||||
min = im.filter(ImageFilter.MinFilter).getpixel((1, 1))
|
||||
minimum = im.filter(ImageFilter.MinFilter).getpixel((1, 1))
|
||||
med = im.filter(ImageFilter.MedianFilter).getpixel((1, 1))
|
||||
max = im.filter(ImageFilter.MaxFilter).getpixel((1, 1))
|
||||
return min, med, max
|
||||
maximum = im.filter(ImageFilter.MaxFilter).getpixel((1, 1))
|
||||
return minimum, med, maximum
|
||||
|
||||
self.assertEqual(rankfilter("1"), (0, 4, 8))
|
||||
self.assertEqual(rankfilter("L"), (0, 4, 8))
|
||||
|
|
|
@ -45,13 +45,13 @@ class TestImageSplit(PillowTestCase):
|
|||
codecs = dir(Image.core)
|
||||
|
||||
if 'zip_encoder' in codecs:
|
||||
file = self.tempfile("temp.png")
|
||||
test_file = self.tempfile("temp.png")
|
||||
else:
|
||||
file = self.tempfile("temp.pcx")
|
||||
test_file = self.tempfile("temp.pcx")
|
||||
|
||||
def split_open(mode):
|
||||
hopper(mode).save(file)
|
||||
im = Image.open(file)
|
||||
hopper(mode).save(test_file)
|
||||
im = Image.open(test_file)
|
||||
return len(im.split())
|
||||
self.assertEqual(split_open("1"), 1)
|
||||
self.assertEqual(split_open("L"), 1)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from helper import unittest, PillowTestCase, hopper
|
||||
import helper
|
||||
from helper import unittest, PillowTestCase
|
||||
|
||||
from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180,
|
||||
ROTATE_270, TRANSPOSE)
|
||||
|
@ -7,8 +8,8 @@ from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180,
|
|||
class TestImageTranspose(PillowTestCase):
|
||||
|
||||
hopper = {
|
||||
'L': hopper('L').crop((0, 0, 121, 127)).copy(),
|
||||
'RGB': hopper('RGB').crop((0, 0, 121, 127)).copy(),
|
||||
'L': helper.hopper('L').crop((0, 0, 121, 127)).copy(),
|
||||
'RGB': helper.hopper('RGB').crop((0, 0, 121, 127)).copy(),
|
||||
}
|
||||
|
||||
def test_flip_left_right(self):
|
||||
|
|
|
@ -24,11 +24,11 @@ class TestImageFile(PillowTestCase):
|
|||
if format in ("MSP", "XBM"):
|
||||
im = im.convert("1")
|
||||
|
||||
file = BytesIO()
|
||||
test_file = BytesIO()
|
||||
|
||||
im.save(file, format)
|
||||
im.save(test_file, format)
|
||||
|
||||
data = file.getvalue()
|
||||
data = test_file.getvalue()
|
||||
|
||||
parser = ImageFile.Parser()
|
||||
parser.feed(data)
|
||||
|
|
|
@ -94,7 +94,8 @@ try:
|
|||
def _render(self, font):
|
||||
txt = "Hello World!"
|
||||
ttf = ImageFont.truetype(font, FONT_SIZE)
|
||||
w, h = ttf.getsize(txt)
|
||||
ttf.getsize(txt)
|
||||
|
||||
img = Image.new("RGB", (256, 64), "white")
|
||||
d = ImageDraw.Draw(img)
|
||||
d.text((10, 10), txt, font=ttf, fill='black')
|
||||
|
|
|
@ -17,11 +17,11 @@ class TestImagePalette(PillowTestCase):
|
|||
|
||||
palette = ImagePalette()
|
||||
|
||||
map = {}
|
||||
test_map = {}
|
||||
for i in range(256):
|
||||
map[palette.getcolor((i, i, i))] = i
|
||||
test_map[palette.getcolor((i, i, i))] = i
|
||||
|
||||
self.assertEqual(len(map), 256)
|
||||
self.assertEqual(len(test_map), 256)
|
||||
self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3)))
|
||||
|
||||
def test_file(self):
|
||||
|
|
|
@ -7,10 +7,10 @@ class TestImageSequence(PillowTestCase):
|
|||
|
||||
def test_sanity(self):
|
||||
|
||||
file = self.tempfile("temp.im")
|
||||
test_file = self.tempfile("temp.im")
|
||||
|
||||
im = hopper("RGB")
|
||||
im.save(file)
|
||||
im.save(test_file)
|
||||
|
||||
seq = ImageSequence.Iterator(im)
|
||||
|
||||
|
|
|
@ -100,8 +100,8 @@ class TestImageWinDib(PillowTestCase):
|
|||
|
||||
# Act
|
||||
# Make one the same as the using tobytes()/frombytes()
|
||||
buffer = dib1.tobytes()
|
||||
dib2.frombytes(buffer)
|
||||
test_buffer = dib1.tobytes()
|
||||
dib2.frombytes(test_buffer)
|
||||
|
||||
# Assert
|
||||
# Confirm they're the same
|
||||
|
@ -111,11 +111,11 @@ class TestImageWinDib(PillowTestCase):
|
|||
# Arrange
|
||||
im = hopper()
|
||||
dib = ImageWin.Dib(im)
|
||||
buffer = dib.tobytes()
|
||||
test_buffer = dib.tobytes()
|
||||
|
||||
# Act/Assert
|
||||
self.assert_warning(DeprecationWarning, dib.tostring)
|
||||
self.assert_warning(DeprecationWarning, lambda: dib.fromstring(buffer))
|
||||
self.assert_warning(DeprecationWarning, lambda: dib.fromstring(test_buffer))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -64,15 +64,15 @@ class TestModeI16(PillowTestCase):
|
|||
self.assertEqual(imIn.getpixel((0, 0)), 2)
|
||||
|
||||
if mode == "L":
|
||||
max = 255
|
||||
maximum = 255
|
||||
else:
|
||||
max = 32767
|
||||
maximum = 32767
|
||||
|
||||
imIn = Image.new(mode, (1, 1), 256)
|
||||
self.assertEqual(imIn.getpixel((0, 0)), min(256, max))
|
||||
self.assertEqual(imIn.getpixel((0, 0)), min(256, maximum))
|
||||
|
||||
imIn.putpixel((0, 0), 512)
|
||||
self.assertEqual(imIn.getpixel((0, 0)), min(512, max))
|
||||
self.assertEqual(imIn.getpixel((0, 0)), min(512, maximum))
|
||||
|
||||
basic("L")
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class TestPickle(PillowTestCase):
|
|||
import pickle
|
||||
|
||||
# Act / Assert
|
||||
for file in [
|
||||
for test_file in [
|
||||
"Tests/images/test-card.png",
|
||||
"Tests/images/zero_bb.png",
|
||||
"Tests/images/zero_bb_scale2.png",
|
||||
|
@ -69,7 +69,7 @@ class TestPickle(PillowTestCase):
|
|||
"Tests/images/p_trns_single.png",
|
||||
"Tests/images/pil123p.png"
|
||||
]:
|
||||
self.helper_pickle_string(pickle, file=file)
|
||||
self.helper_pickle_string(pickle, file=test_file)
|
||||
|
||||
def test_pickle_l_mode(self):
|
||||
# Arrange
|
||||
|
|
|
@ -6,10 +6,7 @@ import sys
|
|||
import threading
|
||||
import time
|
||||
|
||||
try:
|
||||
format = sys.argv[1]
|
||||
except:
|
||||
format = "PNG"
|
||||
test_format = sys.argv[1] if len(sys.argv) > 1 else "PNG"
|
||||
|
||||
im = Image.open("Tests/images/hopper.ppm")
|
||||
im.load()
|
||||
|
@ -28,7 +25,7 @@ class Worker(threading.Thread):
|
|||
sys.stdout.write("x")
|
||||
break
|
||||
f = io.BytesIO()
|
||||
im.save(f, format, optimize=1)
|
||||
im.save(f, test_format, optimize=1)
|
||||
data = f.getvalue()
|
||||
result.append(len(data))
|
||||
im = Image.open(io.BytesIO(data))
|
||||
|
|
Loading…
Reference in New Issue
Block a user