Zip, unzip and image-manipulation helper built on Kademi's content-addressed blob and hash store. Used by the file manager to bundle stored files into a downloadable archive, expand an uploaded or stored zip into its individual files, and crop or resize images that are themselves referenced by content hash. Every method that produces new content writes it back into the blob store and returns the hash of the result, rather than returning the bytes directly.


Methods

compressFiles(Map<String,String> files) · unzip(String zipHash) · unzip(FileItem file) · cropImage(String imageHash, Integer x, Integer y, Integer width, Integer height) · cropImage(String imageHash, Integer x, Integer y, Integer width, Integer height, String formatName) · cropImage(String imageHash, Integer width, Integer height) · imageDimensions(String imageHash) · getImageDimensions(String imageHash) · resizeImage(String imageHash, Integer width, Integer height) · resizeImage(String imageHash, Integer width, Integer height, String formatName)

compressFiles(Map<String,String> files)

Returns: String

Builds a zip archive from a set of previously stored files and writes the archive into the blob store. The files map has one entry per file to include, keyed by the file name to use inside the archive, with the value being the content hash of that file's bytes. Entries whose hash is not present in the hash store are silently skipped.

ParameterDescription
filesmap of archive file name to the content hash of the file's bytes

unzip(String zipHash)

Returns: List<JSONObject>

Expands a zip archive already held in the blob store, writing each contained file back into the blob store as its own content-addressed entry. Directory entries in the archive are skipped.

ParameterDescription
zipHashthe content hash of the zip archive to expand

unzip(FileItem file)

Returns: List<JSONObject>

Expands an uploaded zip file, writing each contained file into the blob store as its own content-addressed entry. Directory entries in the archive are skipped. Unlike unzip(String) the source archive is read directly from the upload rather than being looked up in the blob store first.

ParameterDescription
filethe uploaded zip file to expand

cropImage(String imageHash, Integer x, Integer y, Integer width, Integer height)

Returns: String

Crops a rectangular region out of a stored image and writes the result back into the blob store as a new PNG image. Negative or null x, y, width or height values are treated as zero.

ParameterDescription
imageHashthe content hash of the source image
xthe left edge of the crop rectangle, in pixels
ythe top edge of the crop rectangle, in pixels
widththe width of the crop rectangle, in pixels
heightthe height of the crop rectangle, in pixels

cropImage(String imageHash, Integer x, Integer y, Integer width, Integer height, String formatName)

Returns: String

Crops a rectangular region out of a stored image and writes the result back into the blob store in the given image format. Negative or null x, y, width or height values are treated as zero, and a blank format name defaults to PNG.

ParameterDescription
imageHashthe content hash of the source image
xthe left edge of the crop rectangle, in pixels
ythe top edge of the crop rectangle, in pixels
widththe width of the crop rectangle, in pixels
heightthe height of the crop rectangle, in pixels
formatNamethe image format to write, e.g. png

cropImage(String imageHash, Integer width, Integer height)

Returns: String

Crops a stored image to the given width and height, starting from the top-left corner, and writes the result back into the blob store as a new PNG image.

ParameterDescription
imageHashthe content hash of the source image
widththe width of the crop rectangle, in pixels
heightthe height of the crop rectangle, in pixels

imageDimensions(String imageHash)

Returns: Dimension

Reads the pixel dimensions of a stored image. Equivalent to getImageDimensions.

ParameterDescription
imageHashthe content hash of the image

getImageDimensions(String imageHash)

Returns: Dimension

Reads the pixel dimensions of a stored image.

ParameterDescription
imageHashthe content hash of the image

resizeImage(String imageHash, Integer width, Integer height)

Returns: String

Scales a stored image to the given width and height and writes the result back into the blob store as a new PNG image, using bilinear interpolation.

ParameterDescription
imageHashthe content hash of the source image
widththe target width, in pixels
heightthe target height, in pixels

resizeImage(String imageHash, Integer width, Integer height, String formatName)

Returns: String

Scales a stored image to the given width and height, using bilinear interpolation, and writes the result back into the blob store. A blank format name defaults to PNG. The source image must already be stored and no larger than 500kB; a missing or oversized source causes a runtime exception.

ParameterDescription
imageHashthe content hash of the source image
widththe target width, in pixels
heightthe target height, in pixels
formatNamethe image format to write, e.g. png
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.