コード例 #1
0
class ImageMetadataSchema(AssetMetadataSchema):
    """Data structure storing image asset metadata."""

    detail = Resource(dimensions=Dimensions(width=800, height=800),
                      readonly=True)
    thumbnail = Resource(dimensions=Dimensions(width=100, height=100),
                         readonly=True)
コード例 #2
0
class ImageMetadataSchema(AssetMetadataSchema):
    """Data structure storing image asset metadata."""

    mime_type = SingleLine(missing=required,
                           validator=image_mime_type_validator)
    detail = Resource(dimensions=Dimensions(width=800, height=800))
    thumbnail = Resource(dimensions=Dimensions(width=100, height=100))
コード例 #3
0
 def test_crop_and_resize_image(self, inst_with_dimensions, context,
                                registry, monkeypatch):
     import io
     from PIL import Image
     from substanced.file import File
     from adhocracy_core.sheets import asset
     from adhocracy_core.interfaces import Dimensions
     file = Mock(spec=File)
     file.blob = Mock()
     file.blob.open.return_value = io.BytesIO(b'dummy blob')
     file.mimetype = 'image/png'
     mock_retrieve_asset_file = Mock(spec=asset.retrieve_asset_file,
                                     return_value=file)
     monkeypatch.setattr(asset, 'retrieve_asset_file',
                         mock_retrieve_asset_file)
     mock_image = Mock()
     mock_image.size = (840, 700)
     mock_crop_image = Mock()
     mock_image.crop.return_value = mock_crop_image
     mock_open = Mock(spec=Image.open, return_value=mock_image)
     monkeypatch.setattr(Image, 'open', mock_open)
     dimensions = Dimensions(width=200, height=100)
     result = inst_with_dimensions._crop_and_resize_image(context, registry)
     assert file.blob.open.called
     assert mock_image.crop.called
     assert mock_crop_image.resize.called
     assert mock_crop_image.resize.call_args[0] == (dimensions,
                                                    Image.ANTIALIAS)
     assert result == inst_with_dimensions.file
     assert result.mimetype == file.mimetype
コード例 #4
0
ファイル: test_image.py プロジェクト: andantic/adhocracy3
 def test_create(self, registry, meta, pool):
     from adhocracy_core.interfaces import Dimensions
     from adhocracy_core.sheets.asset import IAssetData
     from adhocracy_core.sheets.image import IImageMetadata
     from .image import IImageDownload
     from adhocracy_core.utils import get_sheet
     file = Mock(mimetype='image/png', size=100, title='title')
     appstructs = {IAssetData.__identifier__: {'data': file}}
     res = registry.content.create(meta.iresource.__identifier__,
                                   appstructs=appstructs,
                                   parent=pool)
     meta = get_sheet(res, IImageMetadata).get()
     assert meta['filename'] == 'title'
     assert meta['size'] == 100
     assert meta['detail'] == res['0000000']
     assert IImageDownload.providedBy(meta['detail'])
     assert meta['detail'].dimensions == Dimensions(height=800, width=800)
     assert meta['thumbnail'] == res['0000001']
     assert meta['thumbnail'].dimensions == Dimensions(height=100, width=100)
コード例 #5
0
ファイル: mercator.py プロジェクト: andantic/adhocracy3
class IntroImageSchema(ImageMetadataSchema):

    thumbnail = Resource(dimensions=Dimensions(width=105, height=90))
    detail = Resource(dimensions=Dimensions(width=800, height=350))
コード例 #6
0
ファイル: image.py プロジェクト: fhartwig/adhocracy3.mercator

class IImageMetadata(IAssetMetadata):
    """Marker interface for images."""


def image_mime_type_validator(mime_type: str) -> bool:
    """Validate image file types."""
    return mime_type in ('image/gif', 'image/jpeg', 'image/png')


image_metadata_meta = asset_metadata_meta._replace(
    isheet=IImageMetadata,
    mime_type_validator=image_mime_type_validator,
    image_sizes={
        'thumbnail': Dimensions(width=100, height=100),
        'detail': Dimensions(width=800, height=800)
    },
)


class IImageReference(ISheet, ISheetReferenceAutoUpdateMarker):
    """Marker interface for an image reference."""


class ImageReference(SheetToSheet):
    """Reference to an image."""

    source_isheet = IImageReference
    source_isheet_field = 'picture'
    target_isheet = IImageMetadata
コード例 #7
0
    isheet=IOrganizationInfo, schema_class=OrganizationInfoSchema)


class IIntroImageMetadata(IAssetMetadata):
    """Marker interface for intro images."""


def _intro_image_mime_type_validator(mime_type: str) -> bool:
    return mime_type in ('image/gif', 'image/jpeg', 'image/png')


intro_image_metadata_meta = asset_metadata_meta._replace(
    isheet=IIntroImageMetadata,
    mime_type_validator=_intro_image_mime_type_validator,
    image_sizes={
        'thumbnail': Dimensions(width=105, height=90),
        'detail': Dimensions(width=800, height=350)
    },
)


class IntroImageReference(SheetToSheet):
    """Reference to an intro image."""

    source_isheet = IIntroduction
    source_isheet_field = 'picture'
    target_isheet = IIntroImageMetadata


class IntroductionSchema(colander.MappingSchema):
    """Data structure for the proposal introduction."""
コード例 #8
0
 def inst_with_dimensions(self):
     from adhocracy_core.sheets.asset import AssetFileDownload
     from adhocracy_core.interfaces import Dimensions
     return AssetFileDownload(Dimensions(width=200, height=100))
コード例 #9
0
ファイル: test_image.py プロジェクト: andantic/adhocracy3
def dimensions():
    from adhocracy_core.interfaces import Dimensions
    return Dimensions(width=200, height=100)