<commit_before>from django.conf import settings
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile

import mimetypes
import email
import time
import datetime

from PIL import Image as PILImage
from PIL import ImageOps
from PIL import ImageEnhance
from PIL import ImageFont
from PIL import ImageDraw

import StringIO


def download_from_bucket(filename, path):
    import urllib2
    s3_path = '%s%s' % (settings.IMAGES_URL, filename)
    image = urllib2.urlopen(s3_path)
    output = open(path + filename, 'wb')
    output.write(image.read())
    output.flush()
    output.close()


def save_to_bucket(filename, content):
    default_storage.save('images/%s' % filename, ContentFile(content));


def watermark_image(image, text, position, opacity):
    watermark = PILImage.new('RGBA', (image.size[0], image.size[1]))
    draw = ImageDraw.Draw(watermark, 'RGBA')
    fontsize = 1
    ttf = 'sitestatic/fonts/arial.ttf'

    img_fraction = 0.33

    font = ImageFont.truetype(ttf, fontsize)
    while font.getsize(text)[0] < img_fraction*image.size[0]:
        # iterate until the text size is just larger than the criteria
        fontsize += 1
        font = ImageFont.truetype(ttf, fontsize)<commit_msg>Fixes path of arial font.<commit_after>from django.conf import settings
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile

import mimetypes
import email
import time
import datetime
import os.path

from PIL import Image as PILImage
from PIL import ImageOps
from PIL import ImageEnhance
from PIL import ImageFont
from PIL import ImageDraw

import StringIO


def download_from_bucket(filename, path):
    import urllib2
    s3_path = '%s%s' % (settings.IMAGES_URL, filename)
    image = urllib2.urlopen(s3_path)
    output = open(path + filename, 'wb')
    output.write(image.read())
    output.flush()
    output.close()


def save_to_bucket(filename, content):
    default_storage.save('images/%s' % filename, ContentFile(content));


def watermark_image(image, text, position, opacity):
    watermark = PILImage.new('RGBA', (image.size[0], image.size[1]))
    draw = ImageDraw.Draw(watermark, 'RGBA')
    fontsize = 1
    ttf = os.path.join(settings.STATIC_ROOT, 'fonts/arial.ttf')

    img_fraction = 0.33

    font = ImageFont.truetype(ttf, fontsize)
    while font.getsize(text)[0] < img_fraction*image.size[0]:
        # iterate until the text size is just larger than the criteria
        fontsize += 1
        font = ImageFont.truetype(ttf, fontsize)
{'fraction_non_alphanumeric': 0.10031225604996097, 'fraction_numerical': 0.01014832162373146, 'mean_word_length': 4.105577689243028, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1413728', 'n_tokens_mistral': 846, 'n_tokens_neox': 814, 'n_words': 222}