<commit_before>#!/usr/local/bin/python

import os
import sys
import glob
import time
import datetime
import csv
import exifread
import Image
from operator import itemgetter
from fractions import Fraction

thumbnail_size = 200
Generated = "thumbnails"

try:
    # using join to get target-directory with a trailing slash.
    input_dir = os.path.join(sys.argv[1],"")
    if not os.path.isdir(input_dir):
        print "target directory is not exists or not directory.\n"
        raise Exception()
except:
    print "Initpics make thumbnails and gather properties of pictures in target directory."
    print "usage : python pripics.py <target directory>"
    sys.exit()
print "target directory is %s" % input_dir

# make name of thumbnails directory
dir = os.path.join(Generated,input_dir)

# make thumbnails directory
if not os.path.isdir(dir):
    try:
        os.makedirs(dir)
    except:
        print "Can't make thumbnails direcotry."
        sys.exit()
print "thumbnails directory is %s" % dir


print "Making thumbnails and gathering properties of pictures."
csvdata = []

# read file name
for i, infile in enumerate(glob.glob(input_dir+'*.jpg')):

    # getmtime
    unixfiledate = os.path.getmtime(infile)
    filedate = time.strftime('%Y:%m:%d %X',time.localtime(unixfiledate))

    # convert thumbnail
    if not os.path.isfile(dir+"_thumb_"+os.path.basename(infile)):
        print i+1,": making a thumbnail."
        # read image
        image = Image.open(infile)
        image.thumbnail((thumbnail_size,thumbnail_size), Image.ANTIALIAS)

        # save filtered image
        image.save(dir+"_thumb_"+os.path.basename(infile))
    else:
        print i+1,": a thumbnail exists."
        image = Image.open(dir+"_thumb_"+os.path.basename(infile))


    width, height = image.size


    # file open
    fp = open(infile)
    exif = exifread.process_file(fp)<commit_msg>Modify thumbnail size<commit_after>#!/usr/local/bin/python

import os
import sys
import glob
import time
import datetime
import csv
import exifread
import Image
import ConfigParser
from operator import itemgetter
from fractions import Fraction

# load config
Config_file = "config.ini"
conf = ConfigParser.SafeConfigParser()
conf.read(Config_file)
ImageHeight = int(conf.get('options','ImageHeight'))
Generated = conf.get('options','Generated')
ImageQuality = int(conf.get('options','ImageQuality'))

try:
    # using join to get target-directory with a trailing slash.
    input_dir = os.path.join(sys.argv[1],"")
    if not os.path.isdir(input_dir):
        print "target directory is not exists or not directory.\n"
        raise Exception()
except:
    print "Initpics make thumbnails and gather properties of pictures in target directory."
    print "usage : python pripics.py <target directory>"
    sys.exit()
print "target directory is %s" % input_dir

# make name of thumbnails directory
dir = os.path.join(Generated,input_dir)

# make thumbnails directory
if not os.path.isdir(dir):
    try:
        os.makedirs(dir)
    except:
        print "Can't make thumbnails direcotry."
        sys.exit()
print "thumbnails directory is %s" % dir


print "Making thumbnails and gathering properties of pictures."
csvdata = []

# read file name
for i, infile in enumerate(glob.glob(input_dir+'*.jpg')):

    # getmtime
    unixfiledate = os.path.getmtime(infile)
    filedate = time.strftime('%Y:%m:%d %X',time.localtime(unixfiledate))

    # convert thumbnail
    if not os.path.isfile(dir+"_thumb_"+os.path.basename(infile)):
        print i+1,": making a thumbnail."
        # read image
        image = Image.open(infile)
        hpercent = (ImageHeight/float(image.size[1]))
        print "hpercent is %s" % hpercent
        wsize = int((float(image.size[0])*float(hpercent)))
        print "wsize is %s" % wsize
        image = image.resize((wsize,ImageHeight), Image.ANTIALIAS)
#        image.thumbnail((thumbnail_size,thumbnail_size), Image.ANTIALIAS)

        # save filtered image
        image.save(dir+"_thumb_"+os.path.basename(infile),quality=ImageQuality,optimize=True,progressive=True)
    else:
        print i+1,": a thumbnail exists."
        image = Image.open(dir+"_thumb_"+os.path.basename(infile))


    width, height = image.size
    print "width, height = %s, %s" % (width,height)


    # file open
    fp = open(infile)
    exif = exifread.process_file(fp)
{'fraction_non_alphanumeric': 0.11414164565665827, 'fraction_numerical': 0.0025212010084804033, 'mean_word_length': 3.522279792746114, 'pattern_counts': {'":': 4, '<': 5, '<?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': '5466383', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1375, 'n_words': 373}