Backport asynchronous thumbnail generation from Kabuki.
This commit is contained in:
@@ -76,11 +76,11 @@ class EditAsset extends HTMLController
|
||||
$image->removeAllThumbnails();
|
||||
}
|
||||
}
|
||||
elseif (preg_match('~^thumb_(\d+)x(\d+)(_c[best]?)?$~', $_POST['replacement_target']))
|
||||
elseif (preg_match('~^thumb_(\d+x\d+(?:_c[best]?)?)$~', $_POST['replacement_target'], $match))
|
||||
{
|
||||
$image = $asset->getImage();
|
||||
if (($replace_result = $image->replaceThumbnail($_POST['replacement_target'], $_FILES['replacement']['tmp_name'])) !== 0)
|
||||
throw new Exception('Could not replace thumbnail \'' . $_POST['replacement_target'] . '\' with the uploaded file. Error code: ' . $replace_result);
|
||||
if (($replace_result = $image->replaceThumbnail($match[1], $_FILES['replacement']['tmp_name'])) !== 0)
|
||||
throw new Exception('Could not replace thumbnail \'' . $match[1] . '\' with the uploaded file. Error code: ' . $replace_result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,12 +97,18 @@ class EditAsset extends HTMLController
|
||||
|
||||
private function getThumbs(Asset $asset)
|
||||
{
|
||||
$path = $asset->getPath();
|
||||
if (!$asset->isImage())
|
||||
return [];
|
||||
|
||||
$image = $asset->getImage();
|
||||
$subdir = $image->getSubdir();
|
||||
$metadata = $image->getMeta();
|
||||
$thumb_selectors = $image->getThumbnails();
|
||||
|
||||
$thumbs = [];
|
||||
$metadata = $asset->getMeta();
|
||||
foreach ($metadata as $key => $meta)
|
||||
foreach ($thumb_selectors as $selector => $filename)
|
||||
{
|
||||
if (!preg_match('~^thumb_(?<width>\d+)x(?<height>\d+)(?<suffix>_c(?<method>[best]?))?$~', $key, $thumb))
|
||||
if (!preg_match('~^(?<width>\d+)x(?<height>\d+)(?<suffix>_c(?<method>[best]?))?$~', $selector, $thumb))
|
||||
continue;
|
||||
|
||||
$has_crop_boundary = isset($metadata['crop_' . $thumb['width'] . 'x' . $thumb['height']]);
|
||||
@@ -113,10 +119,10 @@ class EditAsset extends HTMLController
|
||||
'crop_method' => !$has_custom_image && !empty($thumb['method']) ? $thumb['method'] : (!empty($thumb['suffix']) ? 'c' : null),
|
||||
'crop_region' => $has_crop_boundary ? $metadata['crop_' . $thumb['width'] . 'x' . $thumb['height']] : null,
|
||||
'custom_image' => $has_custom_image,
|
||||
'filename' => $meta,
|
||||
'full_path' => THUMBSDIR . '/' . $path . '/' . $meta,
|
||||
'url' => THUMBSURL . '/' . $path . '/' . $meta,
|
||||
'status' => file_exists(THUMBSDIR . '/' . $path . '/' . $meta),
|
||||
'filename' => $filename,
|
||||
'full_path' => THUMBSDIR . '/' . $subdir . '/' . $filename,
|
||||
'url' => THUMBSURL . '/' . $subdir . '/' . $filename,
|
||||
'status' => file_exists(THUMBSDIR . '/' . $subdir . '/' . $filename),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user