Exemple #1
0
def image_size(img_data, pure_python=False):
    try:
        if imgsize is not None:
            return imgsize.get_size(PeekableStringIO(img_data))
        if Image is not None and not pure_python:
            return Image.open(cStringIO.StringIO(img_data)).size
    except (ValueError, imgsize.UnknownSize):
        pass
    return None
Exemple #2
0
def image_size(img_data, pure_python=False):
    try:
        if imgsize is not None:
            return imgsize.get_size(PeekableStringIO(img_data))
        if Image is not None and not pure_python:
            return Image.open(cStringIO.StringIO(img_data)).size
    except (ValueError, imgsize.UnknownSize):
        pass
    return None
Exemple #3
0
def make_symbols_file(directory):
    '''Create the wonderdraft_symbols file here.

    We default the offset_x to 0 always. offset_y can be overwritten with the offset_y_map, and
    radius is always calculated as the minimum of 15% of the smallest image dimension OR 100.
    '''
    symbols_file_json = {}
    for filename in os.listdir(directory):
        offset_y = 0
        if filename.startswith('.'):
            continue

        # Calculate the radius
        with io.open('{}\\{}'.format(directory, filename), 'rb') as fobj:
            width, height = get_size(fobj)
            # TODO: make these arguments that get passed in.
            radius = min(min(width, height) * .15, 100)

        # Determine if we are going to overwrite the offset_y from the offset_y_map
        for offset_keyname, offset_y_value in offset_y_map.items():
            if offset_keyname.lower() in filename.lower():
                offset_y = offset_y_value * height

        key_name = filename.split('.')[0]  # Take out .png in the filename
        symbols_file_json[key_name] = {
            "name": key_name,
            "radius": int(radius),
            "offset_x": int(0),
            "offset_y": int(offset_y),
            "draw_mode": "normal"
        }

    # Write the dict to the file as json
    symbols_filename = '{}\\{}'.format(directory, '.wonderdraft_symbols')
    print('Writing file {}'.format(symbols_filename))
    with io.open(symbols_filename, 'w+') as f:
        f.write(json.dumps(symbols_file_json, indent=4))