<legend id='cZadX'><style id='cZadX'><dir id='cZadX'><q id='cZadX'></q></dir></style></legend>

        <bdo id='cZadX'></bdo><ul id='cZadX'></ul>

    1. <small id='cZadX'></small><noframes id='cZadX'>

    2. <i id='cZadX'><tr id='cZadX'><dt id='cZadX'><q id='cZadX'><span id='cZadX'><b id='cZadX'><form id='cZadX'><ins id='cZadX'></ins><ul id='cZadX'></ul><sub id='cZadX'></sub></form><legend id='cZadX'></legend><bdo id='cZadX'><pre id='cZadX'><center id='cZadX'></center></pre></bdo></b><th id='cZadX'></th></span></q></dt></tr></i><div id='cZadX'><tfoot id='cZadX'></tfoot><dl id='cZadX'><fieldset id='cZadX'></fieldset></dl></div>
    3. <tfoot id='cZadX'></tfoot>

      PIL图像对象上的Python副本

      时间:2023-08-31
      <i id='IMVGX'><tr id='IMVGX'><dt id='IMVGX'><q id='IMVGX'><span id='IMVGX'><b id='IMVGX'><form id='IMVGX'><ins id='IMVGX'></ins><ul id='IMVGX'></ul><sub id='IMVGX'></sub></form><legend id='IMVGX'></legend><bdo id='IMVGX'><pre id='IMVGX'><center id='IMVGX'></center></pre></bdo></b><th id='IMVGX'></th></span></q></dt></tr></i><div id='IMVGX'><tfoot id='IMVGX'></tfoot><dl id='IMVGX'><fieldset id='IMVGX'></fieldset></dl></div>

          <tfoot id='IMVGX'></tfoot>
        • <legend id='IMVGX'><style id='IMVGX'><dir id='IMVGX'><q id='IMVGX'></q></dir></style></legend>
            <tbody id='IMVGX'></tbody>

            <small id='IMVGX'></small><noframes id='IMVGX'>

              • <bdo id='IMVGX'></bdo><ul id='IMVGX'></ul>
                本文介绍了PIL图像对象上的Python副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试创建一组缩略图,每个缩略图都是从原始图像单独缩小的.

                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)
                

                上面的代码似乎可以正常工作,但是在测试时我发现一些图像(我不知道它们有什么特别之处,可能只适用于 PNG)会引发此错误:

                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' 
                

                没有 copy() 这些图像就可以正常工作.

                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.

                推荐答案

                我猜 copy.copy() 不适用于 PIL Image 类.尝试使用 Image.copy() 代替,因为它的存在是有原因的:

                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)
                

                这篇关于PIL图像对象上的Python副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:当 cp 没有时,为什么 shutil.copy() 会引发权限异常? 下一篇:在Python中将excel工作表从一个工作表复制到另一个工作表

                相关文章

                <i id='KBWv2'><tr id='KBWv2'><dt id='KBWv2'><q id='KBWv2'><span id='KBWv2'><b id='KBWv2'><form id='KBWv2'><ins id='KBWv2'></ins><ul id='KBWv2'></ul><sub id='KBWv2'></sub></form><legend id='KBWv2'></legend><bdo id='KBWv2'><pre id='KBWv2'><center id='KBWv2'></center></pre></bdo></b><th id='KBWv2'></th></span></q></dt></tr></i><div id='KBWv2'><tfoot id='KBWv2'></tfoot><dl id='KBWv2'><fieldset id='KBWv2'></fieldset></dl></div>
                1. <tfoot id='KBWv2'></tfoot>

                  <legend id='KBWv2'><style id='KBWv2'><dir id='KBWv2'><q id='KBWv2'></q></dir></style></legend>
                      <bdo id='KBWv2'></bdo><ul id='KBWv2'></ul>
                  1. <small id='KBWv2'></small><noframes id='KBWv2'>