<commit_before>import os

QUALITY = 95

def fix_filename(filename, suffix=''):
    """
    e.g.
        fix_filename('icon.png', '_40x40')
        
        return
    
            icon_40x40.png
    """
    if suffix:
        f, ext = os.path.splitext(filename)
        return f+suffix+ext
    else:
        return filename

def _image_save(img, filename, encoder, **kwargs):
    import PIL

    try:
        img.save(filename, encoder, **kwargs)
    except IOError:
        PIL.ImageFile.MAXBLOCK = img.size[0] * img.size[1]
        img.save(filename, encoder, **kwargs)

def resize_image(fobj, size=(50, 50), quality=None):
    from PIL import Image
    from StringIO import StringIO
    
    image = Image.open(fobj)
    if image.mode not in ('L', 'RGB'):
        image = image.convert('RGB')
    image = image.resize(size, Image.ANTIALIAS)
    o = StringIO()
    _image_save(image, o, "JPEG", quality=quality or QUALITY)<commit_msg>Fix image bug<commit_after>import os

QUALITY = 95

def fix_filename(filename, suffix=''):
    """
    e.g.
        fix_filename('icon.png', '_40x40')
        
        return
    
            icon_40x40.png
    """
    if suffix:
        f, ext = os.path.splitext(filename)
        return f+suffix+ext
    else:
        return filename

def _image_save(img, filename, encoder, **kwargs):
    import PIL

    try:
        img.save(filename, encoder, **kwargs)
    except IOError:
        PIL.ImageFile.MAXBLOCK = img.size[0] * img.size[1] * 4
        img.save(filename, encoder, **kwargs)

def resize_image(fobj, size=(50, 50), quality=None):
    from PIL import Image
    from StringIO import StringIO
    
    image = Image.open(fobj)
    if image.mode not in ('L', 'RGB'):
        image = image.convert('RGB')
    image = image.resize(size, Image.ANTIALIAS)
    o = StringIO()
    _image_save(image, o, "JPEG", quality=quality or QUALITY)
{'fraction_non_alphanumeric': 0.1263326226012793, 'fraction_numerical': 0.017590618336886993, 'mean_word_length': 2.4567219152854514, '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': '2604248', 'n_tokens_mistral': 658, 'n_tokens_neox': 621, 'n_words': 152}