def from_filepath(filepath, caption=None, jpeg_thumbnail=None): assert os.path.exists(filepath) if not jpeg_thumbnail: jpeg_thumbnail = ImageTools.generatePreviewFromImage(file) width, height = ImageTools.getImageDimensions(filepath) assert width and height, "Could not determine image dimensions" return ImageAttributes(width, height, caption, jpeg_thumbnail)
def fromFilePath(fpath, caption=None): preview = ImageTools.generatePreviewFromImage(fpath) dimensions = ImageTools.getImageDimensions(fpath) assert dimensions, "Could not determine image dimensions" width, height = dimensions entity = DownloadableMessageProtocolEntity("raw", width, height, caption) return entity
def fromBuilder(builder): builder.getOrSet("preview", lambda: ImageTools.generatePreviewFromImage(builder.getOriginalFilepath())) filepath = builder.getFilepath() caption = builder.get("caption") dimensions = builder.get("dimensions", ImageTools.getImageDimensions(builder.getOriginalFilepath())) assert dimensions, "Could not determine image dimensions" width, height = dimensions entity = DownloadableMediaMessageProtocolEntity.fromBuilder(builder) entity.__class__ = builder.cls entity.setImageProps("raw", width, height, caption) return entity
def from_filepath(filepath, dimensions=None, caption=None, jpeg_thumbnail=None): assert os.path.exists(filepath) if not jpeg_thumbnail: jpeg_thumbnail = ImageTools.generatePreviewFromImage(filepath) dimensions = dimensions or ImageTools.getImageDimensions(filepath) width, height = dimensions if dimensions else (None, None) assert width and height, "Could not determine image dimensions, install pillow or pass dimensions" return ImageAttributes(width, height, caption, jpeg_thumbnail)
def fromBuilder(builder): builder.getOrSet("preview", lambda: ImageTools.generatePreviewFromImage(builder.getOriginalFilepath())) filepath = builder.getFilepath() caption = builder.get("caption") dimensions = builder.get("dimensions", ImageTools.getImageDimensions(builder.getOriginalFilepath())) assert dimensions, "Could not determine image dimensions" width, height = dimensions entity = DownloadableMediaMessageProtocolEntity.fromBuilder(builder) entity.__class__ = builder.cls entity.setImageProps("raw", width, height, caption) return entity
def fromFilePath(path, url, ip, to, mimeType = None, caption = None, dimensions = None): preview = ImageTools.generatePreviewFromImage(path) entity = DownloadableMediaMessageProtocolEntity.fromFilePath(path, url, DownloadableMediaMessageProtocolEntity.MEDIA_TYPE_IMAGE, ip, to, mimeType, preview) entity.__class__ = ImageDownloadableMediaMessageProtocolEntity if not dimensions: dimensions = ImageTools.getImageDimensions(path) assert dimensions, "Could not determine image dimensions" width, height = dimensions entity.setImageProps("raw", width, height, caption) return entity
def fromFilePath(path, url, ip, to, mimeType=None, caption=None, dimensions=None): preview = ImageTools.generatePreviewFromImage(path) entity = DownloadableMediaMessageProtocolEntity.fromFilePath( path, url, DownloadableMediaMessageProtocolEntity.MEDIA_TYPE_IMAGE, ip, to, mimeType, preview) entity.__class__ = ImageDownloadableMediaMessageProtocolEntity if not dimensions: dimensions = ImageTools.getImageDimensions(path) assert dimensions, "Could not determine image dimensions" width, height = dimensions entity.setImageProps("raw", width, height, caption) return entity