I'm trying to create a set of thumbnails, each one separately downscaled from the original image.
image = Image.open(path) image = image.crop((left, upper, right, lower)) for size in sizes: temp = copy.copy(image) temp.thumbnail((size, height), Image.ANTIALIAS) temp.save('%s%s%s.%s' % (path, name, size, format), quality=95)
The above code seemed to work fine but while testing I discovered that some images (I can't tell what's special about them, maybe only for PNG) raise this error:
/usr/local/lib/python2.6/site-packages/PIL/PngImagePlugin.py in read(self=<PIL.PngImagePlugin.PngStream instance>) line: s = self.fp.read(8) <type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'read'
Without the copy()
these images work just fine.
I could just open and crop the image anew for every thumbnail, but I'd rather have a better solution.
Call the paste() method from the background image and set the image to paste. By default, the image is pasted at the position where the upper left of the paste image is the origin (upper left) of the base image.
To load the image, we simply import the image module from the pillow and call the Image. open(), passing the image filename. Instead of calling the Pillow module, we will call the PIL module as to make it backward compatible with an older module called Python Imaging Library (PIL).
fromarray - Function. 1.1.1 Construct a CASA image from a numerical (integer or float) array. This function converts a numerical (integer or float) numpy array of any size and dimensionality into a CASA image. It will create both float and complex valued images.
I guess copy.copy()
does not work for the PIL Image
class. Try using Image.copy()
instead, since it is there for a reason:
image = Image.open(path) image = image.crop((left, upper, right, lower)) for size in sizes: temp = image.copy() # <-- Instead of copy.copy(image) temp.thumbnail((size, height), Image.ANTIALIAS) temp.save('%s%s%s.%s' % (path, name, size, format), quality=95)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With