Merge pull request 'Make crop editor usable' (#22) from crop-editor into master

Reviewed-on: #22
This commit was merged in pull request #22.
This commit is contained in:
2020-12-30 20:06:15 +01:00
7 changed files with 461 additions and 242 deletions

View File

@@ -133,9 +133,9 @@ class Image extends Asset
public function removeAllThumbnails()
{
foreach ($this->thumbnails as $key => $value)
foreach ($this->thumbnails as $key => $filename)
{
$thumb_path = THUMBSDIR . '/' . $this->subdir . '/' . $value;
$thumb_path = THUMBSDIR . '/' . $this->subdir . '/' . $filename;
if (is_file($thumb_path))
unlink($thumb_path);
}
@@ -146,6 +146,30 @@ class Image extends Asset
['id_asset' => $this->id_asset]);
}
public function removeThumbnailsOfSize($width, $height)
{
foreach ($this->thumbnails as $key => $filename)
{
if (strpos($key, $width . 'x' . $height) !== 0)
continue;
$thumb_path = THUMBSDIR . '/' . $this->subdir . '/' . $filename;
if (is_file($thumb_path))
unlink($thumb_path);
}
return Registry::get('db')->query('
DELETE FROM assets_thumbs
WHERE id_asset = {int:id_asset} AND
width = {int:width} AND
height = {int:height}',
[
'height' => $height,
'id_asset' => $this->id_asset,
'width' => $width,
]);
}
public function replaceThumbnail($descriptor, $tmp_file)
{
if (!is_file($tmp_file))

View File

@@ -164,6 +164,8 @@ class Thumbnail
$this->filename_suffix .= 's';
elseif ($this->crop_mode === self::CROP_MODE_SLICE_BOTTOM)
$this->filename_suffix .= 'b';
elseif ($this->crop_mode === self::CROP_MODE_BOUNDARY)
$this->filename_suffix .= 'e';
}
else
$this->filename_suffix = '';