Problem Description
When using PIL to read an image and then resize it, a PIL version problem occurs. AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
The specific code is as follows
image = image.resize((scaled_width, scaled_height), Image.ANTIALIAS)
Cause Analysis
In the new version of pillow (after 10.0.0) Image.ANTIALIAS
it has been removed and replaced by Image.LANCZOS
or Image.Resampling.LANCZOS
. The relevant description can be found in the release notes of pillow .
More ways to be removed are as follows
Removed | Use instead |
---|---|
Image.LINEAR | Image.BILINEAR or Image.Resampling.BILINEAR |
Image.CUBIC | Image.BICUBIC or Image.Resampling.BICUBIC |
Image.ANTIALIAS | Image.LANCZOS or Image.Resampling.LANCZOS |
ImageCms.INTENT_PERCEPTUAL | ImageCms.Intent.PERCEPTUAL |
ImageCms.INTENT_RELATIVE_COLORMETRIC | ImageCms.Intent.RELATIVE_COLORMETRIC |
ImageCms.INTENT_SATURATION | ImageCms.Intent.SATURATION |
ImageCms.INTENT_ABSOLUTE_COLORIMETRIC | ImageCms.Intent.ABSOLUTE_COLORIMETRIC |
ImageCms.DIRECTION_INPUT | ImageCms.Direction.INPUT |
ImageCms.DIRECTION_OUTPUT | ImageCms.Direction.OUTPUT |
ImageCms.DIRECTION_PROOF | ImageCms.Direction.PROOF |
ImageFont.LAYOUT_BASIC | ImageFont.Layout.BASIC |
ImageFont.LAYOUT_RAQM | ImageFont.Layout.RAQM |
BlpImagePlugin.BLP_FORMAT_JPEG | BlpImagePlugin.Format.JPEG |
BlpImagePlugin.BLP_ENCODING_UNCOMPRESSED | BlpImagePlugin.Encoding.UNCOMPRESSED |
BlpImagePlugin.BLP_ENCODING_DXT | BlpImagePlugin.Encoding.DXT |
BlpImagePlugin.BLP_ENCODING_UNCOMPRESSED_RAW_RGBA | BlpImagePlugin.Encoding.UNCOMPRESSED_RAW_RGBA |
BlpImagePlugin.BLP_ALPHA_ENCODING_DXT1 | BlpImagePlugin.AlphaEncoding.DXT1 |
BlpImagePlugin.BLP_ALPHA_ENCODING_DXT3 | BlpImagePlugin.AlphaEncoding.DXT3 |
BlpImagePlugin.BLP_ALPHA_ENCODING_DXT5 | BlpImagePlugin.AlphaEncoding.DXT5 |
FtexImagePlugin.FORMAT_DXT1 | FtexImagePlugin.Format.DXT1 |
FtexImagePlugin.FORMAT_UNCOMPRESSED | FtexImagePlugin.Format.UNCOMPRESSED |
PngImagePlugin.APNG_DISPOSE_OP_NONE | PngImagePlugin.Disposal.OP_NONE |
PngImagePlugin.APNG_DISPOSE_OP_BACKGROUND | PngImagePlugin.Disposal.OP_BACKGROUND |
PngImagePlugin.APNG_DISPOSE_OP_PREVIOUS | PngImagePlugin.Disposal.OP_PREVIOUS |
PngImagePlugin.APNG_BLEND_OP_SOURCE | PngImagePlugin.Blend.OP_SOURCE |
PngImagePlugin.APNG_BLEND_OP_OVER | PngImagePlugin.Blend.OP_OVER |
Back to the question just now
solution
The solution to the problem just now is to Image.ANTIALIAS
replace with Image.LANCZOS
or Image.Resampling.LANCZOS
the modified code is as follows:
image = image.resize((scaled_width, scaled_height), Image.LANCZOS)
The above only records the following problems I encountered during the debugging process to facilitate subsequent modification of similar programs.