Skip to content

Commit

Permalink
Fix crop condition
Browse files Browse the repository at this point in the history
Make sure that when fetching the image from the cache we don't
accidentally fetch the cropped image just because it also start with
256-256

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed May 19, 2022
1 parent cdd1793 commit a7adfa6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public function generatePreviews(File $file, array $specifications, $mimeType =
&& ($specifications[0]['width'] <= 256 || $specifications[0]['height'] <= 256)
&& preg_match(Imaginary::supportedMimeTypes(), $mimeType)
&& $this->config->getSystemValueString('preview_imaginary_url', 'invalid') !== 'invalid') {

$crop = $specifications[0]['crop'] ?? false;
$preview = $this->getSmallImagePreview($previewFolder, $file, $mimeType, $previewVersion, $crop);

Expand Down Expand Up @@ -233,9 +232,17 @@ private function getSmallImagePreview(ISimpleFolder $previewFolder, File $file,

foreach ($nodes as $node) {
$name = $node->getName();
if (($prefix === '' || strpos($name, $prefix) === 0)
&& (str_starts_with($name, '256-256-crop') && $crop || str_starts_with($name, '256-256') && !$crop)) {
return $node;
if (($prefix === '' || strpos($name, $prefix) === 0)) {
// Prefix match
if (str_starts_with($name, '256-256-crop') && $crop) {
// Cropped image
return $node;
}

if (str_starts_with($name, '256-256') && !str_starts_with($name, '256-256-crop') && !$crop) {
// Uncropped image
return $node;
}
}
}

Expand Down

0 comments on commit a7adfa6

Please sign in to comment.