Exemple #1
0
def _create_char(userid, x1, y1, x2, y2, charid, config=None, remove=True):
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    filename = d.url_make(charid, "char/.thumb", root=True)
    if not m.os.path.exists(filename):
        filename = d.url_make(charid, "char/cover", root=True)
        if not filename:
            return
        remove = False

    im = image.read(filename)
    size = im.size.width, im.size.height

    d.execute(
        """
        UPDATE character
        SET settings = REGEXP_REPLACE(settings, '-.', '') || '-%s'
        WHERE charid = %i
    """, [image.image_setting(im), charid])
    dest = '%s%i.thumb%s' % (d.get_hash_path(
        charid, "char"), charid, images.image_extension(im))

    bounds = None
    if image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = images.make_thumbnail(im, bounds)
    thumb.write(dest, format=images.image_file_type(thumb))
    if remove:
        m.os.remove(filename)
Exemple #2
0
def create(userid,
           x1,
           y1,
           x2,
           y2,
           submitid=None,
           charid=None,
           config=None,
           remove=True):
    if charid:
        return _create_char(userid, x1, y1, x2, y2, charid, config, remove)

    db = d.connect()
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    source = thumbnail_source(submitid)
    im = db.query(orm.MediaItem).get(source['mediaid']).as_image()
    size = im.size.width, im.size.height
    bounds = None
    if image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = images.make_thumbnail(im, bounds)
    file_type = images.image_file_type(im)
    media_item = orm.fetch_or_create_media_item(
        thumb.to_buffer(format=file_type), file_type=file_type, im=thumb)
    orm.SubmissionMediaLink.make_or_replace_link(submitid, 'thumbnail-custom',
                                                 media_item)
Exemple #3
0
def _create_char(userid, x1, y1, x2, y2, charid, config=None, remove=True):
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    filename = d.url_make(charid, "char/.thumb", root=True)
    if not m.os.path.exists(filename):
        filename = d.url_make(charid, "char/cover", root=True)
        if not filename:
            return
        remove = False

    im = image.read(filename)
    size = im.size.width, im.size.height

    d.execute("""
        UPDATE character
        SET settings = REGEXP_REPLACE(settings, '-.', '') || '-%s'
        WHERE charid = %i
    """, [image.image_setting(im), charid])
    dest = os.path.join(d.get_character_directory(charid), '%i.thumb%s' % (charid, images.image_extension(im)))

    bounds = None
    if image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = images.make_thumbnail(im, bounds)
    thumb.write(dest, format=images.image_file_type(thumb))
    if remove:
        os.remove(filename)
Exemple #4
0
def _create_char(x1, y1, x2, y2, charid, remove=True):
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    filename = d.url_make(charid, "char/.thumb", root=True)
    if not m.os.path.exists(filename):
        filename = d.url_make(charid, "char/cover", root=True)
        if not filename:
            return
        remove = False

    im = image.read(filename)
    size = im.size.width, im.size.height

    d.engine.execute("""
        UPDATE character
        SET settings = REGEXP_REPLACE(settings, '-.', '') || '-' || %(image_setting)s
        WHERE charid = %(char)s
    """, image_setting=image.image_setting(im), char=charid)
    dest = os.path.join(d.get_character_directory(charid), '%i.thumb%s' % (charid, images.image_extension(im)))

    bounds = None
    if image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = images.make_thumbnail(im, bounds)
    thumb.write(dest, format=images.image_file_type(thumb))
    if remove:
        os.remove(filename)
Exemple #5
0
def create(userid, x1, y1, x2, y2, auto=False, config=None):
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    db = d.connect()
    im = db.query(orm.MediaItem).get(avatar_source(userid)['mediaid']).as_image()
    file_type = image.image_file_type(im)
    bounds = None
    size = im.size.width, im.size.height
    if not auto and image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = image.shrinkcrop(im, geometry.Size(100, 100), bounds)
    media_item = orm.fetch_or_create_media_item(
        thumb.to_buffer(format=file_type), file_type=file_type, im=thumb)
    orm.UserMediaLink.make_or_replace_link(userid, 'avatar', media_item)
    orm.UserMediaLink.clear_link(userid, 'avatar-source')
Exemple #6
0
def create(userid, x1, y1, x2, y2):
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    db = d.connect()
    im = db.query(orm.MediaItem).get(
        avatar_source(userid)['mediaid']).as_image()
    file_type = images.image_file_type(im)
    bounds = None
    size = im.size.width, im.size.height
    if image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = image.shrinkcrop(im, geometry.Size(100, 100), bounds)
    media_item = orm.MediaItem.fetch_or_create(
        thumb.to_buffer(format=file_type), file_type=file_type, im=thumb)
    orm.UserMediaLink.make_or_replace_link(userid, 'avatar', media_item)
    orm.UserMediaLink.clear_link(userid, 'avatar-source')
Exemple #7
0
def create(userid, x1, y1, x2, y2, submitid=None, charid=None,
           config=None, remove=True):
    if charid:
        return _create_char(userid, x1, y1, x2, y2, charid, config, remove)

    db = d.connect()
    x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2)
    source = thumbnail_source(submitid)
    im = db.query(orm.MediaItem).get(source['mediaid']).as_image()
    size = im.size.width, im.size.height
    bounds = None
    if image.check_crop(size, x1, y1, x2, y2):
        bounds = geometry.Rectangle(x1, y1, x2, y2)
    thumb = images.make_thumbnail(im, bounds)
    file_type = images.image_file_type(im)
    media_item = orm.fetch_or_create_media_item(
        thumb.to_buffer(format=file_type), file_type=file_type, im=thumb)
    orm.SubmissionMediaLink.make_or_replace_link(
        submitid, 'thumbnail-custom', media_item)