Example #1
0
def save_image(file, owner):
    error = None
    ext = os.path.splitext(file.filename)[1]

    image = model.Image(datetime.datetime.now(), owner.id)
    
    filename = image.uuid+ext

    if (ext==''):
        error = "No extension is set"
        return error, filename, ""
    
    image = model.Image(datetime.datetime.now(), owner.id)
    
    filename = image.uuid+ext
    image.uuid = filename

    fpath = os.path.join(config.upload_dir, filename)
    file.save(fpath)
    print fpath
    
    im = Image(fpath.encode("utf8"))
    im.quality(100)
    im.filterType(FilterTypes.SincFilter)
    im.scale('50x50')
    im.sharpen(1.0)
    thumb_path = os.path.join(config.upload_dir, "thumb_"+filename)
    # im.write(thumb_path.encode("utf8"))
    im.write(str(thumb_path.decode("utf8")))
    
    print file.filename

    model.session.add(image)
    model.session.commit()
    return error, filename, config.upload_dir
Example #2
0
         im = im.resize(
             (size[0] / SCALE_DOWN, size[1] / SCALE_DOWN),
             Image.BICUBIC)
     if QUALITY is not None:
         kwargs = {'quality': QUALITY}
     else:
         kwargs = {}
     im.save(os.path.join(path, output),
             **kwargs)  # 'JPEG' as second param to force JPEG
 elif TOOL == 'PM':
     im = Image()
     im.read(os.path.join(path, name))
     if QUALITY is not None:
         im.quality(QUALITY)
     try:
         im.write(os.path.join(path, output))
     except Exception, e:
         print "ERROR:", str(e)
 elif TOOL == 'OJ':  # OpenJPEG
     curr_command = COMMAND + '-i %s -o %s' % (input_filename,
                                               output_filename)
     print '    ' + curr_command
     process = subprocess.Popen(
         curr_command,
         shell=True,
         stdout=subprocess.PIPE,
     ).communicate()
 elif TOOL == 'VIEW':
     if random.random() > CHANCE: continue
     # Let the user view the two existing files
     print "Original:", name
                if SCALE_DOWN is not None:
                    size = im.size
                    im = im.resize((size[0]/SCALE_DOWN, size[1]/SCALE_DOWN), Image.BICUBIC)
                if QUALITY is not None:
                    kwargs = {'quality': QUALITY}
                else:
                    kwargs = {}
                im.save(os.path.join(path, output), **kwargs) # 'JPEG' as second param to force JPEG
            elif TOOL == 'PM':
                im = Image()
                im.read(os.path.join(path, name))
                if QUALITY is not None:
                    im.quality(QUALITY)
                try:
                    im.write(os.path.join(path, output))
                except Exception, e:
                    print "ERROR:", str(e)
            elif TOOL == 'OJ': # OpenJPEG
                curr_command = COMMAND + '-i %s -o %s' % (input_filename, output_filename)
                print '    ' + curr_command
                process = subprocess.Popen(
                    curr_command,
                    shell=True,
                    stdout=subprocess.PIPE,
                ).communicate()
            elif TOOL == 'VIEW':
                if random.random() > CHANCE: continue
                # Let the user view the two existing files
                print "Original:", name
                process1 = subprocess.Popen(