downgrade to kirby v3
This commit is contained in:
@@ -2,9 +2,7 @@
|
||||
|
||||
namespace Kirby\Cms;
|
||||
|
||||
use Kirby\Content\Field;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Filesystem\Asset;
|
||||
|
||||
/**
|
||||
* Trait for image resizing, blurring etc.
|
||||
@@ -19,36 +17,43 @@ trait FileModifications
|
||||
{
|
||||
/**
|
||||
* Blurs the image by the given amount of pixels
|
||||
*
|
||||
* @param bool $pixels
|
||||
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
|
||||
*/
|
||||
public function blur(int|bool $pixels = true): FileVersion|File|Asset
|
||||
public function blur($pixels = true)
|
||||
{
|
||||
return $this->thumb(['blur' => $pixels]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the image to black and white
|
||||
*
|
||||
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
|
||||
*/
|
||||
public function bw(): FileVersion|File|Asset
|
||||
public function bw()
|
||||
{
|
||||
return $this->thumb(['grayscale' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crops the image by the given width and height
|
||||
*
|
||||
* @param int $width
|
||||
* @param int|null $height
|
||||
* @param string|array $options
|
||||
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
|
||||
*/
|
||||
public function crop(
|
||||
int $width,
|
||||
int $height = null,
|
||||
$options = null
|
||||
): FileVersion|File|Asset {
|
||||
public function crop(int $width, int $height = null, $options = null)
|
||||
{
|
||||
$quality = null;
|
||||
$crop = true;
|
||||
$crop = 'center';
|
||||
|
||||
if (is_int($options) === true) {
|
||||
$quality = $options;
|
||||
} elseif (is_string($options)) {
|
||||
$crop = $options;
|
||||
} elseif ($options instanceof Field) {
|
||||
} elseif (is_a($options, 'Kirby\Cms\Field') === true) {
|
||||
$crop = $options->value();
|
||||
} elseif (is_array($options)) {
|
||||
$quality = $options['quality'] ?? $quality;
|
||||
@@ -65,24 +70,31 @@ trait FileModifications
|
||||
|
||||
/**
|
||||
* Alias for File::bw()
|
||||
*
|
||||
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
|
||||
*/
|
||||
public function grayscale(): FileVersion|File|Asset
|
||||
public function grayscale()
|
||||
{
|
||||
return $this->thumb(['grayscale' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for File::bw()
|
||||
*
|
||||
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
|
||||
*/
|
||||
public function greyscale(): FileVersion|File|Asset
|
||||
public function greyscale()
|
||||
{
|
||||
return $this->thumb(['grayscale' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the JPEG compression quality
|
||||
*
|
||||
* @param int $quality
|
||||
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
|
||||
*/
|
||||
public function quality(int $quality): FileVersion|File|Asset
|
||||
public function quality(int $quality)
|
||||
{
|
||||
return $this->thumb(['quality' => $quality]);
|
||||
}
|
||||
@@ -91,13 +103,14 @@ trait FileModifications
|
||||
* Resizes the file with the given width and height
|
||||
* while keeping the aspect ratio.
|
||||
*
|
||||
* @param int|null $width
|
||||
* @param int|null $height
|
||||
* @param int|null $quality
|
||||
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
|
||||
* @throws \Kirby\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function resize(
|
||||
int $width = null,
|
||||
int $height = null,
|
||||
int $quality = null
|
||||
): FileVersion|File|Asset {
|
||||
public function resize(int $width = null, int $height = null, int $quality = null)
|
||||
{
|
||||
return $this->thumb([
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
@@ -105,21 +118,16 @@ trait FileModifications
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sharpens the image
|
||||
*/
|
||||
public function sharpen(int $amount = 50): FileVersion|File|Asset
|
||||
{
|
||||
return $this->thumb(['sharpen' => $amount]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a srcset definition for the given sizes
|
||||
* Sizes can be defined as a simple array. They can
|
||||
* also be set up in the config with the thumbs.srcsets option.
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array|string|null $sizes
|
||||
* @return string|null
|
||||
*/
|
||||
public function srcset(array|string|null $sizes = null): string|null
|
||||
public function srcset($sizes = null): ?string
|
||||
{
|
||||
if (empty($sizes) === true) {
|
||||
$sizes = $this->kirby()->option('thumbs.srcsets.default', []);
|
||||
@@ -166,11 +174,12 @@ trait FileModifications
|
||||
* could potentially also be a CDN or any other
|
||||
* place.
|
||||
*
|
||||
* @param array|null|string $options
|
||||
* @return \Kirby\Cms\FileVersion|\Kirby\Cms\File
|
||||
* @throws \Kirby\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function thumb(
|
||||
array|string|null $options = null
|
||||
): FileVersion|File|Asset {
|
||||
public function thumb($options = null)
|
||||
{
|
||||
// thumb presets
|
||||
if (empty($options) === true) {
|
||||
$options = $this->kirby()->option('thumbs.presets.default');
|
||||
@@ -182,15 +191,6 @@ trait FileModifications
|
||||
return $this;
|
||||
}
|
||||
|
||||
// fallback to content file options
|
||||
if (($options['crop'] ?? false) === true) {
|
||||
if ($this instanceof ModelWithContent === true) {
|
||||
$options['crop'] = $this->focus()->value() ?? 'center';
|
||||
} else {
|
||||
$options['crop'] = 'center';
|
||||
}
|
||||
}
|
||||
|
||||
// fallback to global config options
|
||||
if (isset($options['format']) === false) {
|
||||
if ($format = $this->kirby()->option('thumbs.format')) {
|
||||
@@ -202,9 +202,9 @@ trait FileModifications
|
||||
$result = $component($this->kirby(), $this, $options);
|
||||
|
||||
if (
|
||||
$result instanceof FileVersion === false &&
|
||||
$result instanceof File === false &&
|
||||
$result instanceof Asset === false
|
||||
is_a($result, 'Kirby\Cms\FileVersion') === false &&
|
||||
is_a($result, 'Kirby\Cms\File') === false &&
|
||||
is_a($result, 'Kirby\Filesystem\Asset') === false
|
||||
) {
|
||||
throw new InvalidArgumentException('The file::version component must return a File, FileVersion or Asset object');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user