The header of an image file, which is what a check of artwork needs.
The header gives the type of the image, its size in pixels, its color model and whether it can be transparent. The reader takes them from the first bytes and doesn't decode the image. It reads these formats:
A reading takes a view of the parts of the file at hand, as in dk.simongray.podcast.util.bytes.view, and gives the header, or the ranges that it still needs. An image embedded in text, e.g. the artwork of a chapter, is a data URL, which data-url and from-data-url write and read. Only colors, palette and dominant-color decode an image, through the platform, for the colours that an app can colour its UI by.
The header of an image file, which is what a check of artwork needs. The header gives the type of the image, its size in pixels, its color model and whether it can be transparent. The reader takes them from the first bytes and doesn't decode the image. It reads these formats: - PNG, by the W3C PNG specification - JPEG, by ITU-T T.81 - GIF87a and GIF89a - WebP, by RFC 9649, with the VP8 frame header of RFC 6386, section 9.1 A reading takes a view of the parts of the file at hand, as in dk.simongray.podcast.util.bytes.view, and gives the header, or the ranges that it still needs. An image embedded in text, e.g. the artwork of a chapter, is a data URL, which data-url and from-data-url write and read. Only colors, palette and dominant-color decode an image, through the platform, for the colours that an app can colour its UI by.
(colors b)The colours for an app to colour its UI by the image in the bytes b,
e.g. the artwork of a show, as a map. On the JVM it gives the map, and
in ClojureScript a promise of it.
{:background "#a90000" ; the dominant colour, to tint by
:text "#ffffff" ; black or white, whichever reads better
:accent "#e8c070" ; for controls, e.g. a progress bar
:accent-text "#000000" ; for text on the accent
:complement "#00a9a9" ; the opposite hue of the background
:palette ["#a90000" …]} ; the most common colours, most first
The accent is the first other colour of the palette that stands apart from the background by a contrast of 3:1, as WCAG 2.2 asks of controls, or else the complement when it does, or else the text colour. The map is nil where the platform can't decode the image, as dominant-color says.
The colours for an app to colour its UI by the image in the bytes `b`,
e.g. the artwork of a show, as a map. On the JVM it gives the map, and
in ClojureScript a promise of it.
{:background "#a90000" ; the dominant colour, to tint by
:text "#ffffff" ; black or white, whichever reads better
:accent "#e8c070" ; for controls, e.g. a progress bar
:accent-text "#000000" ; for text on the accent
:complement "#00a9a9" ; the opposite hue of the background
:palette ["#a90000" …]} ; the most common colours, most first
The accent is the first other colour of the palette that stands apart
from the background by a contrast of 3:1, as WCAG 2.2 asks of controls,
or else the complement when it does, or else the text colour. The map is
nil where the platform can't decode the image, as dominant-color says.(complementary-color hex)The complement of the CSS hex colour hex, #rrggbb: the colour of the
opposite hue, e.g. #00a9a9 of #a90000, or nil when hex isn't one. A
grey has no hue, so it's its own complement.
The complement of the CSS hex colour `hex`, #rrggbb: the colour of the opposite hue, e.g. #00a9a9 of #a90000, or nil when `hex` isn't one. A grey has no hue, so it's its own complement.
(contrast-color hex)Black or white, whichever reads better as text on the CSS hex colour
hex, #rrggbb, by the contrast ratio of WCAG 2.2, or nil when hex
isn't one. A tie goes to white, as with contrast-color() of CSS.
Black or white, whichever reads better as text on the CSS hex colour `hex`, #rrggbb, by the contrast ratio of WCAG 2.2, or nil when `hex` isn't one. A tie goes to white, as with contrast-color() of CSS.
(data-url type b)The bytes b of the MIME type type as a data URL, which a browser
shows as an image source.
The bytes `b` of the MIME type `type` as a data URL, which a browser shows as an image source.
(dominant-color b)The colour that most of the image in the bytes b has, as a CSS hex
colour, e.g. #1e3a5f, for a player to tint its screen by the artwork.
On the JVM it gives the colour, and in ClojureScript a promise of it.
The platform decodes the image at a small size: ImageIO on the JVM, and the browser's own decoder in ClojureScript. The colour 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.
The colour that most of the image in the bytes `b` has, as a CSS hex colour, e.g. #1e3a5f, for a player to tint its screen by the artwork. On the JVM it gives the colour, and in ClojureScript a promise of it. The platform decodes the image at a small size: ImageIO on the JVM, and the browser's own decoder in ClojureScript. The colour 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.
(from-data-url s)The MIME type and the bytes of the data URL s as a map of :type and
:data, or nil for a text that isn't a data URL. A data URL without a
type is text/plain;charset=US-ASCII.
The MIME type and the bytes of the data URL `s` as a map of :type and :data, or nil for a text that isn't a data URL. A data URL without a type is text/plain;charset=US-ASCII.
(palette b)(palette b n)The colours that the most of the image in the bytes b has, at most
n, by default 5, the most common first, as CSS hex colours. On the JVM
it gives them, and in ClojureScript a promise of them. They're nil
where the platform can't decode the image, as dominant-color says.
The colours that the most of the image in the bytes `b` has, at most `n`, by default 5, the most common first, as CSS hex colours. On the JVM it gives them, and in ClojureScript a promise of them. They're nil where the platform can't decode the image, as dominant-color says.
(read view)The header of the image whose parts view holds, as a map of :type,
:width, :height, :color and :alpha?.
A JPEG also gives:
The height of a JPEG is absent when the image gives it only after its data. AVIF, HEIC, HEIF, SVG, BMP, TIFF and ICO give their :type alone, since the reader doesn't read their headers.
When the view lacks bytes, the result has the ranges that the reading needs under :need, as pairs of start and end. For an image that doesn't read, the report tells why, and the result has the :type when the first bytes tell it.
The header of the image whose parts `view` holds, as a map of :type, :width, :height, :color and :alpha?. - :type is a MIME type - :width and :height are in pixels - :color is the color model: :rgb, :indexed, :grayscale or :cmyk - :alpha? is whether the image has transparent pixels, or nil when the header doesn't tell, as for a GIF A JPEG also gives: - :process, the coding process, which is a value of frame-markers - :progressive? - :bits, the sample precision - :orientation, the EXIF orientation, 1 to 8 The height of a JPEG is absent when the image gives it only after its data. AVIF, HEIC, HEIF, SVG, BMP, TIFF and ICO give their :type alone, since the reader doesn't read their headers. When the view lacks bytes, the result has the ranges that the reading needs under :need, as pairs of start and end. For an image that doesn't read, the report tells why, and the result has the :type when the first bytes tell it.
(read! url)(read! url opts)Read the header of the image at url, fetched with opts. On the JVM
it gives the result, and in ClojureScript a promise of it.
The reading most often needs the first 64 KB alone. The opts are
these:
url only
names the file in an errorNothing that the network or the server does throws. When a request fails, the result has a :file/unreachable diagnostic under :error.
Read the header of the image at `url`, fetched with `opts`. On the JVM it gives the result, and in ClojureScript a promise of it. The reading most often needs the first 64 KB alone. The `opts` are these: - :fetch, a function as http/fetcher makes, or for a local file one that ranges/file-fetcher or ranges/blob-fetcher makes, when `url` only names the file in an error - :headers, :timeout-seconds and :send, as http/fetcher takes them - :allow-pred and :user-agent, as http/send! takes them - the limits of ranges/read!, with ranges/default-limits for those that they don't set Nothing that the network or the server does throws. When a request fails, the result has a :file/unreachable diagnostic under :error.
(report image)The diagnostics of the read image. Each diagnostic has its message.
The diagnostics of the read `image`. Each diagnostic has its message.
(sniff b)The MIME type of the image whose bytes b begin as a JPEG, PNG, GIF or
WebP image begins, or nil for other bytes.
The MIME type of the image whose bytes `b` begin as a JPEG, PNG, GIF or WebP image begins, or nil for other bytes.
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 |