Skip to content

Commit a49beb5

Browse files
committed
ImageProcessor: extract getSilhouetteUrl() for client-side fallback
Splits the silhouette URL construction out of getHighlightImageUrl() into its own public method so consumers can serve the silhouette as a client-side onerror fallback when a highlight image's media file is missing on disk — webtrees core's media-thumbnail endpoint 404s in that case instead of substituting a silhouette itself. getHighlightImageUrl() behaviour is preserved: when the silhouette branch fires, it now delegates to getSilhouetteUrl() instead of building the URL inline. Same gating (canShow + USE_SILHOUETTE).
1 parent e7f1a04 commit a49beb5

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

src/Processor/ImageProcessor.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,40 @@ public function getHighlightImageUrl(
6868
return $mediaFile->imageUrl($width, $height, 'contain');
6969
}
7070

71-
if (
72-
$returnSilhouettes
73-
&& ($this->individual->tree()->getPreference('USE_SILHOUETTE') !== '')
74-
) {
75-
return $this->module->assetUrl(
76-
sprintf(
77-
'images/silhouette-%s.svg',
78-
$this->individual->sex()
79-
)
80-
);
71+
if ($returnSilhouettes) {
72+
return $this->getSilhouetteUrl();
8173
}
8274
}
8375

8476
return '';
8577
}
78+
79+
/**
80+
* Returns the URL of the sex-specific silhouette image, intended as a
81+
* client-side fallback when a highlight image's media file is missing
82+
* (webtrees core's media-thumbnail endpoint 404s in that case instead
83+
* of substituting a silhouette itself).
84+
*
85+
* Returns an empty string when the individual cannot be shown or when
86+
* the tree has `USE_SILHOUETTE` disabled — same gating as the
87+
* silhouette branch in `getHighlightImageUrl()`.
88+
*
89+
* @return string
90+
*/
91+
public function getSilhouetteUrl(): string
92+
{
93+
if (
94+
$this->individual->canShow()
95+
&& ($this->individual->tree()->getPreference('USE_SILHOUETTE') !== '')
96+
) {
97+
return $this->module->assetUrl(
98+
sprintf(
99+
'images/silhouette-%s.svg',
100+
$this->individual->sex()
101+
)
102+
);
103+
}
104+
105+
return '';
106+
}
86107
}

0 commit comments

Comments
 (0)