- IOError: cannot identify image file:表示路径对应的文件不是有效的图片
- ValueError: images do not match:表示图片大小和box对应的宽度不一致,参考API说明:Pastes another image into this image. The box argument is either a 2-tuple giving the upper left corner, a 4-tuple defining the left, upper, right, and lower pixel coordinate, or None (same as (0, 0)). If a 4-tuple is given, the size of the pasted image must match the size of the region.使用2纬的box避免上述问题
- IOError: image file is truncated (40 bytes not processed) :表示路径对应的图片文件已损坏,请确认
- IOError: Unsupported BMP header type (56):发现还是图片已损坏
The Python Imaging Library supports a wide variety of raster file formats. Nearly 30 different file formats can be identified and read by the library. Write support is less extensive, but most common interchange and presentation formats are supported.
The open function identifies files from their contents, not their names, but the save method looks at the name to determine which format to use, unless the format is given explicitly.
PIL根据文件内容而不是文件名后缀来读取图片,但是保存的时候可以指定某种格式(文件名后缀和格式不匹配也可以),如下
srcImg.save(targetFullFile)
srcImg.save(targetFullFile, 'jpeg')