Files
chrnxandClaude Opus 5 f859780eaa feat: add atmosphere backdrops and shipped placeholders
About and Projects had a figure floating on a CSS gradient while Music
and Podcasts had a whole world behind theirs. They get their own
landscape backdrop, which is what made the four read as one series.

Adds placeholder art for a release without a cover and a post without a
featured image, composited over the per-topic accent so a grid of
missing images still varies. Tracks borrow their album cover first.

The generated inventory grows to 76 files. Placeholders encode at lower
quality because they sit at half opacity behind text, which kept the
payload inside its budget instead of raising it again.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-13 19:41:48 -05:00

84 lines
4.6 KiB
PHP

<?php
/**
* Responsive theme-owned media helpers.
*
* @package CHRNX
*/
/**
* Render an allowlisted topic portrait using modern derivatives and a PNG fallback.
*
* @param string $topic_slug Topic slug.
* @param string $alt Alternative text. Empty is valid for decorative art.
* @param string $class_name Optional image class.
* @param string $loading Either lazy (default) or eager for above-fold art.
* @return string Safe picture markup or an empty string.
*/
function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '', string $class_name = '', string $loading = 'lazy' ): string {
$source = chrnx_get_topic_art_asset( $topic_slug );
$dimensions = chrnx_get_topic_art_dimensions( $topic_slug );
if ( '' === $source || 2 !== count( $dimensions ) ) {
return '';
}
$basename = pathinfo( $source, PATHINFO_FILENAME );
$base_uri = get_theme_file_uri( 'assets/images/generated/' . $basename );
$sizes = '(max-width: 599px) 70vw, 384px';
$split_classes = preg_split( '/\s+/', trim( $class_name ) );
$classes = is_array( $split_classes ) ? array_filter( $split_classes ) : array();
$class = implode( ' ', array_map( 'sanitize_html_class', $classes ) );
$decorative = '' === $alt ? ' aria-hidden="true"' : '';
$loading = 'eager' === $loading ? 'eager' : 'lazy';
$priority = 'eager' === $loading ? ' fetchpriority="high"' : '';
if ( 'music-collage' === $topic_slug ) {
$sizes = '(max-width: 599px) 100vw, 720px';
}
$markup = '<picture class="chrnx-responsive-portrait"' . $decorative . '>';
$markup .= '<source type="image/avif" srcset="' . esc_url( $base_uri . '-384.avif' ) . ' 384w, ' . esc_url( $base_uri . '-768.avif' ) . ' 768w" sizes="' . esc_attr( $sizes ) . '">';
$markup .= '<source type="image/webp" srcset="' . esc_url( $base_uri . '-384.webp' ) . ' 384w, ' . esc_url( $base_uri . '-768.webp' ) . ' 768w" sizes="' . esc_attr( $sizes ) . '">';
// The fallback is the 768 WebP, not the multi-megabyte master: every browser
// that renders <picture> has supported WebP since 2020, and shipping design
// masters as a runtime fallback cost megabytes per image.
$markup .= '<img' . ( '' !== $class ? ' class="' . esc_attr( $class ) . '"' : '' ) . ' src="' . esc_url( $base_uri . '-768.webp' ) . '" width="' . esc_attr( $dimensions[0] ) . '" height="' . esc_attr( $dimensions[1] ) . '" loading="' . esc_attr( $loading ) . '"' . $priority . ' decoding="async" sizes="' . esc_attr( $sizes ) . '" alt="' . esc_attr( $alt ) . '">';
$markup .= '</picture>';
return $markup;
}
/**
* Render an allowlisted decorative atmosphere using modern opaque derivatives.
*
* @param string $asset_key Fixed atmosphere key.
* @param string $class_name Optional image class.
* @return string Safe picture markup or an empty string.
*/
function chrnx_get_atmosphere_markup( string $asset_key, string $class_name = '' ): string {
if ( ! in_array( $asset_key, array( 'podcast-frequency', 'about-grunge', 'projects-grunge' ), true ) ) {
return '';
}
$source = chrnx_get_topic_art_asset( $asset_key );
$dimensions = chrnx_get_topic_art_dimensions( $asset_key );
if ( '' === $source || 2 !== count( $dimensions ) ) {
return '';
}
$basename = pathinfo( $source, PATHINFO_FILENAME );
$base_uri = get_theme_file_uri( 'assets/images/generated/' . $basename );
$sizes = '(max-width: 780px) 100vw, 1200px';
$split_classes = preg_split( '/\s+/', trim( $class_name ) );
$classes = is_array( $split_classes ) ? array_filter( $split_classes ) : array();
$class = implode( ' ', array_map( 'sanitize_html_class', $classes ) );
$loading = 'lazy';
$alt = '';
$markup = '<picture class="chrnx-responsive-atmosphere" aria-hidden="true">';
$markup .= '<source type="image/avif" srcset="' . esc_url( $base_uri . '-384.avif' ) . ' 384w, ' . esc_url( $base_uri . '-768.avif' ) . ' 768w, ' . esc_url( $base_uri . '-1536.avif' ) . ' 1536w" sizes="' . esc_attr( $sizes ) . '">';
$markup .= '<source type="image/webp" srcset="' . esc_url( $base_uri . '-384.webp' ) . ' 384w, ' . esc_url( $base_uri . '-768.webp' ) . ' 768w, ' . esc_url( $base_uri . '-1536.webp' ) . ' 1536w" sizes="' . esc_attr( $sizes ) . '">';
$markup .= '<img' . ( '' !== $class ? ' class="' . esc_attr( $class ) . '"' : '' ) . ' src="' . esc_url( $base_uri . '-1536.webp' ) . '" width="' . esc_attr( $dimensions[0] ) . '" height="' . esc_attr( $dimensions[1] ) . '" loading="' . esc_attr( $loading ) . '" decoding="async" sizes="' . esc_attr( $sizes ) . '" alt="' . esc_attr( $alt ) . '">';
$markup .= '</picture>';
return $markup;
}