LanguageValues and typesStandard typesMedia and visual
ImageDimensions
On this page
An image's width and height in pixels: 1920x1080.
Use it for photos and pictures. media.fit scales one to fit inside another. For video, use VideoResolution. For a physical box, use Dimensions.
Shape
| Field | Type | Required? |
|---|---|---|
width |
Int |
Yes |
height |
Int |
Yes |
Example
ImageDimensions { width: 1920 height: 1080 }text.parse(raw, as: ImageDimensions) reads one from text that comes from outside. Text that isn't one at all fails malformed, such as 0x1080, 1920x0 or 1920X1080.
This operation gives one: media.fit.
Good to know
- Each side must be at least 1.
==tells you whether two are the same.<andlist.sort_bydon't take it, so sort by one of its parts instead.
In JSON
An object of its parts, in a request, a response or json.write:
{"width":1,"height":1}{"width":4000,"height":3000}{"width":320,"height":240}
Details
Text form, storage, how it is shown, and operations
ImageDimensions is in the group Media and visual, and has been in Jadpo since 0.1.0.
Text form
text.from writes one standard text form, the same form text.parse reads back: 1x1, 4000x3000 and 320x240.
How it is stored
It is stored in 2 columns, each named for the field, _ and its suffix. This is 320x240:
| Column | Type | Holds |
|---|---|---|
<field>_width |
integer |
320 |
<field>_height |
integer |
240 |
How it is shown to people
text.format(value, locale:) shows it to people in their locale.
With locale: Locale.en_gb:
| Value | Shown |
|---|---|
1x1 |
1x1 |
4000x3000 |
4000x3000 |
320x240 |
320x240 |
2147483647x1 |
2147483647x1 |
Operations
media.fit(dimensions: ImageDimensions, within: ImageDimensions) -> ImageDimensions:dimensionsscaled to fit insidewithin, keeping its aspect ratio and never made larger, each side rounded down to a whole pixel and never below 1, as CSS'sobject-fit: scale-downfits an image:media.fit(photo, within: tile).
It also takes text.parse, text.from, text.format, json.read, json.write and ==. How every standard type behaves says how they work.
Markdown for agents: /docs/types/type-image-dimensions.md.Built from Jadpo main at aee2e8f.