1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-06 16:16:39 +02:00

Enable to set JPEG image as interlaced, implement feature #177.

This commit is contained in:
Mikael Roos
2020-06-08 12:26:40 +02:00
parent 2ce1f18fe5
commit 4ea72be49a
7 changed files with 192 additions and 31 deletions

View File

@@ -423,6 +423,13 @@ class CImage
/*
* Use interlaced progressive mode for JPEG images.
*/
private $interlace = false;
/*
* Image copy strategy, defaults to RESAMPLE.
*/
@@ -838,6 +845,7 @@ class CImage
'blur' => null,
'convolve' => null,
'rotateAfter' => null,
'interlace' => null,
// Output format
'outputFormat' => null,
@@ -1402,6 +1410,7 @@ class CImage
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
$lossy = $this->lossy ? "_l" : null;
$interlace = $this->interlace ? "_i" : null;
$saveAs = $this->normalizeFileExtension();
$saveAs = $saveAs ? "_$saveAs" : null;
@@ -1468,7 +1477,7 @@ class CImage
. $quality . $filters . $sharpen . $emboss . $blur . $palette
. $optimize . $compress
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
. $convolve . $copyStrat . $lossy . $saveAs;
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
return $this->setTarget($file, $base);
}
@@ -2440,6 +2449,12 @@ class CImage
case 'jpeg':
case 'jpg':
// Set as interlaced progressive JPEG
if ($this->interlace) {
$this->Log("Set JPEG image to be interlaced.");
$res = imageinterlace($this->image, true);
}
$this->Log("Saving image as JPEG to cache using quality = {$this->quality}.");
imagejpeg($this->image, $this->cacheFileName, $this->quality);

View File

