在Python中,给予全尺寸图片的目录,我怎么能产生使用多个CPU核心缩略图?

StackOverflow https://stackoverflow.com/questions/4066606

我有一个16芯机,但我的当前尺寸调整函数只使用一个核心,其是用于大型目录图像的真低效的。

def generateThumbnail(self, width, height):
     """
     Generates thumbnails for an image
     """
     im = Image.open(self._file)
     (detected_width,detected_height) = im.size

     #Get cropped box area
     bbox = self.getCropArea(detected_width, detected_height, width, height)

     #Crop to box area
     cropped_image = im.crop(bbox)

     #Resize to thumbnail
     cropped_image.thumbnail((width, height), Image.ANTIALIAS)

     #Save image
     cropped_image.save(self._path + str(width) + 'x' +
             str(height) + '-' + self._filename, "JPEG")

任何帮助,将不胜感激。谢谢你。

有帮助吗?

解决方案

这听起来像获取模块很好地解决,它使用螺纹接口,而造成单独的过程,而不是线程。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top