mirror of
https://github.com/getgrav/grav.git
synced 2026-06-26 14:50:16 +02:00
Thumbnails need to be images, other minor fixes
This commit is contained in:
@@ -23,11 +23,11 @@ class MediaIndex
|
||||
|
||||
/** @var string */
|
||||
protected $filepath;
|
||||
/** @var array */
|
||||
/** @var array|null */
|
||||
protected $indexes;
|
||||
/** @var int */
|
||||
protected $modified = 0;
|
||||
/** @var JsonFile */
|
||||
/** @var JsonFile|null */
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
namespace Grav\Common\Media\Traits;
|
||||
|
||||
use Grav\Common\Data\Data;
|
||||
use Grav\Common\Media\Interfaces\ImageMediaInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaFileInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaLinkInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaObjectInterface;
|
||||
use Grav\Common\Page\Medium\ImageMedium;
|
||||
use Grav\Common\Page\Medium\ThumbnailImageMedium;
|
||||
use Grav\Common\Utils;
|
||||
use RuntimeException;
|
||||
@@ -611,9 +611,9 @@ trait MediaObjectTrait
|
||||
/**
|
||||
* Get the thumbnail Medium object
|
||||
*
|
||||
* @return ThumbnailImageMedium|ImageMedium
|
||||
* @return ImageMediaInterface
|
||||
*/
|
||||
protected function getThumbnail(): ImageMedium
|
||||
protected function getThumbnail(): ImageMediaInterface
|
||||
{
|
||||
if (null === $this->_thumbnail) {
|
||||
$thumbnails = (array)$this->get('thumbnails') + ['system' => 'system://images/media/thumb.png'];
|
||||
@@ -646,6 +646,10 @@ trait MediaObjectTrait
|
||||
throw new RuntimeException(sprintf("Default thumbnail image '%s' does not exist!", $thumbnails['system']), 500);
|
||||
}
|
||||
|
||||
if (!$image instanceof ImageMediaInterface) {
|
||||
throw new RuntimeException(sprintf("Thumbnail '%s' is not an image", $image->filepath), 500);
|
||||
}
|
||||
|
||||
$image->set('parent', $this);
|
||||
$this->_thumbnail = $image;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
|
||||
'retina_scale' => (int)$config->get('system.images.cls.retina_scale', 1)
|
||||
];
|
||||
|
||||
$this->imageSettings = $this->defaults;
|
||||
$this->quality = $this->defaults['quality'];
|
||||
|
||||
$this->def('debug', $config->get('system.images.debug'));
|
||||
|
||||
$path = $this->get('filepath');
|
||||
@@ -125,9 +128,12 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
|
||||
{
|
||||
parent::reset();
|
||||
|
||||
/** @var Config $config */
|
||||
$config = $this->getGrav()['config'];
|
||||
|
||||
$this->format = 'guess';
|
||||
$this->imageSettings = $this->defaults;
|
||||
$this->quality = $this->defaults['quality'] ?? 80;
|
||||
$this->quality = $this->defaults['quality'] ?? (int)$config->get('system.images.default_image_quality', 85);
|
||||
|
||||
$this->resetImage();
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ namespace Grav\Common\Page\Medium;
|
||||
|
||||
use Grav\Common\File\CompiledYamlFile;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Media\Interfaces\ImageMediaInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaCollectionInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaFileInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaLinkInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaObjectInterface;
|
||||
use Grav\Common\Media\Traits\MediaFileTrait;
|
||||
use Grav\Common\Media\Traits\MediaObjectTrait;
|
||||
use JsonSerializable;
|
||||
@@ -178,11 +178,17 @@ class Medium implements RenderableInterface, MediaFileInterface, JsonSerializabl
|
||||
|
||||
/**
|
||||
* @param string $thumb
|
||||
* @return MediaObjectInterface|null
|
||||
* @return ImageMediaInterface|null
|
||||
* @phpstan-impure
|
||||
*/
|
||||
protected function createThumbnail(string $thumb): ?MediaObjectInterface
|
||||
protected function createThumbnail(string $thumb): ?ImageMediaInterface
|
||||
{
|
||||
return $this->getMedia()->createFromFile($thumb, ['type' => 'thumbnail']);
|
||||
$thumbnail = $this->getMedia()->createFromFile($thumb, ['type' => 'thumbnail']);
|
||||
if (!$thumbnail instanceof ImageMediaInterface) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $thumbnail;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user