<commit_before>import logging
import traceback
import Image
import ImageOps
from pypes.component import Component

log = logging.getLogger(__name__)

DEFAULT_RESOLUTION = (128, 128)

class ImageThumbnail(Component):

    __metatype__ = 'TRANSFORMER'

    def __init__(self):
        Component.__init__(self)
        
        self.set_parameter('size', '(128, 128)')
        self.set_parameter('filter', 'ANTIALIAS', ['ANTIALIAS', 'NEAREST', 'BILINEAR', 'BICUBIC'])

        self.filter_dict = {
            'ANTIALIAS': Image.ANTIALIAS,
            'NEAREST': Image.NEAREST,
            'BILINEAR': Image.BILINEAR,
            'BICUBIC': Image.BICUBIC
        }

        log.info('Component Initialized: %s' % self.__class__.__name__)

    def run(self):
        while True:

            resolution = self.get_parameter('size')
            filter_type = self.get_parameter('filter')
            try:
                filter = self.filter_dict[filter_type]
            except:
                filter = Image.ANTIALIAS

            # for each document waiting on our input port
            for doc in self.receive_all('in'):
                try:
                    # grab the serialized image
                    raw_image = doc.get('image_data')

                    # grab the meta-data we need
                    size = doc.get_meta('size', 'image_data')
                    mode = doc.get_meta('mode', 'image_data')

                    # deserialize the image content
                    image = Image.fromstring(mode, size, raw_image)

                    # perform the cropping using our user defined border
                    try:
                        resolution = eval(size)
                    except:<commit_msg>Fixed bug that prevented using non-default thumbnail sizes.<commit_after>import logging
import traceback
import Image
import ImageOps
from pypes.component import Component

log = logging.getLogger(__name__)

DEFAULT_RESOLUTION = (128, 128)

class ImageThumbnail(Component):

    __metatype__ = 'TRANSFORMER'

    def __init__(self):
        Component.__init__(self)
        
        self.set_parameter('size', '(128, 128)')
        self.set_parameter('filter', 'ANTIALIAS', ['ANTIALIAS', 'NEAREST', 'BILINEAR', 'BICUBIC'])

        self.filter_dict = {
            'ANTIALIAS': Image.ANTIALIAS,
            'NEAREST': Image.NEAREST,
            'BILINEAR': Image.BILINEAR,
            'BICUBIC': Image.BICUBIC
        }

        log.info('Component Initialized: %s' % self.__class__.__name__)

    def run(self):
        while True:

            resolution = self.get_parameter('size')
            filter_type = self.get_parameter('filter')
            try:
                filter = self.filter_dict[filter_type]
            except:
                filter = Image.ANTIALIAS

            # for each document waiting on our input port
            for doc in self.receive_all('in'):
                try:
                    # grab the serialized image
                    raw_image = doc.get('image_data')

                    # grab the meta-data we need
                    size = doc.get_meta('size', 'image_data')
                    mode = doc.get_meta('mode', 'image_data')

                    # deserialize the image content
                    image = Image.fromstring(mode, size, raw_image)

                    # perform the cropping using our user defined border
                    try:
                        resolution = eval(resolution)
                    except:
{'fraction_non_alphanumeric': 0.0930365296803653, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 1.73828125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6979119', 'n_tokens_mistral': 1002, 'n_tokens_neox': 924, 'n_words': 226}