Update Kirby and Composer dependencies
This commit is contained in:
parent
f5d3ea5e84
commit
ec74d78ba9
382 changed files with 25077 additions and 4955 deletions
|
@ -8,7 +8,7 @@ namespace Kirby\Image;
|
|||
* @package Kirby Image
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Camera
|
||||
|
|
|
@ -11,7 +11,7 @@ use Exception;
|
|||
* @package Kirby Image
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Darkroom
|
||||
|
@ -63,14 +63,16 @@ class Darkroom
|
|||
protected function defaults(): array
|
||||
{
|
||||
return [
|
||||
'autoOrient' => true,
|
||||
'blur' => false,
|
||||
'crop' => false,
|
||||
'format' => null,
|
||||
'grayscale' => false,
|
||||
'height' => null,
|
||||
'quality' => 90,
|
||||
'width' => null,
|
||||
'autoOrient' => true,
|
||||
'blur' => false,
|
||||
'crop' => false,
|
||||
'format' => null,
|
||||
'grayscale' => false,
|
||||
'height' => null,
|
||||
'quality' => 90,
|
||||
'scaleHeight' => null,
|
||||
'scaleWidth' => null,
|
||||
'width' => null,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -124,12 +126,21 @@ class Darkroom
|
|||
*/
|
||||
public function preprocess(string $file, array $options = [])
|
||||
{
|
||||
$options = $this->options($options);
|
||||
$image = new Image($file);
|
||||
$dimensions = $image->dimensions()->thumb($options);
|
||||
$options = $this->options($options);
|
||||
$image = new Image($file);
|
||||
|
||||
$options['width'] = $dimensions->width();
|
||||
$options['height'] = $dimensions->height();
|
||||
$dimensions = $image->dimensions();
|
||||
$thumbDimensions = $dimensions->thumb($options);
|
||||
|
||||
$sourceWidth = $image->width();
|
||||
$sourceHeight = $image->height();
|
||||
|
||||
$options['width'] = $thumbDimensions->width();
|
||||
$options['height'] = $thumbDimensions->height();
|
||||
|
||||
// scale ratio compared to the source dimensions
|
||||
$options['scaleWidth'] = $sourceWidth ? $options['width'] / $sourceWidth : null;
|
||||
$options['scaleHeight'] = $sourceHeight ? $options['height'] / $sourceHeight : null;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use Kirby\Image\Darkroom;
|
|||
* @package Kirby Image
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class GdLib extends Darkroom
|
||||
|
|
|
@ -12,7 +12,7 @@ use Kirby\Image\Darkroom;
|
|||
* @package Kirby Image
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class ImageMagick extends Darkroom
|
||||
|
@ -42,7 +42,7 @@ class ImageMagick extends Darkroom
|
|||
protected function blur(string $file, array $options)
|
||||
{
|
||||
if ($options['blur'] !== false) {
|
||||
return '-blur 0x' . $options['blur'];
|
||||
return '-blur ' . escapeshellarg('0x' . $options['blur']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,21 @@ class ImageMagick extends Darkroom
|
|||
*/
|
||||
protected function convert(string $file, array $options): string
|
||||
{
|
||||
return sprintf($options['bin'] . ' "%s"', $file);
|
||||
$command = escapeshellarg($options['bin']);
|
||||
|
||||
// limit to single-threading to keep CPU usage sane
|
||||
$command .= ' -limit thread 1';
|
||||
|
||||
// add JPEG size hint to optimize CPU and memory usage
|
||||
if (F::mime($file) === 'image/jpeg') {
|
||||
// add hint only when downscaling
|
||||
if ($options['scaleWidth'] < 1 && $options['scaleHeight'] < 1) {
|
||||
$command .= ' -define ' . escapeshellarg(sprintf('jpeg:size=%dx%d', $options['width'], $options['height']));
|
||||
}
|
||||
}
|
||||
|
||||
// append input file
|
||||
return $command . ' ' . escapeshellarg($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,7 +176,7 @@ class ImageMagick extends Darkroom
|
|||
*/
|
||||
protected function quality(string $file, array $options): string
|
||||
{
|
||||
return '-quality ' . $options['quality'];
|
||||
return '-quality ' . escapeshellarg($options['quality']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +191,7 @@ class ImageMagick extends Darkroom
|
|||
{
|
||||
// simple resize
|
||||
if ($options['crop'] === false) {
|
||||
return sprintf('-resize %sx%s!', $options['width'], $options['height']);
|
||||
return '-thumbnail ' . escapeshellarg(sprintf('%sx%s!', $options['width'], $options['height']));
|
||||
}
|
||||
|
||||
$gravities = [
|
||||
|
@ -195,15 +209,15 @@ class ImageMagick extends Darkroom
|
|||
// translate the gravity option into something imagemagick understands
|
||||
$gravity = $gravities[$options['crop']] ?? 'Center';
|
||||
|
||||
$command = sprintf('-resize %sx%s^', $options['width'], $options['height']);
|
||||
$command .= sprintf(' -gravity %s -crop %sx%s+0+0', $gravity, $options['width'], $options['height']);
|
||||
$command = '-thumbnail ' . escapeshellarg(sprintf('%sx%s^', $options['width'], $options['height']));
|
||||
$command .= ' -gravity ' . escapeshellarg($gravity);
|
||||
$command .= ' -crop ' . escapeshellarg(sprintf('%sx%s+0+0', $options['width'], $options['height']));
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes sure to not process too many images at once
|
||||
* which could crash the server
|
||||
* Creates the option for the output file
|
||||
*
|
||||
* @param string $file
|
||||
* @param array $options
|
||||
|
@ -215,7 +229,7 @@ class ImageMagick extends Darkroom
|
|||
$file = pathinfo($file, PATHINFO_DIRNAME) . '/' . pathinfo($file, PATHINFO_FILENAME) . '.' . $options['format'];
|
||||
}
|
||||
|
||||
return sprintf('-limit thread 1 "%s"', $file);
|
||||
return escapeshellarg($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -227,6 +241,14 @@ class ImageMagick extends Darkroom
|
|||
*/
|
||||
protected function strip(string $file, array $options): string
|
||||
{
|
||||
return '-strip';
|
||||
if (F::extension($file) === 'png') {
|
||||
// ImageMagick does not support keeping ICC profiles while
|
||||
// stripping other privacy- and security-related information,
|
||||
// such as GPS data; so discard all color profiles for PNG files
|
||||
// (tested with ImageMagick 7.0.11-14 Q16 x86_64 2021-05-31)
|
||||
return '-strip';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Kirby\Image;
|
|||
* @package Kirby Image
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Dimensions
|
||||
|
@ -285,12 +285,12 @@ class Dimensions
|
|||
|
||||
if ($xml !== false) {
|
||||
$attr = $xml->attributes();
|
||||
$width = (float)($attr->width);
|
||||
$height = (float)($attr->height);
|
||||
if (($width === 0.0 || $height === 0.0) && empty($attr->viewBox) === false) {
|
||||
$width = (int)($attr->width);
|
||||
$height = (int)($attr->height);
|
||||
if (($width === 0 || $height === 0) && empty($attr->viewBox) === false) {
|
||||
$box = explode(' ', $attr->viewBox);
|
||||
$width = (float)($box[2] ?? 0);
|
||||
$height = (float)($box[3] ?? 0);
|
||||
$width = (int)($box[2] ?? 0);
|
||||
$height = (int)($box[3] ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use Kirby\Toolkit\V;
|
|||
* @package Kirby Image
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Exif
|
||||
|
|
|
@ -17,7 +17,7 @@ use Kirby\Toolkit\Html;
|
|||
* @package Kirby Image
|
||||
* @author Nico Hoffmann <nico@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Image extends File
|
||||
|
@ -116,7 +116,7 @@ class Image extends File
|
|||
*/
|
||||
public function exif()
|
||||
{
|
||||
return $this->exif = $this->exif ?? new Exif($this);
|
||||
return $this->exif ??= new Exif($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Kirby\Image;
|
|||
* @package Kirby Image
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier GmbH
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class Location
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue