Liking cljdoc? Tell your friends :D

dk.simongray.colour-coded.image

The colours of an image, e.g. a podcast's artwork, from the bytes of its file, for an app to colour its UI by, and small copies of the image.

The platform decodes the image at a small size: ImageIO on the JVM, and the browser's own decoder in ClojureScript. On the JVM each function returns its result, and in ClojureScript a promise of it. The result is nil where the platform can't decode the image, e.g. WebP on the JVM, or anything in Node, which has no decoder, and for an image that's all transparent.

(cc/hex (image/seed bytes))   ; e.g. "#24476b"

For the theme of a whole site or app from an image, see theme/from-image. For small copies of an image, e.g. of artwork for a list, see thumbnails.

The colours of an image, e.g. a podcast's artwork, from the bytes of its
file, for an app to colour its UI by, and small copies of the image.

The platform decodes the image at a small size: ImageIO on the JVM, and
the browser's own decoder in ClojureScript. On the JVM each function
returns its result, and in ClojureScript a promise of it. The result is
nil where the platform can't decode the image, e.g. WebP on the JVM, or
anything in Node, which has no decoder, and for an image that's all
transparent.

    (cc/hex (image/seed bytes))   ; e.g. "#24476b"

For the theme of a whole site or app from an image, see
theme/from-image. For small copies of an image, e.g. of artwork for a
list, see thumbnails.
raw docstring

coloursclj/s

(colours b)

The colours for an app to colour its UI by the image in the bytes b, e.g. the artwork of a show: the scheme of its five commonest colours.

The colours for an app to colour its UI by the image in the bytes `b`,
e.g. the artwork of a show: the scheme of its five commonest colours.
sourceraw docstring

dominant-colourclj/s

(dominant-colour b)

The colour that most of the image in the bytes b has, e.g. for a player to tint its screen by the artwork.

The colour that most of the image in the bytes `b` has, e.g. for a player
to tint its screen by the artwork.
sourceraw docstring

max-pixelsclj/s

The most pixels of an image that thumbnails decodes, 25 million, e.g. 5000 by 5000. imgproxy refuses more than 16.8 million by default, to stop images that decode to more memory than their size suggests.

The most pixels of an image that thumbnails decodes, 25 million, e.g.
5000 by 5000. imgproxy refuses more than 16.8 million by default, to
stop images that decode to more memory than their size suggests.
sourceraw docstring

paletteclj/s

(palette b)
(palette b n)
(palette b n f)

At most n colours, by default 5, of the image in the bytes b, the most common first, as maps of the :colour and its :share of the opaque pixels. The quantiser f finds them, by default quantise/buckets, or e.g. quantise/k-means.

At most `n` colours, by default 5, of the image in the bytes `b`, the
most common first, as maps of the :colour and its :share of the opaque
pixels. The quantiser `f` finds them, by default quantise/buckets, or
e.g. quantise/k-means.
sourceraw docstring

pixelsclj/s

(pixels b)
(pixels b n)

The pixels of the image in the bytes b, decoded at about n pixels a side, by default 64 on the JVM and 32 in ClojureScript, as vectors of red, green, blue and alpha from 0 to 255. The bytes are a byte array on the JVM, and in ClojureScript a typed array, an ArrayBuffer or a Blob.

The pixels of the image in the bytes `b`, decoded at about `n` pixels a
side, by default 64 on the JVM and 32 in ClojureScript, as vectors of red,
green, blue and alpha from 0 to 255. The bytes are a byte array on the
JVM, and in ClojureScript a typed array, an ArrayBuffer or a Blob.
sourceraw docstring

schemeclj/s

(scheme palette)

The colours of a UI by the colours of an image, its palette, the most common first: a map of these, or nil for an empty palette.

  • :background, the most common colour, to tint by
  • :text, black or white, whichever reads better on the background
  • :accent, for controls, e.g. a progress bar: the first other colour whose contrast with the background is 3:1, which WCAG 2.2 asks of a control, or else the complement when its contrast is, or else the text colour
  • :accent-text, black or white, whichever reads better on the accent
  • :complement, the background's hue turned halfway round in HSL
  • :seed, the first colour with a hue, by choose/seed, or nil
  • :palette, the colours of the palette
