ContextImages
in package
1-1 course branding images on lti_context (hero 16:9 + square icon).
Bytes live in context_images, not dataroot / blob_file. List queries must not SELECT the MEDIUMBLOB columns; serve each kind from its own endpoint. Browser JS constructs JPEG to these specs; PHP re-constructs and verifies.
Table of Contents
Constants
- HERO_HEIGHT : mixed = 720
- HERO_MAX_BYTES : mixed = 204800
- HERO_MIN_EDGE : mixed = 360
- HERO_WIDTH : mixed = 1280
- ICON_HEIGHT : mixed = 512
- ICON_MAX_BYTES : mixed = 51200
- ICON_MIN_EDGE : mixed = 128
- ICON_WIDTH : mixed = 512
- KIND_HERO : mixed = 'hero'
- KIND_ICON : mixed = 'icon'
- MIME : mixed = 'image/jpeg'
Methods
- blob() : array{bytes: string, mime: string, updated_at: ?string}|null
- One kind's bytes. Does not SELECT the other BLOB.
- clear() : string|null
- constructJpeg() : array{bytes: string, mime: string, width: int, height: int}|string
- Cover-crop PNG/JPEG to the kind's exact size and encode JPEG under max bytes.
- coverCropRect() : array{sx: int, sy: int, sw: int, sh: int}
- Source rectangle for CSS object-fit: cover into $dstW × $dstH.
- heroPlaceholderSeed() : array{id: int, palette: int, variant: int, a: int, b: int, c: int}
- Stable seed so each course gets its own placeholder look.
- heroPlaceholderSvg() : mixed
- Decorative 16×9 SVG for an empty hero. Title is HTML overlay, not in the SVG.
- initialsAvatarSvg() : string
- Same decorative art as an empty course hero, cropped to a circle with initials on top.
- isKind() : mixed
- metadata() : array<string, mixed>
- Metadata only (no BLOBs). Missing row → empty flags.
- save() : string|null
- Insert or update one kind. Leaves the other image alone.
- servedUrl() : mixed
- Versioned, session-safe URL when this kind has stored bytes.
- spec() : array<string, mixed>|null
- url() : mixed
- Public URL for a served image (versioned for browser cache).
- heroPalettes() : array<int, array{0: string, 1: string, 2: string}>
- heroPlaceholderArt() : mixed
- heroPlaceholderInner() : string
- Gradient, shapes, and scrim for one hero seed. No outer svg element.
- jpegUnderLimit() : string
Constants
HERO_HEIGHT
public
mixed
HERO_HEIGHT
= 720
HERO_MAX_BYTES
public
mixed
HERO_MAX_BYTES
= 204800
HERO_MIN_EDGE
public
mixed
HERO_MIN_EDGE
= 360
HERO_WIDTH
public
mixed
HERO_WIDTH
= 1280
ICON_HEIGHT
public
mixed
ICON_HEIGHT
= 512
ICON_MAX_BYTES
public
mixed
ICON_MAX_BYTES
= 51200
ICON_MIN_EDGE
public
mixed
ICON_MIN_EDGE
= 128
ICON_WIDTH
public
mixed
ICON_WIDTH
= 512
KIND_HERO
public
mixed
KIND_HERO
= 'hero'
KIND_ICON
public
mixed
KIND_ICON
= 'icon'
MIME
public
mixed
MIME
= 'image/jpeg'
Methods
blob()
One kind's bytes. Does not SELECT the other BLOB.
public
static blob(mixed $context_id, mixed $kind) : array{bytes: string, mime: string, updated_at: ?string}|null
Parameters
- $context_id : mixed
- $kind : mixed
Return values
array{bytes: string, mime: string, updated_at: ?string}|nullclear()
public
static clear(mixed $context_id, mixed $kind) : string|null
Parameters
- $context_id : mixed
- $kind : mixed
Return values
string|null —Error message
constructJpeg()
Cover-crop PNG/JPEG to the kind's exact size and encode JPEG under max bytes.
public
static constructJpeg(mixed $path, mixed $kind) : array{bytes: string, mime: string, width: int, height: int}|string
Parameters
- $path : mixed
- $kind : mixed
Return values
array{bytes: string, mime: string, width: int, height: int}|string —Error message
coverCropRect()
Source rectangle for CSS object-fit: cover into $dstW × $dstH.
public
static coverCropRect(mixed $srcW, mixed $srcH, mixed $dstW, mixed $dstH) : array{sx: int, sy: int, sw: int, sh: int}
Parameters
- $srcW : mixed
- $srcH : mixed
- $dstW : mixed
- $dstH : mixed
Return values
array{sx: int, sy: int, sw: int, sh: int}heroPlaceholderSeed()
Stable seed so each course gets its own placeholder look.
public
static heroPlaceholderSeed(mixed $context_id) : array{id: int, palette: int, variant: int, a: int, b: int, c: int}
Parameters
- $context_id : mixed
Return values
array{id: int, palette: int, variant: int, a: int, b: int, c: int}heroPlaceholderSvg()
Decorative 16×9 SVG for an empty hero. Title is HTML overlay, not in the SVG.
public
static heroPlaceholderSvg(mixed $context_id) : mixed
Parameters
- $context_id : mixed
initialsAvatarSvg()
Same decorative art as an empty course hero, cropped to a circle with initials on top.
public
static initialsAvatarSvg(int $seed, string $initials) : string
Parameters
- $seed : int
-
Passed through heroPlaceholderSeed() so each person gets a stable pattern.
- $initials : string
Return values
stringisKind()
public
static isKind(mixed $kind) : mixed
Parameters
- $kind : mixed
metadata()
Metadata only (no BLOBs). Missing row → empty flags.
public
static metadata(mixed $context_id) : array<string, mixed>
Parameters
- $context_id : mixed
Return values
array<string, mixed>save()
Insert or update one kind. Leaves the other image alone.
public
static save(mixed $context_id, mixed $kind, mixed $bytes) : string|null
Parameters
- $context_id : mixed
- $kind : mixed
- $bytes : mixed
Return values
string|null —Error message
servedUrl()
Versioned, session-safe URL when this kind has stored bytes.
public
static servedUrl(mixed $context_id, mixed $kind, mixed $nbytes[, mixed $updated_at = null ]) : mixed
Parameters
- $context_id : mixed
- $kind : mixed
- $nbytes : mixed
- $updated_at : mixed = null
spec()
public
static spec(mixed $kind) : array<string, mixed>|null
Parameters
- $kind : mixed
Return values
array<string, mixed>|nullurl()
Public URL for a served image (versioned for browser cache).
public
static url(mixed $context_id, mixed $kind[, mixed $updated_at = null ]) : mixed
Parameters
- $context_id : mixed
- $kind : mixed
- $updated_at : mixed = null
heroPalettes()
private
static heroPalettes() : array<int, array{0: string, 1: string, 2: string}>
Return values
array<int, array{0: string, 1: string, 2: string}>heroPlaceholderArt()
private
static heroPlaceholderArt(mixed $uid, array{0: string, 1: string, 2: string} $p, array{id: int, palette: int, variant: int, a: int, b: int, c: int} $seed) : mixed
Parameters
- $uid : mixed
- $p : array{0: string, 1: string, 2: string}
- $seed : array{id: int, palette: int, variant: int, a: int, b: int, c: int}
heroPlaceholderInner()
Gradient, shapes, and scrim for one hero seed. No outer svg element.
private
static heroPlaceholderInner(int $context_id) : string
Parameters
- $context_id : int
Return values
stringjpegUnderLimit()
private
static jpegUnderLimit(mixed $im, mixed $maxBytes) : string
Parameters
- $im : mixed
- $maxBytes : mixed
Return values
string —JPEG bytes, or error message