<commit_before>import os
from PIL import Image

from django.conf import settings
from django.core.files.storage import default_storage
from django.template import Library

register = Library()

def _thumbnail(file, x, y):

    miniature = os.path.join(settings.THUMBNAIL_PATH, file.name)

    filename = file.path
    miniature_filename = default_storage.path(miniature)
    miniature_url = default_storage.url(miniature)

    # see if the full size image is newer than the thumbnail
    if os.path.exists(miniature_filename) and \
            os.path.getmtime(filename) > os.path.getmtime(miniature_filename):
        default_storage.delete(miniature)

    # if the image wasn't already resized, resize it
    if not default_storage.exists(miniature): 

        # make sure the directories exist
        os.makedirs(os.path.dirname(miniature_filename))

        image = Image.open(filename)
        image.thumbnail([x, y], Image.ANTIALIAS)
        try:
            image.save(miniature_filename, image.format, quality=90, optimize=1)
        except:
            image.save(miniature_filename, image.format, quality=90)

    return miniature_url

@register.filter
def thumbnail(file, size='104x104'):

    # defining the size
    x, y = [int(x) for x in size.split('x')]

    return _thumbnail(file, x, y)

@register.filter
def scale(file, max_side=200):

    try:
        max_side = float(max_side)

        # calculate the size
        x, y = file.width, file.height

        if x > y:
            # horizontal orientation
            y = int((max_side/x) * y)
            x = int(max_side)
        else:
            # vertical orientation
            x = int((max_side/y) * x)<commit_msg>Default image scaling to max_side == 150.<commit_after>import os
from PIL import Image

from django.conf import settings
from django.core.files.storage import default_storage
from django.template import Library

register = Library()

def _thumbnail(file, x, y):

    miniature = os.path.join(settings.THUMBNAIL_PATH, file.name)

    filename = file.path
    miniature_filename = default_storage.path(miniature)
    miniature_url = default_storage.url(miniature)

    # see if the full size image is newer than the thumbnail
    if os.path.exists(miniature_filename) and \
            os.path.getmtime(filename) > os.path.getmtime(miniature_filename):
        default_storage.delete(miniature)

    # if the image wasn't already resized, resize it
    if not default_storage.exists(miniature): 

        # make sure the directories exist
        os.makedirs(os.path.dirname(miniature_filename))

        image = Image.open(filename)
        image.thumbnail([x, y], Image.ANTIALIAS)
        try:
            image.save(miniature_filename, image.format, quality=90, optimize=1)
        except:
            image.save(miniature_filename, image.format, quality=90)

    return miniature_url

@register.filter
def thumbnail(file, size='104x104'):

    # defining the size
    x, y = [int(x) for x in size.split('x')]

    return _thumbnail(file, x, y)

@register.filter
def scale(file, max_side=150):

    try:
        max_side = float(max_side)

        # calculate the size
        x, y = file.width, file.height

        if x > y:
            # horizontal orientation
            y = int((max_side/x) * y)
            x = int(max_side)
        else:
            # vertical orientation
            x = int((max_side/y) * x)
{'fraction_non_alphanumeric': 0.09589442815249268, 'fraction_numerical': 0.00909090909090909, 'mean_word_length': 2.7237991266375547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1362560', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1019, 'n_words': 266}