<commit_before>import logging
from PIL import Image, ImageOps
from math import ceil

logger = logging.getLogger('katana.resizer')


def resize(src, dst, width=0, height=0, fit=True, quality=75):
    try:
        img = Image.open(src)
    except IOError as e:
        logger.error('resize %s: (%dx%d) corrupt image [%s]', src, width, height, e)
        return False

    origin_width, origin_height = img.size
    if origin_height == origin_width == 0:
        return False

    if not width:
        width = int(ceil(origin_width / (float(origin_height) / height)))
    if not height:
        height = int(ceil(origin_height / (float(origin_width) / width)))

    logger.debug('resize %s: (%dx%d) => (%dx%d) mode=%s quality=%d', src, origin_width, origin_height, width, height, 'fit' if fit else 'fill', quality)

    if fit:
        img = ImageOps.fit(img, (width, height), Image.ANTIALIAS)
    else:
        img = img.copy()
        img.thumbnail((width, height), Image.ANTIALIAS)
    try:
        if img.mode != "RGB":
            img = img.convert("RGB")
        img.save(dst, quality=quality)
    except IOError as e:
        logger.error('error saving %s to %s: %s', src, dst, e)
        return False
    return True<commit_msg>allow to convert without resizing<commit_after>import logging
from PIL import Image, ImageOps
from math import ceil

logger = logging.getLogger('katana.resizer')


def resize(src, dst, width=0, height=0, fit=True, quality=75):
    try:
        img = Image.open(src)
    except IOError as e:
        logger.error('resize %s: (%dx%d) corrupt image [%s]', src, width, height, e)
        return False

    origin_width, origin_height = img.size
    if origin_height == origin_width == 0:
        return False

    if not width:
        width = int(ceil(origin_width / (float(origin_height) / height)))
    if not height:
        height = int(ceil(origin_height / (float(origin_width) / width)))

    logger.debug('resize %s: (%dx%d) => (%dx%d) mode=%s quality=%d', src, origin_width, origin_height, width, height, 'fit' if fit else 'fill', quality)

    if width != 0 and height != 0:
        if fit:
            img = ImageOps.fit(img, (width, height), Image.ANTIALIAS)
        else:
            img = img.copy()
            img.thumbnail((width, height), Image.ANTIALIAS)
    try:
        if img.mode != "RGB":
            img = img.convert("RGB")
        img.save(dst, quality=quality)
    except IOError as e:
        logger.error('error saving %s to %s: %s', src, dst, e)
        return False
    return True
{'fraction_non_alphanumeric': 0.13252064490758947, 'fraction_numerical': 0.0047188360204482895, 'mean_word_length': 2.73568281938326, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '3346156', 'n_tokens_mistral': 825, 'n_tokens_neox': 800, 'n_words': 243}