@@ -5,6 +5,15 @@ Revision history
[![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
v0.8.0 (2020-06-08)
-------------------------------------
* Enable to set JPEG image as interlaced, implement feature #177.
* Add function getValue() to read from querystring.
* Set PHP 7.0 as precondition (to prepare to update the codebase).
v0.7.23 (2020-05-06)
-------------------------------------

View File

@@ -920,6 +920,18 @@ if ($cacheControl) {
/**
* interlace - Enable configuration for interlaced progressive JPEG images.
*/
$interlaceConfig = getConfig('interlace', null);
$interlaceValue = getValue('interlace', null);
$interlaceDefined = getDefined('interlace', true, null);
$interlace = $interlaceValue ?? $interlaceDefined ?? $interlaceConfig;
verbose("interlace (configfile) = ", $interlaceConfig);
verbose("interlace = ", $interlace);
/**
* Prepare a dummy image and use it as source image.
*/
@@ -1081,6 +1093,7 @@ if (is_callable($hookBeforeCImage)) {
'blur' => $blur,
'convolve' => $convolve,
'rotateAfter' => $rotateAfter,
'interlace' => $interlace,
// Output format
'outputFormat' => $outputFormat,
@@ -1169,6 +1182,7 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
'blur' => $blur,
'convolve' => $convolve,
'rotateAfter' => $rotateAfter,
'interlace' => $interlace,
// Output format
'outputFormat' => $outputFormat,

View File

@@ -485,6 +485,17 @@ return array(
"scale" => 14,
"luminanceStrategy" => 3,
"customCharacterSet" => null,
);
},*/
), */
/**
* Default options using interlaced progressive JPEG images. Set to true to
* always render jpeg images as interlaced. This setting can be overridden
* by using `?interlace=true` or `?interlace=false`.
*
* Default values are:
* interlace: false
*/
/*'interlace' => false,*/
);

View File

@@ -158,6 +158,25 @@ function getDefined($key, $defined, $undefined)
/**
* Get value of input from query string or else $undefined.
*
* @param mixed $key as string or array of string values to look for in $_GET.
* @param mixed $undefined value to return when $key has no, or empty value in $_GET.
*
* @return mixed value as or $undefined.
*/
function getValue($key, $undefined)
{
$val = get($key);
if (is_null($val) || $val === "") {
return $undefined;
}
return $val;
}
/**
* Get value from config array or default if key is not set in config array.
*
@@ -183,7 +202,7 @@ function getConfig($key, $default)
*
* @return void or array.
*/
function verbose($msg = null)
function verbose($msg = null, $arg = "")
{
global $verbose, $verboseFile;
static $log = array();
@@ -196,7 +215,15 @@ function verbose($msg = null)
return $log;
}
$log[] = $msg;
if (is_null($arg)) {
$arg = "null";
} elseif ($arg === false) {
$arg = "false";
} elseif ($arg === true) {
$arg = "true";
}
$log[] = $msg . $arg;
}
@@ -1533,6 +1560,13 @@ class CImage
/*
* Use interlaced progressive mode for JPEG images.
*/
private $interlace = false;
/*
* Image copy strategy, defaults to RESAMPLE.
*/
@@ -1948,6 +1982,7 @@ class CImage
'blur' => null,
'convolve' => null,
'rotateAfter' => null,
'interlace' => null,
// Output format
'outputFormat' => null,
@@ -2512,6 +2547,7 @@ class CImage
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
$lossy = $this->lossy ? "_l" : null;
$interlace = $this->interlace ? "_i" : null;
$saveAs = $this->normalizeFileExtension();
$saveAs = $saveAs ? "_$saveAs" : null;
@@ -2578,7 +2614,7 @@ class CImage
. $quality . $filters . $sharpen . $emboss . $blur . $palette
. $optimize . $compress
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
. $convolve . $copyStrat . $lossy . $saveAs;
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
return $this->setTarget($file, $base);
}
@@ -3550,6 +3586,12 @@ class CImage
case 'jpeg':
case 'jpg':
// Set as interlaced progressive JPEG
if ($this->interlace) {
$this->Log("Set JPEG image to be interlaced.");
$res = imageinterlace($this->image, true);
}
$this->Log("Saving image as JPEG to cache using quality = {$this->quality}.");
imagejpeg($this->image, $this->cacheFileName, $this->quality);
@@ -5316,6 +5358,18 @@ if ($cacheControl) {
/**
* interlace - Enable configuration for interlaced progressive JPEG images.
*/
$interlaceConfig = getConfig('interlace', null);
$interlaceValue = getValue('interlace', null);
$interlaceDefined = getDefined('interlace', true, null);
$interlace = $interlaceValue ?? $interlaceDefined ?? $interlaceConfig;
verbose("interlace (configfile) = ", $interlaceConfig);
verbose("interlace = ", $interlace);
/**
* Prepare a dummy image and use it as source image.
*/
@@ -5477,6 +5531,7 @@ if (is_callable($hookBeforeCImage)) {
'blur' => $blur,
'convolve' => $convolve,
'rotateAfter' => $rotateAfter,
'interlace' => $interlace,
// Output format
'outputFormat' => $outputFormat,
@@ -5565,6 +5620,7 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
'blur' => $blur,
'convolve' => $convolve,
'rotateAfter' => $rotateAfter,
'interlace' => $interlace,
// Output format
'outputFormat' => $outputFormat,

View File

@@ -158,6 +158,25 @@ function getDefined($key, $defined, $undefined)
/**
* Get value of input from query string or else $undefined.
*
* @param mixed $key as string or array of string values to look for in $_GET.
* @param mixed $undefined value to return when $key has no, or empty value in $_GET.
*
* @return mixed value as or $undefined.
*/
function getValue($key, $undefined)
{
$val = get($key);
if (is_null($val) || $val === "") {
return $undefined;
}
return $val;
}
/**
* Get value from config array or default if key is not set in config array.
*
@@ -183,7 +202,7 @@ function getConfig($key, $default)
*
* @return void or array.
*/
function verbose($msg = null)
function verbose($msg = null, $arg = "")
{
global $verbose, $verboseFile;
static $log = array();
@@ -196,7 +215,15 @@ function verbose($msg = null)
return $log;
}
$log[] = $msg;
if (is_null($arg)) {
$arg = "null";
} elseif ($arg === false) {
$arg = "false";
} elseif ($arg === true) {
$arg = "true";
}
$log[] = $msg . $arg;
}
@@ -1533,6 +1560,13 @@ class CImage
/*
* Use interlaced progressive mode for JPEG images.
*/
private $interlace = false;
/*
* Image copy strategy, defaults to RESAMPLE.
*/
@@ -1948,6 +1982,7 @@ class CImage
'blur' => null,
'convolve' => null,
'rotateAfter' => null,
'interlace' => null,
// Output format
'outputFormat' => null,
@@ -2512,6 +2547,7 @@ class CImage
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
$lossy = $this->lossy ? "_l" : null;
$interlace = $this->interlace ? "_i" : null;
$saveAs = $this->normalizeFileExtension();
$saveAs = $saveAs ? "_$saveAs" : null;
@@ -2578,7 +2614,7 @@ class CImage
. $quality . $filters . $sharpen . $emboss . $blur . $palette
. $optimize . $compress
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
. $convolve . $copyStrat . $lossy . $saveAs;
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
return $this->setTarget($file, $base);
}
@@ -3550,6 +3586,12 @@ class CImage
case 'jpeg':
case 'jpg':
// Set as interlaced progressive JPEG
if ($this->interlace) {
$this->Log("Set JPEG image to be interlaced.");
$res = imageinterlace($this->image, true);
}
$this->Log("Saving image as JPEG to cache using quality = {$this->quality}.");
imagejpeg($this->image, $this->cacheFileName, $this->quality);
@@ -5316,6 +5358,18 @@ if ($cacheControl) {
/**
* interlace - Enable configuration for interlaced progressive JPEG images.
*/
$interlaceConfig = getConfig('interlace', null);
$interlaceValue = getValue('interlace', null);
$interlaceDefined = getDefined('interlace', true, null);
$interlace = $interlaceValue ?? $interlaceDefined ?? $interlaceConfig;
verbose("interlace (configfile) = ", $interlaceConfig);
verbose("interlace = ", $interlace);
/**
* Prepare a dummy image and use it as source image.
*/
@@ -5477,6 +5531,7 @@ if (is_callable($hookBeforeCImage)) {
'blur' => $blur,
'convolve' => $convolve,
'rotateAfter' => $rotateAfter,
'interlace' => $interlace,
// Output format
'outputFormat' => $outputFormat,
@@ -5565,6 +5620,7 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
'blur' => $blur,
'convolve' => $convolve,
'rotateAfter' => $rotateAfter,
'interlace' => $interlace,
// Output format
'outputFormat' => $outputFormat,

File diff suppressed because one or more lines are too long