The colours of a UI by the colours of an image, its `palette`, the most
common first: a map of these, or nil for an empty palette.

- :background, the most common colour, to tint by
- :text, black or white, whichever reads better on the background
- :accent, for controls, e.g. a progress bar: the first other colour
  whose contrast with the background is 3:1, which WCAG 2.2 asks of a
  control, or else the complement when its contrast is, or else the text
  colour
- :accent-text, black or white, whichever reads better on the accent
- :complement, the background's hue turned halfway round in HSL
- :seed, the first colour with a hue, by choose/seed, or nil
- :palette, the colours of the palette
sourceraw docstring

seedclj/s

(seed b)

The colour of the image in the bytes b to derive the colours of a UI from: the most common of its five commonest colours that has a hue, or nil where they're all about grey.

The colour of the image in the bytes `b` to derive the colours of a UI
from: the most common of its five commonest colours that has a hue, or
nil where they're all about grey.
sourceraw docstring

thenclj/s

(then x f)

What f returns for x, unless x is nil, or in ClojureScript a promise of what it returns for the value of the promise x.

What `f` returns for `x`, unless `x` is nil, or in ClojureScript a promise
of what it returns for the value of the promise `x`.
sourceraw docstring

thumbnailsclj/s

(thumbnails b widths)
(thumbnails b widths opts)

The image in the bytes b scaled down to each of the widths, with the :max-pixels of opts, as a map of each width to the thumbnail's :type, :width, :height and :data, its bytes. On the JVM it returns the map, and in ClojureScript a promise of it.

A thumbnail is a JPEG, or a PNG when the image has transparency. It's never wider than the image: the widths at or above the image's own share one thumbnail, the image at its own width.

The platform decodes the image: ImageIO on the JVM, which reads JPEG, PNG, GIF and BMP, and the browser's own decoder in ClojureScript. The map is nil where it can't, e.g. for WebP on the JVM, or anything in Node, and for these:

  • an animated GIF on the JVM. A browser scales its first frame.
  • an image of more than :max-pixels, by default max-pixels. ImageIO reads the size before it decodes the image, but a browser decodes the whole image first.

ImageIO ignores the EXIF orientation of a JPEG, so check it first where it matters.

The image in the bytes `b` scaled down to each of the `widths`, with the
:max-pixels of `opts`, as a map of each width to the thumbnail's :type,
:width, :height and :data, its bytes. On the JVM it returns the map, and
in ClojureScript a promise of it.

A thumbnail is a JPEG, or a PNG when the image has transparency. It's
never wider than the image: the widths at or above the image's own share
one thumbnail, the image at its own width.

The platform decodes the image: ImageIO on the JVM, which reads JPEG,
PNG, GIF and BMP, and the browser's own decoder in ClojureScript. The map
is nil where it can't, e.g. for WebP on the JVM, or anything in Node, and
for these:

- an animated GIF on the JVM. A browser scales its first frame.
- an image of more than :max-pixels, by default max-pixels. ImageIO
  reads the size before it decodes the image, but a browser decodes the
  whole image first.

ImageIO ignores the EXIF orientation of a JPEG, so check it first where
it matters.
sourceraw docstring

with-bitmapcljs

(with-bitmap b f)

A promise of what f returns for an ImageBitmap of the image in the bytes b, or of nil where the browser can't decode the image or f throws, e.g. in Node, which has no decoder. The bitmap is closed once f returns, or once the promise that it returns settles.

A promise of what `f` returns for an ImageBitmap of the image in the
bytes `b`, or of nil where the browser can't decode the image or `f`
throws, e.g. in Node, which has no decoder. The bitmap is closed once
`f` returns, or once the promise that it returns settles.
sourceraw docstring

with-readerclj

(with-reader b f)

What f returns for an ImageReader of the image in the bytes b, or nil when ImageIO can't read the image or f throws. The reader has read no pixels yet, so f can check the size of the image first.

What `f` returns for an ImageReader of the image in the bytes `b`, or
nil when ImageIO can't read the image or `f` throws. The reader has
read no pixels yet, so `f` can check the size of the image first.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close