adhocracy_core.resources.image module

image resource type.

allow_view_eveyone(context: <InterfaceClass adhocracy_core.interfaces.IResource>, registry: pyramid.registry.Registry, options: dict)[source]

Add view permission for everyone for context.

interface IImageDownload[source]

Extends: adhocracy_core.resources.asset.IAssetDownload

Downloadable binary file for Images.

class ImageDownload(stream=None, mimetype=None, title='')[source]

Bases: substanced.file.File, adhocracy_core.resources.asset.AssetDownload

Allow downloading the first image file in the term:lineage.

The constructor of a File object.

stream should be a filelike object (an object with a read method that takes a size argument) or None. If stream is None, the blob attached to this file object is created empty.

title must be a string or Unicode object.

mimetype may be any of the following:

  • None, meaning set this file object’s mimetype to application/octet-stream (the default).

  • A mimetype string (e.g. image/gif)

  • The constant substanced.file.USE_MAGIC, which will derive the mimetype from the stream content (if stream is also supplied) using the python-magic library.

    Warning

    On non-Linux systems, successful use of substanced.file.USE_MAGIC requires the installation of additional dependencies. See optional_dependencies.

dimensions = None

adhocracy_core.interfaces.Dimension to resize the image

get_response(registry: pyramid.registry.Registry=None) → pyramid.response.FileResponse[source]

Return response with resized binary content of the image data.

The image mimetype is converted to JPEG to decrease the file size.

crop(image: <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/adhocracy3/envs/stable/lib/python3.5/site-packages/PIL/Image.py'>, dimensions: adhocracy_core.interfaces.Dimensions) → <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/adhocracy3/envs/stable/lib/python3.5/site-packages/PIL/Image.py'>[source]

Return a cropped version of image.

The returned version will have the same aspect ratio as the target dimensions, but not necessarily the same size, so a further resizing step may be needed. If the original image is wider, it is cropped in X direction so that only the middle part remains. If it’s higher, it’s cropped in Y direction.

If original and target aspect ratio are identical, the image is returned unchanged.

interface IImage[source]

Extends: adhocracy_core.resources.asset.IAsset

An image asset.

add_image_size_downloads(context: <InterfaceClass adhocracy_core.resources.image.IImage>, registry: pyramid.registry.Registry, **kwargs)[source]

Add download for every image size of context.

includeme(config)[source]

Add resource type to registry.