Preparing images in the browser for upload, e.g. shrinking a photo taken on a phone before sending it to the server.
Preparing images in the browser for upload, e.g. shrinking a photo taken on a phone before sending it to the server.
(resize file)(resize file
{:keys [max-dimension quality type on-success on-error]
:or {max-dimension 1024 quality 0.85 type "image/jpeg"}})Draws the image file (a File or Blob) onto a canvas no larger than the maximum dimension, preserving the aspect ratio, and returns a js/Promise of the result as a Blob. Smaller images are not enlarged.
The image is decoded with createImageBitmap, which applies the photo's EXIF orientation by default, so sideways phone photos come out upright.
Options: :max-dimension - the largest the width or height may be, in pixels (default 1024) :quality - the encoding quality, between 0 and 1, for lossy types (default 0.85) :type - the MIME type of the resulting blob (default "image/jpeg") :on-success - called with the blob :on-error - called with the error if the image can't be read or encoded. When given, the promise resolves to its return value; otherwise the promise rejects.
Draws the image file (a File or Blob) onto a canvas no larger than
the maximum dimension, preserving the aspect ratio, and returns a
js/Promise of the result as a Blob. Smaller images are not enlarged.
The image is decoded with createImageBitmap, which applies the photo's
EXIF orientation by default, so sideways phone photos come out upright.
Options:
:max-dimension - the largest the width or height may be, in pixels
(default 1024)
:quality - the encoding quality, between 0 and 1, for lossy
types (default 0.85)
:type - the MIME type of the resulting blob
(default "image/jpeg")
:on-success - called with the blob
:on-error - called with the error if the image can't be read or
encoded. When given, the promise resolves to its
return value; otherwise the promise rejects.(scaled-dimensions width height max-dim)Returns [width height] scaled so neither exceeds max-dim, preserving the aspect ratio. Smaller images keep their size.
Returns [width height] scaled so neither exceeds max-dim, preserving the aspect ratio. Smaller images keep their size.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |