<commit_before>#-*- coding: utf-8 -*-
import os
import Image
from django.conf import settings

def get_thumbnail_filename(file, size, miniature_subdir, crop=False):
    filehead, filetail = os.path.split(file.path)
    basename, format = os.path.splitext(filetail)
    miniature = basename + '_' + size + ( 'c' if crop else '') + format
    filehead = os.path.join(filehead,miniature_subdir)
    miniature_filename = os.path.join(filehead, miniature)
    return (miniature,miniature_filename)

# modified snippet from djangosnippets.org
def create_thumbnail(file, size=settings.THUMBNAILS_SIZE, miniature_subdir=settings.THUMBNAILS_SUBDIR, crop=False):
    x, y = [int(x) for x in size.split('x')]
    miniature,miniature_filename = get_thumbnail_filename(file, size, miniature_subdir, crop)
    filehead, filetail = os.path.split(file.url)
    filehead = os.path.join(filehead,miniature_subdir)
    miniature_url = filehead + '/' + miniature
    if os.path.exists(miniature_filename) and os.path.getmtime(file.path)>os.path.getmtime(miniature_filename):
        os.unlink(miniature_filename)
    # if miniature subdir does ot exist, create it
    subdir, fn = os.path.split(file.path)
    p = os.path.join(subdir,miniature_subdir)
    if not os.path.exists(p):
        os.mkdir(p)
        i = open(os.path.join(p,"index.html"),"w")
        i.close()
    # if the image wasn't already resized, resize it
    if not os.path.exists(miniature_filename):
        image = Image.open(file.path)
        if crop:
			cx,cy = image.size
			s = min(cx/x,cy/y)
			nx,ny = s*x,s*y
			ox,oy = (cx-nx)/2,(cy-ny)/2
			box = (ox,oy,ox+nx,oy+ny)
			image = image.crop(box)
        image.thumbnail([x, y], Image.ANTIALIAS)
        try:<commit_msg>Changed get_miniature_filename to recive filepath instead of file<commit_after>#-*- coding: utf-8 -*-
import os
import Image
from django.conf import settings

def get_thumbnail_filename(filepath, size, miniature_subdir, crop=False):
    filehead, filetail = os.path.split(filepath)
    basename, format = os.path.splitext(filetail)
    miniature = basename + '_' + size + ( 'c' if crop else '') + format
    filehead = os.path.join(filehead,miniature_subdir)
    miniature_filename = os.path.join(filehead, miniature)
    return (miniature,miniature_filename)

# modified snippet from djangosnippets.org
def create_thumbnail(file, size=settings.THUMBNAILS_SIZE, miniature_subdir=settings.THUMBNAILS_SUBDIR, crop=False):
    x, y = [int(x) for x in size.split('x')]
    miniature,miniature_filename = get_thumbnail_filename(file.path, size, miniature_subdir, crop)
    filehead, filetail = os.path.split(file.url)
    filehead = os.path.join(filehead,miniature_subdir)
    miniature_url = filehead + '/' + miniature
    if os.path.exists(miniature_filename) and os.path.getmtime(file.path)>os.path.getmtime(miniature_filename):
        os.unlink(miniature_filename)
    # if miniature subdir does ot exist, create it
    subdir, fn = os.path.split(file.path)
    p = os.path.join(subdir,miniature_subdir)
    if not os.path.exists(p):
        os.mkdir(p)
        i = open(os.path.join(p,"index.html"),"w")
        i.close()
    # if the image wasn't already resized, resize it
    if not os.path.exists(miniature_filename):
        image = Image.open(file.path)
        if crop:
            cx,cy = image.size
            s = min(cx/x,cy/y)
            nx,ny = s*x,s*y
            ox,oy = (cx-nx)/2,(cy-ny)/2
            box = (ox,oy,ox+nx,oy+ny)
            image = image.crop(box)
        image.thumbnail([x, y], Image.ANTIALIAS)
        try:
{'fraction_non_alphanumeric': 0.1282194848824188, 'fraction_numerical': 0.0016797312430011197, 'mean_word_length': 3.4551122194513715, 'pattern_counts': {'":': 0, '<': 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': '690652', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1254, 'n_words': 250}