Pythonでは、フルサイズの画像のディレクトリが与えられた場合、複数のCPUコアを使用してサムネイルを生成するにはどうすればよいですか?

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

質問

私は16コアマシンを持っていますが、現在のサイズ変更関数は1つのコアのみを使用しています。これは、画像の大きなディレクトリに対しては本当に非効率的です。

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