mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
New Trait for decoding attribute in images
This commit is contained in:
parent
cd2a7d8d98
commit
959acda39c
42
system/src/Grav/Common/Media/Traits/ImageDecodingTrait.php
Normal file
42
system/src/Grav/Common/Media/Traits/ImageDecodingTrait.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Common\Media
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2024 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common\Media\Traits;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
|
||||
/**
|
||||
* Trait ImageLoadingTrait
|
||||
* @package Grav\Common\Media\Traits
|
||||
*/
|
||||
|
||||
trait ImageDecodingTrait
|
||||
{
|
||||
/**
|
||||
* Allows to set the decoding attribute from Markdown or Twig
|
||||
*
|
||||
* @param string|null $value
|
||||
* @return $this
|
||||
*/
|
||||
public function decoding($value = null)
|
||||
{
|
||||
$validValues = ['sync', 'async', 'auto'];
|
||||
|
||||
if (null === $value) {
|
||||
$value = Grav::instance()['config']->get('system.images.defaults.decoding', 'auto');
|
||||
}
|
||||
|
||||
// Validate the provided value
|
||||
if ($value && in_array($value, $validValues, true)) {
|
||||
$this->attributes['decoding'] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ use Grav\Common\Media\Interfaces\ImageManipulateInterface;
|
|||
use Grav\Common\Media\Interfaces\ImageMediaInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaLinkInterface;
|
||||
use Grav\Common\Media\Traits\ImageLoadingTrait;
|
||||
use Grav\Common\Media\Traits\ImageDecodingTrait;
|
||||
use Grav\Common\Media\Traits\ImageMediaTrait;
|
||||
use Grav\Common\Utils;
|
||||
use Gregwar\Image\Image;
|
||||
|
|
@ -30,6 +31,7 @@ class ImageMedium extends Medium implements ImageMediaInterface, ImageManipulate
|
|||
{
|
||||
use ImageMediaTrait;
|
||||
use ImageLoadingTrait;
|
||||
use ImageDecodingTrait;
|
||||
|
||||
/**
|
||||
* @var mixed|string
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user