The ImageMagickidentify
tool, when used with the -verbose
option, provides comprehensive information about an image. While the resulting text output is comprehensive, it is not particularly well suited for machine consumption and automation.
This Python 2.xImageMagickIdentifyParser
utility class can be used to call or parse the identify -verbose <image>
tool text output and converts it into various formats such as JSON, XML, and iRODS for further integration reuse by code or applications.
See the samples folder for examples.
- You will need Python 2.x and ImageMagick to be installed on your system in order to use this utility
- Be aware that some security vulnerabilities were recently reported around the ImageMagick package. Make sure to read about this and, if applicable, take necessary steps ensuring you operate in a safe environment.
sudo apt-get install imagemagick
pip install --user -r dependencies.txt
You can run the utility directly from the command line by calling python ImageMagickIdentifyParser.py <options> <filename>
or import/integrate in your own Python scripts.
usage: ImageMagickIdentifyParser.py [-h] [--type TYPE] [--histo] filename
ImageMagick identify -verbose parser and convertor
positional arguments:
filename The input file
optional arguments:
-h, --help show this help message and exit
--type TYPE, -t TYPE The output type. Can be json|irods|raw|xml.
--histo, -H Includes histogram section in output
A specialized output format is supported by this utlity to facilitate integration with the Integrated Rule-Oriented Data System (iRODS), an open source file storage virtualization and management platform. The -t irods
option generates a '%'
separated collection of key/value pairs compatible with the msiString2KeyValPair iRODS microservice. This string can then be parsed to automatically associate the image extracted properties as metadata for a file stored in iRODS.
The utility is expected to be integrated in a iRODS rule using the the msiExecCmd
microservice. This requires a shell command to be installed in the server/bin/cmd
directory under your iRODS server root. For example:
#!/bin/sh
python /git/imagemagick-identify-parser/ImageMagickIdentifyParser.py -t irods $1
The msiExecCmd output can be called for example when an image file is added or modified in the repository, and its output processed by msiString2KeyValPair, and the parse metadata attached to the resources using msiSetKeyValuePairsToObj. This is illustrated in the rule code below (e.g. to add to the /etc/irods/core.re file):
ON($objPath like "/mtnaZone/demo/images\*.dcm"
|| $objPath like "/mtnaZone/demo/images\*.gif"
|| $objPath like "/mtnaZone/demo/images\*.jpg"
|| $objPath like "/mtnaZone/demo/images\*.jpeg"
|| $objPath like "/mtnaZone/demo/images\*.png"
|| $objPath like "/mtnaZone/demo/images\*.psd"
|| $objPath like "/mtnaZone/demo/images\*.tif"
|| $objPath like "/mtnaZone/demo/images\*.tiff"
{
*metaPath = $objPath;
*path = $filePath;
# call identify.sh command
msiExecCmd("identify.sh", *path, "null", "null", "null", *result);
# retrieve output
msiGetStdoutInExecCmdOut(*result,*out);
# parse into key value pairs
msiString2KeyValPair(*out, *kvp);
writeKeyValPairs("stdout", *kvp,"=");
# set metadata on object
msiGetObjType(*metaPath, *objType);
msiSetKeyValuePairsToObj(*kvp, *metaPath, *objType);
writeLine("stdout","added metadata *out to object with path *metaPath");
}
)
Putting this product together and maintaining the repository takes time and resources. We welcome your support in any shape or form, in particular:
- Let us know is you find any discrepancy or have suggestions towards enhancing the content or quality of the tool
- Donations are appreciated and can be made through PayPal
- Contact us if you would like to fund this work and optionally be credited as a sponsor
- Consider using our data/metadata services, products, or expertise
This work is licensed under the BSD-3 License. See LICENCE file for details.