Thumbnail generator library for Clojure.
Based on mikera/imagez this library is useful to convert, resize and crop images.
(use 'thumbnailz.core)
Usage: (png-path? image-path)
Returns true if image-path is a string that ends with .png extension
Example:
(png-path? "some/dir/file.png")
=> true
(png-path? "some/dir/file.jpg")
=> false
Usage: (change-path-extension file-path new-ext)
Returns file-path with new-ext as file extension
Example:
(change-path-extension "./image.jpg" "png")
=> "./image.png"
Usage: (apply-suffix-to-filename file-path suffix)
Returns file-path with suffix appended to the file name
Example:
(apply-suffix-to-filename "./image.png" "_WxH")
=> "./image_WxH.png"
(apply-suffix-to-filename "./image.png" "-circle")
=> "./image-circle.png"
Usage: (load-image-from-path image-path)
Returns a BufferedImage loaded from image-path
Example:
(load-image-from-path "./image.png")
=> #object[java.awt.image.BufferedImage ...]
Usage: (get-image-object-width image)
Returns the width of the given image object
Example:
(get-image-object-width (load-image-from-path "./image.png"))
=> 300
Usage: (get-image-object-height image)
Returns the height of the given image object
Example:
(get-image-object-height (load-image-from-path "./image.png"))
=> 300
Usage: (get-image-info image-path)
Returns information about the image located at image-path
Example:
(get-image-info "./image.png")
=> {:width 300, :height 300}
Usage: (convert-to-png image-path)
Returns the path of the new png created from image-path file.
Saves the new png at the same level of image-path
Example:
(convert-to-png "some/dir/image.jpg")
=> "some/dir/image.png"
Usage: (save-image-to-path image dest-path)
Saves the image to the dest-path and returns the dest-path
Example:
(save-image-to-path (load-image-from-path "./image.png") "destination/output.png")
=> "destination/output.png"
Usage: (resize-image image-path width height)
Usage: (resize-image image-path dimension)
Returns the BufferedImage resized by width and height.
If only one dimension is specified, the biggest between width and height is resized, maintaining the ratio of the other one.
Example:
(resize-image "./image.png" 300 300)
=> #object[java.awt.image.BufferedImage ...]
(resize-image "./image.png" 300)
=> #object[java.awt.image.BufferedImage ...]
Usage: (resize-image-and-save image-path dest-path width height)
Usage: (resize-image-and-save image-path dest-path dimension)
Returns the dest-path of the resized image located in src-path.
Saves the image to the dest-path.
Example:
(resize-image-and-save "./image.png" "./dest/output.png" 300 300)
=> "./dest/output.png"
;no conversion applied
(resize-image-and-save "./image.jpg" "./dest/output.jpg" 300)
=> "./dest/output.jpg"
Usage: (crop-square image-path dimension suffix)
Returns the path of a new square image resized from image-path with width and height equal to dimension.
If the image is not squared, it will be cropped from center by the min dimension.
Saves the new png at the same level of image-path applying suffix to file name.
Example:
(crop-square "some/dir/image.png" 200 "_200x200")
=> "some/dir/image_200x200.png"
;automatic conversion in png
(crop-square "some/dir/image.jpg" 200 "_200x200")
=> "some/dir/image_200x200.png"
Usage: (crop-circle image-path dimension suffix)
Returns the path of a new circle image cropped from image-path with width and height equal to dimension.
Saves the new png at the same level of image-path applying suffix to file name.
Example:
(crop-circle "some/dir/image.png" 150 "_circle")
=> "some/dir/image_circle.png"
;automatic conversion in png
(crop-circle "some/dir/image.jpg" 150 "_circle")
=> "some/dir/image_circle.png"
MIT.