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)
def fake_media_items(charid, userid, login, settings): submission_url = define.cdnify_url(define.url_make( charid, "char/submit", query=[userid, settings], file_prefix=login)) cover_url = define.cdnify_url(define.url_make( charid, "char/cover", query=[settings], file_prefix=login)) thumbnail_url = define.cdnify_url(define.url_make( charid, "char/thumb", query=[settings])) return { "submission": [{ "display_url": submission_url, "described": { "cover": [{ "display_url": cover_url, }], }, }], "thumbnail-generated": [{ "display_url": thumbnail_url, }], "cover": [{ "display_url": cover_url, "described": { "submission": [{ "display_url": submission_url, }], }, }], }
def fake_media_items(charid, userid, login, settings): submission_url = define.cdnify_url(define.url_make( charid, "char/submit", query=[userid, settings], file_prefix=login)) cover_url = define.cdnify_url(define.url_make( charid, "char/cover", query=[settings], file_prefix=login)) thumbnail_url = define.cdnify_url(define.url_make( charid, "char/thumb", query=[settings])) return { "submission": [{ "display_url": submission_url, "described": { "cover": [{ "display_url": cover_url, }], }, }], "thumbnail-generated": [{ "display_url": thumbnail_url, }], "cover": [{ "display_url": cover_url, "described": { "submission": [{ "display_url": submission_url, }], }, }], }
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)
def manage_thumbnail_get_(request): form = request.web_input(submitid="", charid="", auto="") submitid = define.get_int(form.submitid) charid = define.get_int(form.charid) if submitid and request.userid not in staff.ADMINS and request.userid != define.get_ownerid(submitid=submitid): return Response(define.errorpage(request.userid, errorcode.permissions)) elif charid and request.userid not in staff.ADMINS and request.userid != define.get_ownerid(charid=charid): return Response(define.errorpage(request.userid, errorcode.permissions)) elif not submitid and not charid: return Response(define.errorpage(request.userid)) if charid: source_path = define.url_make(charid, "char/.thumb", root=True) if os.path.exists(source_path): source = define.url_make(charid, "char/.thumb") else: source = define.url_make(charid, "char/cover") else: try: source = thumbnail.thumbnail_source(submitid)['display_url'] except WeasylError: source = None return Response(define.webpage(request.userid, "manage/thumbnail.html", [ # Feature "submit" if submitid else "char", # Targetid define.get_targetid(submitid, charid), # Thumbnail source, # Exists bool(source), ], options=['imageselect'], title="Select Thumbnail"))
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)
def manage_thumbnail_get_(request): form = request.web_input(submitid="", charid="", auto="") submitid = define.get_int(form.submitid) charid = define.get_int(form.charid) if submitid and request.userid not in staff.ADMINS and request.userid != define.get_ownerid( submitid=submitid): return Response(define.errorpage(request.userid, errorcode.permissions)) elif charid and request.userid not in staff.ADMINS and request.userid != define.get_ownerid( charid=charid): return Response(define.errorpage(request.userid, errorcode.permissions)) elif not submitid and not charid: return Response(define.errorpage(request.userid)) if charid: source_path = define.url_make(charid, "char/.thumb", root=True) if os.path.exists(source_path): source = define.url_make(charid, "char/.thumb") else: source = define.url_make(charid, "char/cover") else: try: source = thumbnail.thumbnail_source(submitid)['display_url'] except WeasylError: source = None return Response( define.webpage( request.userid, "manage/thumbnail.html", [ # Feature "submit" if submitid else "char", # Targetid define.get_targetid(submitid, charid), # Thumbnail source, # Exists bool(source), ], options=['imageselect'], title="Select Thumbnail"))
def _upload_char(filedata, charid): """ Creates a preview-size copy of an uploaded image file for a new thumbnail selection file. """ filename = d.url_make(charid, "char/.thumb", root=True) files.write(filename, filedata) if image.check_type(filename): image.make_cover(filename) else: os.remove(filename) raise WeasylError("FileType")
def _upload_char(userid, filedata, charid): """ Creates a preview-size copy of an uploaded image file for a new thumbnail selection file. """ query = d.execute( "SELECT userid, settings FROM character WHERE charid = %i", [charid], options="single") if not query: raise WeasylError("Unexpected") elif userid != query[0] and userid not in staff.MODS: raise WeasylError("InsufficientPermissions") filename = d.url_make(charid, "char/.thumb", root=True) files.write(filename, filedata, encoding=None) if image.check_type(filename): image.make_cover(filename) else: files.remove(filename) raise WeasylError("FileType")
def _upload_char(userid, filedata, charid): """ Creates a preview-size copy of an uploaded image file for a new thumbnail selection file. """ query = d.execute( "SELECT userid, settings FROM character WHERE charid = %i", [charid], options="single") if not query: raise WeasylError("Unexpected") elif userid != query[0] and userid not in staff.MODS: raise WeasylError("InsufficientPermissions") filename = d.url_make(charid, "char/.thumb", root=True) files.write(filename, filedata) if image.check_type(filename): image.make_cover(filename) else: os.remove(filename) raise WeasylError("FileType")