Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
fixed: crop no longer part of core options forwared to thumb component
Browse files Browse the repository at this point in the history
  • Loading branch information
bnomei committed Jul 18, 2019
1 parent aa9cb37 commit 843b4c4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
36 changes: 22 additions & 14 deletions classes/Imageoptim.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private static function pop(string $key)

public static function removeFilesOfUnfinishedJobs()
{
$r = kirby()->roots()->cache().'/bnomei/thumbimageoptim';
$r = kirby()->roots()->cache() . '/bnomei/thumbimageoptim';
$cachefiles = \Kirby\Toolkit\Dir::files($r);
foreach ($cachefiles as $file) {
$md5 = basename($file, '.cache');
Expand All @@ -51,7 +51,7 @@ public static function removeFilesOfUnfinishedJobs()
}
}

private static function log(string $msg = '', string $level = 'info', array $context = []):bool
private static function log(string $msg = '', string $level = 'info', array $context = []): bool
{
$log = option('bnomei.thumbimageoptim.log');
if ($log && is_callable($log)) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public static function thumb($src, $dst, $options)
if ($pos === false) {
return $v;
} else {
return substr($v, $pos+1);
return substr($v, $pos + 1);
}
}, $path);
$pathO = implode('/', $pathO);
Expand Down Expand Up @@ -147,19 +147,27 @@ public static function thumb($src, $dst, $options)
}
}
if ($request) {
$fit = A::get($settings, 'crop', 'crop');
$allowedFitOptions = ['fit', 'crop', 'scale-down', 'pad'];
if (null !== $fit && !in_array($fit, $allowedFitOptions)) {
$fit = 'crop';
}
$request = $request->resize(
$settings['width'],
$settings['height'],
$settings['crop'] == 1 ? 'crop' : 'scale-down'
)->quality(
$settings['io_quality']
)
->dpr(intval($settings['io_dpr']));
A::get($settings, 'width'),
A::get($settings, 'height'),
A::get($settings, 'height') === null ? null : $fit
);
if ($io_quality = A::get($settings, 'io_quality')) {
$request = $request->quality($io_quality);
}
if ($io_dpr = A::get($settings, 'io_dpr')) {
$request = intval($request->dpr($io_dpr));
}

if ($tl = option('bnomei.thumbimageoptim.timelimit')) {
set_time_limit(intval($tl));
}

$bytes = null;
// https://github.com/bnomei/kirby3-thumb-imageoptim/issues/4
if (static::is_localhost() || option('bnomei.thumbimageoptim.forceupload')) {
Expand All @@ -168,11 +176,11 @@ public static function thumb($src, $dst, $options)
static::log('Image URL', 'debug', [
'url' => $request->apiURL()
]);

// https://github.com/ImageOptim/php-imageoptim-api#apiurl--debug-or-use-another-https-client
$bytes = \Kirby\Http\Remote::get($request->apiURL(), ['method' => 'POST'])->content();
}

$success = $bytes ? \Kirby\Toolkit\F::write($dst, $bytes) : false;
if ($success) {
static::pop($dst);
Expand All @@ -195,7 +203,7 @@ public static function thumb($src, $dst, $options)

private static function is_localhost()
{
$whitelist = array( '127.0.0.1', '::1' );
$whitelist = array('127.0.0.1', '::1');
if (in_array($_SERVER['REMOTE_ADDR'], $whitelist)) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bnomei/kirby3-thumb-imageoptim",
"description": "Kirby 3 Thumb Driver using Imageoptim",
"type": "kirby-plugin",
"version": "1.3.1",
"version": "1.3.2",
"license": "MIT",
"authors": [
{
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 843b4c4

Please sign in to comment.