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.
| Parameter | Description |
|---|---|
files | map 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.
| Parameter | Description |
|---|---|
zipHash | the 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.
| Parameter | Description |
|---|---|
file | the 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.
| Parameter | Description |
|---|---|
imageHash | the content hash of the source image |
x | the left edge of the crop rectangle, in pixels |
y | the top edge of the crop rectangle, in pixels |
width | the width of the crop rectangle, in pixels |
height | the 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.
| Parameter | Description |
|---|---|
imageHash | the content hash of the source image |
x | the left edge of the crop rectangle, in pixels |
y | the top edge of the crop rectangle, in pixels |
width | the width of the crop rectangle, in pixels |
height | the height of the crop rectangle, in pixels |
formatName | the 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.
| Parameter | Description |
|---|---|
imageHash | the content hash of the source image |
width | the width of the crop rectangle, in pixels |
height | the height of the crop rectangle, in pixels |
imageDimensions(String imageHash)
Returns: Dimension
Reads the pixel dimensions of a stored image. Equivalent to getImageDimensions.
| Parameter | Description |
|---|---|
imageHash | the content hash of the image |
getImageDimensions(String imageHash)
Returns: Dimension
Reads the pixel dimensions of a stored image.
| Parameter | Description |
|---|---|
imageHash | the 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.
| Parameter | Description |
|---|---|
imageHash | the content hash of the source image |
width | the target width, in pixels |
height | the 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.
| Parameter | Description |
|---|---|
imageHash | the content hash of the source image |
width | the target width, in pixels |
height | the target height, in pixels |
formatName | the image format to write, e.g. png |