mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Fixed PHP 8.1 issue in Media, minor optimization
This commit is contained in:
parent
4519971a76
commit
6af1ee48a5
|
|
@ -10,6 +10,7 @@
|
|||
namespace Grav\Common\Page;
|
||||
|
||||
use FilesystemIterator;
|
||||
use Grav\Common\Config\Config;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Media\Interfaces\MediaObjectInterface;
|
||||
use Grav\Common\Yaml;
|
||||
|
|
@ -86,11 +87,6 @@ class Media extends AbstractMedia
|
|||
*/
|
||||
protected function init()
|
||||
{
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = Grav::instance()['locator'];
|
||||
$config = Grav::instance()['config'];
|
||||
$exif_reader = isset(Grav::instance()['exif']) ? Grav::instance()['exif']->getReader() : false;
|
||||
$media_types = array_keys(Grav::instance()['config']->get('media.types'));
|
||||
$path = $this->getPath();
|
||||
|
||||
// Handle special cases where page doesn't exist in filesystem.
|
||||
|
|
@ -98,6 +94,17 @@ class Media extends AbstractMedia
|
|||
return;
|
||||
}
|
||||
|
||||
$grav = Grav::instance();
|
||||
|
||||
/** @var UniformResourceLocator $locator */
|
||||
$locator = $grav['locator'];
|
||||
|
||||
/** @var Config $config */
|
||||
$config = $grav['config'];
|
||||
|
||||
$exif_reader = isset($grav['exif']) ? $grav['exif']->getReader() : null;
|
||||
$media_types = array_keys($config->get('media.types', []));
|
||||
|
||||
$iterator = new FilesystemIterator($path, FilesystemIterator::UNIX_PATHS | FilesystemIterator::SKIP_DOTS);
|
||||
|
||||
$media = [];
|
||||
|
|
|
|||
|
|
@ -249,12 +249,12 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
|
|||
if ($this->saved_image_path && $this->auto_sizes) {
|
||||
if (!array_key_exists('height', $this->attributes) && !array_key_exists('width', $this->attributes)) {
|
||||
$info = getimagesize($this->saved_image_path);
|
||||
$width = intval($info[0]);
|
||||
$height = intval($info[1]);
|
||||
$width = (int)$info[0];
|
||||
$height = (int)$info[1];
|
||||
|
||||
$scaling_factor = $this->retina_scale > 0 ? $this->retina_scale : 1;
|
||||
$attributes['width'] = intval($width / $scaling_factor);
|
||||
$attributes['height'] = intval($height / $scaling_factor);
|
||||
$attributes['width'] = (int)($width / $scaling_factor);
|
||||
$attributes['height'] = (int)($height / $scaling_factor);
|
||||
|
||||
if ($this->aspect_ratio) {
|
||||
$style = ($attributes['style'] ?? ' ') . "--aspect-ratio: $width/$height;";
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user