Skip to content

fediverse_pasture.server.image_provider_blueprint

image_provider_blueprint = Blueprint('image_provider', __name__) module-attribute

Provides the capability to generate randomly colored 40 by 40 pixel images in various formats

get_filename(filename) async

Returns a random image. If filename ends with jpg, eps, gif, tiff, or webp an image of that type is returned otherwise png

Source code in fediverse_pasture/server/image_provider_blueprint.py
@image_provider_blueprint.get("/<filename>")
async def get_filename(filename):
    """Returns a random image. If filename ends with jpg, eps, gif, tiff, or webp an image of that type is returned otherwise png"""
    image_format, content_type = determine_format(filename)

    b = BytesIO()
    image = Image.new(
        "RGB", (40, 40), (randint(0, 255), randint(0, 255), randint(0, 255))
    )
    image.save(b, format=image_format)

    return b.getvalue(), 200, {"content-type": content_type}