Example #1
0
async def download(id, filename='image'):
    try:
        id = str(UUID(id))
        media = Media.get(id=id)
        return await send_file(io.BytesIO(media.data), attachment_filename="{}.{}".format(filename, media.extension))
    except Exception as e:
        logging.exception(e)
        abort(404)
Example #2
0
async def downloadthumbnailRetina(id, filename='image'):
    try:
        id = str(UUID(id))
        media = Media.get(id=id)
        return await send_file(io.BytesIO(media.thumbnailRetina), attachment_filename="{}.jpg".format(filename))
    except Exception as e:
        logging.exception(e)
        abort(404)
Example #3
0
     if len(media.datas) == 0:
         OriginalImage.create(media=media, data=HEICEncode(media._data))'''
 '''backupPath = "/CityLand02/PixivDump/"
 for media_id in tqdm(Media.select(Media.id).where(Media.sourceType=='PIXIV'), total=Media.select(Media.id).where(Media.sourceType=='PIXIV').count()):
     media = Media.get(id=media_id)
     if media._data is not None and len(media.datas)>0:
         with open(os.path.join(backupPath, "{}.{}".format(media.mainDescription, media.extension)), "wb") as img:
             img.write(media._data)
         media._data = None
         media.save()'''
 for media_id in tqdm(Media.select(Media.id).where(
         Media.sourceType == 'PIXIV' and Media.extension == 'png'),
                      total=Media.select(Media.id).where(
                          Media.sourceType == 'PIXIV'
                          and Media.extension == 'png').count()):
     media = Media.get(id=media_id)
     imgBuffer = io.BytesIO(media.thumbnail)
     imgObj = Image.open(imgBuffer)
     if imgObj.format in ['JPEG', 'jpeg']:
         continue
     imgObj = imgObj.convert('RGB')
     thumb = io.BytesIO()
     imgObj.save(thumb, format="jpeg", quality=85, optimize=True)
     media.thumbnail = thumb.getvalue()
     if media.thumbnail2x is not None:
         imgBuffer = io.BytesIO(media.thumbnail2x)
         imgObj = Image.open(imgBuffer)
         imgObj = imgObj.convert('RGB')
         width, height = imgObj.size
         if width > 800:
             #twidth = min([width, 1600])
Example #4
0
        ret = dict()
        degree_dict = {1: 0, 3: 180, 6: -90, 8: 90}
        if info:
            orientation = info.get(274, 0)
            degree = degree_dict.get(orientation, 0)
    return degree


if __name__ == '__main__':
    #sourceTypes = ["MIKU", "GANBARU", "YOGIOH_WAKE", "LOLI", "ERK"]
    sourceTypes = ["YUGIOH_WAKE"]
    for id in tqdm(
            Media.select(Media.id).where(Media.sourceType << sourceTypes),
            total=Media.select(
                Media.id).where(Media.sourceType << sourceTypes).count()):
        media = Media.get(id=id)
        imgBuffer = io.BytesIO(media.data)
        img = Image.open(imgBuffer)
        format = img.format
        img = img.rotate(get_rotate_degree(img))
        width, height = img.size
        twidth = min([width, 1600])
        theight = floor((twidth / width) * height + 0.5)
        img.thumbnail((twidth, theight), resample=Image.ANTIALIAS)
        thumb = io.BytesIO()
        img.save(thumb, format=format, quality=100)
        media.thumbnailRetina = thumb.getvalue()

        img = Image.open(imgBuffer)
        format = img.format
        img = img.rotate(get_rotate_degree(img))