Upgrade to 4.1.0
This commit is contained in:
@@ -60,6 +60,7 @@ class Darkroom
|
||||
'quality' => 90,
|
||||
'scaleHeight' => null,
|
||||
'scaleWidth' => null,
|
||||
'sharpen' => null,
|
||||
'width' => null,
|
||||
];
|
||||
}
|
||||
@@ -93,6 +94,11 @@ class Darkroom
|
||||
unset($options['bw']);
|
||||
}
|
||||
|
||||
// normalize the sharpen option
|
||||
if ($options['sharpen'] === true) {
|
||||
$options['sharpen'] = 50;
|
||||
}
|
||||
|
||||
$options['quality'] ??= $this->settings['quality'];
|
||||
|
||||
return $options;
|
||||
|
@@ -33,6 +33,7 @@ class GdLib extends Darkroom
|
||||
$image = $this->autoOrient($image, $options);
|
||||
$image = $this->blur($image, $options);
|
||||
$image = $this->grayscale($image, $options);
|
||||
$image = $this->sharpen($image, $options);
|
||||
|
||||
$image->toFile($file, $mime, $options);
|
||||
|
||||
@@ -116,6 +117,18 @@ class GdLib extends Darkroom
|
||||
return $image->desaturate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies sharpening if activated in the options.
|
||||
*/
|
||||
protected function sharpen(SimpleImage $image, array $options): SimpleImage
|
||||
{
|
||||
if (is_int($options['sharpen']) === false) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
return $image->sharpen($options['sharpen']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns mime type based on `format` option
|
||||
*/
|
||||
|
@@ -65,14 +65,6 @@ class ImageMagick extends Darkroom
|
||||
// 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);
|
||||
}
|
||||
@@ -100,6 +92,19 @@ class ImageMagick extends Darkroom
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies sharpening if activated in the options.
|
||||
*/
|
||||
protected function sharpen(string $file, array $options): string|null
|
||||
{
|
||||
if (is_int($options['sharpen']) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$amount = max(1, min(100, $options['sharpen'])) / 100;
|
||||
return '-sharpen ' . escapeshellarg('0x' . $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the correct settings for interlaced JPEGs if
|
||||
* activated via options
|
||||
@@ -133,6 +138,7 @@ class ImageMagick extends Darkroom
|
||||
$command[] = $this->resize($file, $options);
|
||||
$command[] = $this->quality($file, $options);
|
||||
$command[] = $this->blur($file, $options);
|
||||
$command[] = $this->sharpen($file, $options);
|
||||
$command[] = $this->save($file, $options);
|
||||
|
||||
// remove all null values and join the parts
|
||||
|
@@ -76,10 +76,11 @@ class Image extends File
|
||||
}
|
||||
|
||||
if (in_array($this->mime(), [
|
||||
'image/avif',
|
||||
'image/gif',
|
||||
'image/jpeg',
|
||||
'image/jp2',
|
||||
'image/png',
|
||||
'image/gif',
|
||||
'image/webp'
|
||||
])) {
|
||||
return $this->dimensions = Dimensions::forImage($this->root);
|
||||
|
Reference in New Issue
Block a user