keepluggable.image_actions module

An Action class that deals with images.

class keepluggable.image_actions.ImageAction(orchestrator: keepluggable.orchestrator.Orchestrator, namespace: str)[source]

Bases: keepluggable.actions.BaseFilesAction

A specialized Action class that deals with images.

It converts formats, rotates and resizes images etc.

To enable this action, use this configuration:

cls_action = keepluggable.image_actions.ImageAction

It inherits from BaseFilesAction, so read its documentation too.

Installing Pillow

To use this action, you need to install the Pillow imaging library:

sudo apt-get install libjpeg-dev zlib1g-dev libfreetype6-dev
# Create these links. If they already exist, remove and readd them:
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib
pip install Pillow

Pay attention to the desired supported formats near the end of the output:

*** TKINTER support not available
--- JPEG support available
*** OPENJPEG (JPEG2000) support not available
--- ZLIB (PNG/ZIP) support available
*** LIBTIFF support not available
--- FREETYPE2 support available
*** LITTLECMS2 support not available
*** WEBP support not available
*** WEBPMUX support not available

Configuration settings

  • upload_must_be_img: a boolean; if True, uploads will only be accepted if they are image files. The default for this setting is False.

  • store_original: a boolean; if False, the original upload will not have its payload stored. The metadata is always stored in an effort to recognize repeated uploads of the same file. The default for this setting is True.

  • versions: a list of image versions in the form “format max-width max-height name”

  • versions_quality (integer): the quality parameter to be passed to the Pillow JPEG encoder. The default is 90.

Here is an example configuration:

[keepluggable_page_images]
# (...)
store_original = False
versions =
    jpeg 3840 2160 4k
    jpeg 1920 1920 hd
    jpeg  960  960 half
    jpeg  480  480 quarter
    jpeg  240  240 vignette
versions_quality = 90
class Config(*args, **kw)[source]

Bases: keepluggable.actions.BaseFilesAction.Config

Validated configuration for ImageAction.

EXIF_ROTATION_FIX = {1: 0, 3: 180, 6: 270, 8: 90}
EXIF_TAGS = {'Acceleration': 37892, 'ActiveArea': 50829, 'AmbientTemperature': 37888, 'AnalogBalance': 50727, 'AntiAliasStrength': 50738, 'ApertureValue': 37378, 'Artist': 315, 'AsShotICCProfile': 50831, 'AsShotNeutral': 50728, 'AsShotPreProfileMatrix': 50832, 'AsShotProfileName': 50934, 'AsShotWhiteXY': 50729, 'BaselineExposure': 50730, 'BaselineNoise': 50731, 'BaselineSharpness': 50732, 'BatteryLevel': 33423, 'BayerGreenSplit': 50733, 'BestQualityScale': 50780, 'BitsPerSample': 258, 'BlackLevel': 50714, 'BlackLevelDeltaH': 50715, 'BlackLevelDeltaV': 50716, 'BlackLevelRepeatDim': 50713, 'BodySerialNumber': 42033, 'BrightnessValue': 37379, 'CFALayout': 50711, 'CFAPattern': 41730, 'CFAPlaneColor': 50710, 'CFARepeatPatternDim': 33421, 'CalibrationIlluminant1': 50778, 'CalibrationIlluminant2': 50779, 'CameraCalibration1': 50723, 'CameraCalibration2': 50724, 'CameraCalibrationSignature': 50931, 'CameraElevationAngle': 37893, 'CameraOwnerName': 42032, 'CameraSerialNumber': 50735, 'CellLength': 265, 'CellWidth': 264, 'ChromaBlurRadius': 50737, 'ClipPath': 343, 'ColorMap': 320, 'ColorMatrix1': 50721, 'ColorMatrix2': 50722, 'ColorSpace': 40961, 'ColorimetricReference': 50879, 'ComponentsConfiguration': 37121, 'CompressedBitsPerPixel': 37122, 'Compression': 259, 'Contrast': 41992, 'Copyright': 33432, 'CurrentICCProfile': 50833, 'CurrentPreProfileMatrix': 50834, 'CustomRendered': 41985, 'DNGBackwardVersion': 50707, 'DNGPrivateData': 50740, 'DNGVersion': 50706, 'DateTime': 306, 'DateTimeDigitized': 36868, 'DateTimeOriginal': 36867, 'DefaultCropOrigin': 50719, 'DefaultCropSize': 50720, 'DefaultScale': 50718, 'DeviceSettingDescription': 41995, 'DigitalZoomRatio': 41988, 'DocumentName': 269, 'DotRange': 336, 'ExifImageHeight': 40963, 'ExifImageWidth': 40962, 'ExifInteroperabilityOffset': 40965, 'ExifOffset': 34665, 'ExifVersion': 36864, 'ExposureBiasValue': 37380, 'ExposureIndex': 41493, 'ExposureMode': 41986, 'ExposureProgram': 34850, 'ExposureTime': 33434, 'ExtraSamples': 338, 'FNumber': 33437, 'FileSource': 41728, 'FillOrder': 266, 'Flash': 37385, 'FlashEnergy': 41483, 'FlashPixVersion': 40960, 'FocalLength': 37386, 'FocalLengthIn35mmFilm': 41989, 'FocalPlaneResolutionUnit': 41488, 'FocalPlaneXResolution': 41486, 'FocalPlaneYResolution': 41487, 'ForwardMatrix1': 50964, 'ForwardMatrix2': 50965, 'FreeByteCounts': 289, 'FreeOffsets': 288, 'GPSInfo': 34853, 'GainControl': 41991, 'Gamma': 42240, 'GrayResponseCurve': 291, 'GrayResponseUnit': 290, 'HalftoneHints': 321, 'HostComputer': 316, 'Humidity': 37889, 'IPTCNAA': 33723, 'ISOSpeedRatings': 34855, 'ImageDescription': 270, 'ImageHistory': 37395, 'ImageID': 32781, 'ImageLength': 257, 'ImageNumber': 37393, 'ImageResources': 34377, 'ImageUniqueID': 42016, 'ImageWidth': 256, 'Indexed': 346, 'InkNames': 333, 'InkSet': 332, 'InterColorProfile': 34675, 'Interlace': 34857, 'JPEGProc': 512, 'JPEGTables': 347, 'JpegACTables': 521, 'JpegDCTables': 520, 'JpegIFByteCount': 514, 'JpegIFOffset': 513, 'JpegLosslessPredictors': 517, 'JpegPointTransforms': 518, 'JpegQTables': 519, 'JpegRestartInterval': 515, 'LensInfo': 50736, 'LensMake': 42035, 'LensModel': 42036, 'LensSerialNumber': 42037, 'LensSpecification': 42034, 'LightSource': 37384, 'LinearResponseLimit': 50734, 'LinearizationTable': 50712, 'LocalizedCameraModel': 50709, 'Make': 271, 'MakerNote': 37500, 'MakerNoteSafety': 50741, 'MaskedAreas': 50830, 'MaxApertureValue': 37381, 'MaxSampleValue': 281, 'MeteringMode': 37383, 'MinSampleValue': 280, 'Model': 272, 'NewSubfileType': 254, 'Noise': 37389, 'NoiseProfile': 51041, 'NoiseReductionApplied': 50935, 'NumberOfInks': 334, 'OECF': 34856, 'OPIProxy': 351, 'OpcodeList1': 51008, 'OpcodeList2': 51009, 'OpcodeList3': 51022, 'Orientation': 274, 'OriginalRawFileData': 50828, 'OriginalRawFileDigest': 50973, 'OriginalRawFileName': 50827, 'PageName': 285, 'PageNumber': 297, 'PhotometricInterpretation': 262, 'PlanarConfiguration': 284, 'Predictor': 317, 'Pressure': 37890, 'PreviewApplicationName': 50966, 'PreviewApplicationVersion': 50967, 'PreviewColorSpace': 50970, 'PreviewDateTime': 50971, 'PreviewSettingsDigest': 50969, 'PreviewSettingsName': 50968, 'PrimaryChromaticities': 319, 'PrintImageMatching': 50341, 'ProcessingSoftware': 11, 'ProfileCalibrationSignature': 50932, 'ProfileCopyright': 50942, 'ProfileEmbedPolicy': 50941, 'ProfileHueSatMapData1': 50938, 'ProfileHueSatMapData2': 50939, 'ProfileHueSatMapDims': 50937, 'ProfileLookTableData': 50982, 'ProfileLookTableDims': 50981, 'ProfileName': 50936, 'ProfileToneCurve': 50940, 'Rating': 18246, 'RatingPercent': 18249, 'RawDataUniqueID': 50781, 'RawImageDigest': 50972, 'ReductionMatrix1': 50725, 'ReductionMatrix2': 50726, 'ReferenceBlackWhite': 532, 'RelatedImageFileFormat': 4096, 'RelatedImageLength': 4098, 'RelatedImageWidth': 4097, 'RelatedSoundFile': 40964, 'ResolutionUnit': 296, 'RowInterleaveFactor': 50975, 'RowsPerStrip': 278, 'SMaxSampleValue': 341, 'SMinSampleValue': 340, 'SampleFormat': 339, 'SamplesPerPixel': 277, 'Saturation': 41993, 'SceneCaptureType': 41990, 'SceneType': 41729, 'SecurityClassification': 37394, 'SelfTimerMode': 34859, 'SensingMethod': 41495, 'ShadowScale': 50739, 'Sharpness': 41994, 'ShutterSpeedValue': 37377, 'Software': 305, 'SpatialFrequencyResponse': 41484, 'SpectralSensitivity': 34852, 'StripByteCounts': 279, 'StripOffsets': 273, 'SubIFDs': 330, 'SubTileBlockSize': 50974, 'SubfileType': 255, 'SubjectDistance': 37382, 'SubjectDistanceRange': 41996, 'SubjectLocation': 41492, 'SubsecTime': 37520, 'SubsecTimeDigitized': 37522, 'SubsecTimeOriginal': 37521, 'T4Options': 292, 'T6Options': 293, 'TIFF/EPStandardID': 37398, 'TargetPrinter': 337, 'Thresholding': 263, 'TileByteCounts': 325, 'TileLength': 323, 'TileOffsets': 324, 'TileWidth': 322, 'TimeZoneOffset': 34858, 'TransferFunction': 301, 'TransferRange': 342, 'UniqueCameraModel': 50708, 'UserComment': 37510, 'WaterDepth': 37891, 'WhiteBalance': 41987, 'WhiteLevel': 50717, 'WhitePoint': 318, 'XClipPathUnits': 344, 'XMLPacket': 700, 'XPAuthor': 40093, 'XPComment': 40092, 'XPKeywords': 40094, 'XPSubject': 40095, 'XPTitle': 40091, 'XResolution': 282, 'YCbCrCoefficients': 529, 'YCbCrPositioning': 531, 'YCbCrSubSampling': 530, 'YClipPathUnits': 345, 'YResolution': 283}
classmethod get_config(settings: Dict[str, Any]) Dict[str, Any][source]

Image versions are a complex string in configuration; parse them.

This gets called by the orchestrator at startup. Return the entire action configuration dictionary.

class keepluggable.image_actions.ImageVersionConfig(*args, **kw)[source]

Bases: colander.Schema

A part of the configuration.

classmethod from_str(line: str) Dict[str, Any][source]

From a configuration line, return a config dict.