في Python ، بالنظر إلى دليل من الصور بالحجم الكامل ، كيف يمكنني إنشاء صور مصغرة باستخدام أكثر من CPU Core؟

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