示例#1
0
    def generate(self, avatars, text, usernames, kwargs):
        avatar = BytesIO(http.get_content_raw(avatars[0]))
        try:
            img = image.Image(file=avatar)
        except Exception as e:
            raise BadRequest(f'The image could not be loaded: {e}')

        if img.animation:
            img = img.convert('png')
        img.transform(resize='400x400')

        try:
            multiplier = int(text)
        except ValueError:
            multiplier = 1
        else:
            multiplier = max(min(multiplier, 10), 1)

        img.liquid_rescale(width=int(img.width * 0.5),
                           height=int(img.height * 0.5),
                           delta_x=0.5 * multiplier,
                           rigidity=0)
        img.liquid_rescale(width=int(img.width * 1.5),
                           height=int(img.height * 1.5),
                           delta_x=2 * multiplier,
                           rigidity=0)

        b = BytesIO()
        img.save(file=b)
        b.seek(0)
        img.destroy()
        return send_file(b, mimetype='image/png')
示例#2
0
def convert(image: str, args: list, output_format: str):
    img_bytes = get_content_raw(image)
    args = ['gm', 'convert', '-'] + args + ['{}:-'.format(output_format)]

    proc = subprocess.Popen(args,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            stdin=subprocess.PIPE)
    stdout, stderr = proc.communicate(img_bytes)
    return stdout
示例#3
0
def radial_blur(image: str, degrees: int, output_format: str):
    img_bytes = get_content_raw(image)
    args = [
        'convert', '-', '-rotational-blur',
        str(degrees), '{}:-'.format(output_format)
    ]
    proc = subprocess.Popen(args,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            stdin=subprocess.PIPE)
    stdout, stderr = proc.communicate(img_bytes)
    return stdout