mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-31 19:31:47 +02:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4ea72be49a | ||
|
2ce1f18fe5 | ||
|
0f1f537b62 | ||
|
1411adc828 | ||
|
86737af69e | ||
|
c563275ed5 | ||
|
8fec09b195 | ||
|
ac16343cd7 | ||
|
cd142c5880 | ||
|
91dd92d483 | ||
|
4b64d921d1 | ||
|
4211d7e0e6 | ||
|
dd8878c8bd |
23
CImage.php
23
CImage.php
@@ -423,6 +423,13 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use interlaced progressive mode for JPEG images.
|
||||||
|
*/
|
||||||
|
private $interlace = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Image copy strategy, defaults to RESAMPLE.
|
* Image copy strategy, defaults to RESAMPLE.
|
||||||
*/
|
*/
|
||||||
@@ -838,6 +845,7 @@ class CImage
|
|||||||
'blur' => null,
|
'blur' => null,
|
||||||
'convolve' => null,
|
'convolve' => null,
|
||||||
'rotateAfter' => null,
|
'rotateAfter' => null,
|
||||||
|
'interlace' => null,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => null,
|
'outputFormat' => null,
|
||||||
@@ -1023,13 +1031,15 @@ class CImage
|
|||||||
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
|
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
|
||||||
|
|
||||||
// width as %
|
// width as %
|
||||||
if ($this->newWidth[strlen($this->newWidth)-1] == '%') {
|
if ($this->newWidth
|
||||||
|
&& $this->newWidth[strlen($this->newWidth)-1] == '%') {
|
||||||
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
|
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
|
||||||
$this->log("Setting new width based on % to {$this->newWidth}");
|
$this->log("Setting new width based on % to {$this->newWidth}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// height as %
|
// height as %
|
||||||
if ($this->newHeight[strlen($this->newHeight)-1] == '%') {
|
if ($this->newHeight
|
||||||
|
&& $this->newHeight[strlen($this->newHeight)-1] == '%') {
|
||||||
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
|
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
|
||||||
$this->log("Setting new height based on % to {$this->newHeight}");
|
$this->log("Setting new height based on % to {$this->newHeight}");
|
||||||
}
|
}
|
||||||
@@ -1400,6 +1410,7 @@ class CImage
|
|||||||
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
||||||
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
||||||
$lossy = $this->lossy ? "_l" : null;
|
$lossy = $this->lossy ? "_l" : null;
|
||||||
|
$interlace = $this->interlace ? "_i" : null;
|
||||||
|
|
||||||
$saveAs = $this->normalizeFileExtension();
|
$saveAs = $this->normalizeFileExtension();
|
||||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||||
@@ -1466,7 +1477,7 @@ class CImage
|
|||||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||||
. $optimize . $compress
|
. $optimize . $compress
|
||||||
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
||||||
. $convolve . $copyStrat . $lossy . $saveAs;
|
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
|
||||||
|
|
||||||
return $this->setTarget($file, $base);
|
return $this->setTarget($file, $base);
|
||||||
}
|
}
|
||||||
@@ -2438,6 +2449,12 @@ class CImage
|
|||||||
|
|
||||||
case 'jpeg':
|
case 'jpeg':
|
||||||
case 'jpg':
|
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}.");
|
$this->Log("Saving image as JPEG to cache using quality = {$this->quality}.");
|
||||||
imagejpeg($this->image, $this->cacheFileName, $this->quality);
|
imagejpeg($this->image, $this->cacheFileName, $this->quality);
|
||||||
|
|
||||||
|
38
REVISION.md
38
REVISION.md
@@ -5,10 +5,46 @@ Revision history
|
|||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/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)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Fix error in composer.json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
v0.7.22 (2020-05-06)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Update composer.json and move ext-gd from required to suggested to ease installation where cli does not have all extensions installed.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
v0.7.21 (2020-01-15)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Support PHP 7.4, some minor fixes with notices.
|
||||||
|
|
||||||
|
|
||||||
|
v0.7.20 (2017-11-06)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Remove webroot/img/{round8.PNG,wider.JPEG,wider.JPG} to avoid unzip warning message when installing with composer.
|
||||||
|
* Adding docker-compose.yml #169.
|
||||||
|
|
||||||
|
|
||||||
v0.7.19 (2017-03-31)
|
v0.7.19 (2017-03-31)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
* Move exception handler from functions.php to img.php.
|
* Move exception handler from functions.php to img.php #166.
|
||||||
* Correct XSS injection in `check_system.php`.
|
* Correct XSS injection in `check_system.php`.
|
||||||
* Composer suggests ext-imagick and ext-curl.
|
* Composer suggests ext-imagick and ext-curl.
|
||||||
|
|
||||||
|
@@ -18,12 +18,12 @@
|
|||||||
"docs": "http://dbwebb.se/opensource/cimage"
|
"docs": "http://dbwebb.se/opensource/cimage"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3",
|
"php": ">=7.0"
|
||||||
"ext-gd": "*"
|
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"ext-exif": "*",
|
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
|
"ext-exif": "*",
|
||||||
|
"ext-gd": "*",
|
||||||
"ext-imagick": "*"
|
"ext-imagick": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.7.19 (2017-03-31)");
|
define("CIMAGE_VERSION", "v0.7.23 (2020-05-06)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
|
30
docker-compose.yml
Normal file
30
docker-compose.yml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
php74:
|
||||||
|
image: anax/dev:php74-apache
|
||||||
|
ports:
|
||||||
|
- "8074:80"
|
||||||
|
volumes:
|
||||||
|
- .:/home/anax/repo
|
||||||
|
|
||||||
|
php71:
|
||||||
|
image: cimage/php71-apache:latest
|
||||||
|
#build: .
|
||||||
|
ports:
|
||||||
|
- "8071:80"
|
||||||
|
volumes:
|
||||||
|
- ./:/var/www/html/
|
||||||
|
php70:
|
||||||
|
image: cimage/php70-apache:latest
|
||||||
|
#build: .
|
||||||
|
ports:
|
||||||
|
- "8070:80"
|
||||||
|
volumes:
|
||||||
|
- .:/var/www/html
|
||||||
|
php56:
|
||||||
|
image: cimage/php56-apache:latest
|
||||||
|
#build: .
|
||||||
|
ports:
|
||||||
|
- "8056:80"
|
||||||
|
volumes:
|
||||||
|
- .:/var/www/html
|
@@ -107,6 +107,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.
|
* Get value from config array or default if key is not set in config array.
|
||||||
*
|
*
|
||||||
@@ -132,7 +151,7 @@ function getConfig($key, $default)
|
|||||||
*
|
*
|
||||||
* @return void or array.
|
* @return void or array.
|
||||||
*/
|
*/
|
||||||
function verbose($msg = null)
|
function verbose($msg = null, $arg = "")
|
||||||
{
|
{
|
||||||
global $verbose, $verboseFile;
|
global $verbose, $verboseFile;
|
||||||
static $log = array();
|
static $log = array();
|
||||||
@@ -145,7 +164,15 @@ function verbose($msg = null)
|
|||||||
return $log;
|
return $log;
|
||||||
}
|
}
|
||||||
|
|
||||||
$log[] = $msg;
|
if (is_null($arg)) {
|
||||||
|
$arg = "null";
|
||||||
|
} elseif ($arg === false) {
|
||||||
|
$arg = "false";
|
||||||
|
} elseif ($arg === true) {
|
||||||
|
$arg = "true";
|
||||||
|
}
|
||||||
|
|
||||||
|
$log[] = $msg . $arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -440,7 +440,7 @@ if (isset($sizes[$newWidth])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Support width as % of original width
|
// Support width as % of original width
|
||||||
if ($newWidth[strlen($newWidth)-1] == '%') {
|
if ($newWidth && $newWidth[strlen($newWidth)-1] == '%') {
|
||||||
is_numeric(substr($newWidth, 0, -1))
|
is_numeric(substr($newWidth, 0, -1))
|
||||||
or errorPage('Width % not numeric.', 404);
|
or errorPage('Width % not numeric.', 404);
|
||||||
} else {
|
} else {
|
||||||
@@ -465,7 +465,7 @@ if (isset($sizes[$newHeight])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// height
|
// height
|
||||||
if ($newHeight[strlen($newHeight)-1] == '%') {
|
if ($newHeight && $newHeight[strlen($newHeight)-1] == '%') {
|
||||||
is_numeric(substr($newHeight, 0, -1))
|
is_numeric(substr($newHeight, 0, -1))
|
||||||
or errorPage('Height % out of range.', 404);
|
or errorPage('Height % out of range.', 404);
|
||||||
} else {
|
} else {
|
||||||
@@ -496,7 +496,7 @@ $aspectRatioConstant = getConfig('aspect_ratio_constant', function () {
|
|||||||
|
|
||||||
// Check to replace predefined aspect ratio
|
// Check to replace predefined aspect ratio
|
||||||
$aspectRatios = call_user_func($aspectRatioConstant);
|
$aspectRatios = call_user_func($aspectRatioConstant);
|
||||||
$negateAspectRatio = ($aspectRatio[0] == '!') ? true : false;
|
$negateAspectRatio = ($aspectRatio && $aspectRatio[0] == '!') ? true : false;
|
||||||
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
|
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
|
||||||
|
|
||||||
if (isset($aspectRatios[$aspectRatio])) {
|
if (isset($aspectRatios[$aspectRatio])) {
|
||||||
@@ -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.
|
* Prepare a dummy image and use it as source image.
|
||||||
*/
|
*/
|
||||||
@@ -1081,6 +1093,7 @@ if (is_callable($hookBeforeCImage)) {
|
|||||||
'blur' => $blur,
|
'blur' => $blur,
|
||||||
'convolve' => $convolve,
|
'convolve' => $convolve,
|
||||||
'rotateAfter' => $rotateAfter,
|
'rotateAfter' => $rotateAfter,
|
||||||
|
'interlace' => $interlace,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => $outputFormat,
|
'outputFormat' => $outputFormat,
|
||||||
@@ -1169,6 +1182,7 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
|
|||||||
'blur' => $blur,
|
'blur' => $blur,
|
||||||
'convolve' => $convolve,
|
'convolve' => $convolve,
|
||||||
'rotateAfter' => $rotateAfter,
|
'rotateAfter' => $rotateAfter,
|
||||||
|
'interlace' => $interlace,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => $outputFormat,
|
'outputFormat' => $outputFormat,
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 6.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 70 KiB |
Binary file not shown.
Before Width: | Height: | Size: 70 KiB |
@@ -41,7 +41,7 @@ return array(
|
|||||||
* mode: 'production'
|
* mode: 'production'
|
||||||
*/
|
*/
|
||||||
//'mode' => 'production',
|
//'mode' => 'production',
|
||||||
//'mode' => 'development',
|
'mode' => 'development',
|
||||||
//'mode' => 'strict',
|
//'mode' => 'strict',
|
||||||
|
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ return array(
|
|||||||
*/
|
*/
|
||||||
'image_path' => __DIR__ . '/img/',
|
'image_path' => __DIR__ . '/img/',
|
||||||
'cache_path' => __DIR__ . '/../cache/',
|
'cache_path' => __DIR__ . '/../cache/',
|
||||||
//'alias_path' => __DIR__ . '/img/alias/',
|
'alias_path' => __DIR__ . '/img/alias/',
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ return array(
|
|||||||
* password_type: 'text' // use plain password, not encoded,
|
* password_type: 'text' // use plain password, not encoded,
|
||||||
*/
|
*/
|
||||||
//'password_always' => false, // always require password,
|
//'password_always' => false, // always require password,
|
||||||
//'password' => false, // "secret-password",
|
'password' => "moped", // "secret-password",
|
||||||
//'password_type' => 'text', // supports 'text', 'md5', 'hash',
|
//'password_type' => 'text', // supports 'text', 'md5', 'hash',
|
||||||
|
|
||||||
|
|
||||||
@@ -485,6 +485,17 @@ return array(
|
|||||||
"scale" => 14,
|
"scale" => 14,
|
||||||
"luminanceStrategy" => 3,
|
"luminanceStrategy" => 3,
|
||||||
"customCharacterSet" => null,
|
"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,*/
|
||||||
);
|
);
|
||||||
|
@@ -38,7 +38,7 @@ $config = array(
|
|||||||
|
|
||||||
|
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.7.19 (2017-03-31)");
|
define("CIMAGE_VERSION", "v0.7.23 (2020-05-06)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
@@ -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.
|
* 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.
|
* @return void or array.
|
||||||
*/
|
*/
|
||||||
function verbose($msg = null)
|
function verbose($msg = null, $arg = "")
|
||||||
{
|
{
|
||||||
global $verbose, $verboseFile;
|
global $verbose, $verboseFile;
|
||||||
static $log = array();
|
static $log = array();
|
||||||
@@ -196,7 +215,15 @@ function verbose($msg = null)
|
|||||||
return $log;
|
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.
|
* Image copy strategy, defaults to RESAMPLE.
|
||||||
*/
|
*/
|
||||||
@@ -1948,6 +1982,7 @@ class CImage
|
|||||||
'blur' => null,
|
'blur' => null,
|
||||||
'convolve' => null,
|
'convolve' => null,
|
||||||
'rotateAfter' => null,
|
'rotateAfter' => null,
|
||||||
|
'interlace' => null,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => null,
|
'outputFormat' => null,
|
||||||
@@ -2133,13 +2168,15 @@ class CImage
|
|||||||
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
|
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
|
||||||
|
|
||||||
// width as %
|
// width as %
|
||||||
if ($this->newWidth[strlen($this->newWidth)-1] == '%') {
|
if ($this->newWidth
|
||||||
|
&& $this->newWidth[strlen($this->newWidth)-1] == '%') {
|
||||||
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
|
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
|
||||||
$this->log("Setting new width based on % to {$this->newWidth}");
|
$this->log("Setting new width based on % to {$this->newWidth}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// height as %
|
// height as %
|
||||||
if ($this->newHeight[strlen($this->newHeight)-1] == '%') {
|
if ($this->newHeight
|
||||||
|
&& $this->newHeight[strlen($this->newHeight)-1] == '%') {
|
||||||
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
|
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
|
||||||
$this->log("Setting new height based on % to {$this->newHeight}");
|
$this->log("Setting new height based on % to {$this->newHeight}");
|
||||||
}
|
}
|
||||||
@@ -2510,6 +2547,7 @@ class CImage
|
|||||||
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
||||||
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
||||||
$lossy = $this->lossy ? "_l" : null;
|
$lossy = $this->lossy ? "_l" : null;
|
||||||
|
$interlace = $this->interlace ? "_i" : null;
|
||||||
|
|
||||||
$saveAs = $this->normalizeFileExtension();
|
$saveAs = $this->normalizeFileExtension();
|
||||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||||
@@ -2576,7 +2614,7 @@ class CImage
|
|||||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||||
. $optimize . $compress
|
. $optimize . $compress
|
||||||
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
||||||
. $convolve . $copyStrat . $lossy . $saveAs;
|
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
|
||||||
|
|
||||||
return $this->setTarget($file, $base);
|
return $this->setTarget($file, $base);
|
||||||
}
|
}
|
||||||
@@ -3548,6 +3586,12 @@ class CImage
|
|||||||
|
|
||||||
case 'jpeg':
|
case 'jpeg':
|
||||||
case 'jpg':
|
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}.");
|
$this->Log("Saving image as JPEG to cache using quality = {$this->quality}.");
|
||||||
imagejpeg($this->image, $this->cacheFileName, $this->quality);
|
imagejpeg($this->image, $this->cacheFileName, $this->quality);
|
||||||
|
|
||||||
@@ -4834,7 +4878,7 @@ if (isset($sizes[$newWidth])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Support width as % of original width
|
// Support width as % of original width
|
||||||
if ($newWidth[strlen($newWidth)-1] == '%') {
|
if ($newWidth && $newWidth[strlen($newWidth)-1] == '%') {
|
||||||
is_numeric(substr($newWidth, 0, -1))
|
is_numeric(substr($newWidth, 0, -1))
|
||||||
or errorPage('Width % not numeric.', 404);
|
or errorPage('Width % not numeric.', 404);
|
||||||
} else {
|
} else {
|
||||||
@@ -4859,7 +4903,7 @@ if (isset($sizes[$newHeight])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// height
|
// height
|
||||||
if ($newHeight[strlen($newHeight)-1] == '%') {
|
if ($newHeight && $newHeight[strlen($newHeight)-1] == '%') {
|
||||||
is_numeric(substr($newHeight, 0, -1))
|
is_numeric(substr($newHeight, 0, -1))
|
||||||
or errorPage('Height % out of range.', 404);
|
or errorPage('Height % out of range.', 404);
|
||||||
} else {
|
} else {
|
||||||
@@ -4890,7 +4934,7 @@ $aspectRatioConstant = getConfig('aspect_ratio_constant', function () {
|
|||||||
|
|
||||||
// Check to replace predefined aspect ratio
|
// Check to replace predefined aspect ratio
|
||||||
$aspectRatios = call_user_func($aspectRatioConstant);
|
$aspectRatios = call_user_func($aspectRatioConstant);
|
||||||
$negateAspectRatio = ($aspectRatio[0] == '!') ? true : false;
|
$negateAspectRatio = ($aspectRatio && $aspectRatio[0] == '!') ? true : false;
|
||||||
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
|
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
|
||||||
|
|
||||||
if (isset($aspectRatios[$aspectRatio])) {
|
if (isset($aspectRatios[$aspectRatio])) {
|
||||||
@@ -5314,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.
|
* Prepare a dummy image and use it as source image.
|
||||||
*/
|
*/
|
||||||
@@ -5475,6 +5531,7 @@ if (is_callable($hookBeforeCImage)) {
|
|||||||
'blur' => $blur,
|
'blur' => $blur,
|
||||||
'convolve' => $convolve,
|
'convolve' => $convolve,
|
||||||
'rotateAfter' => $rotateAfter,
|
'rotateAfter' => $rotateAfter,
|
||||||
|
'interlace' => $interlace,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => $outputFormat,
|
'outputFormat' => $outputFormat,
|
||||||
@@ -5563,6 +5620,7 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
|
|||||||
'blur' => $blur,
|
'blur' => $blur,
|
||||||
'convolve' => $convolve,
|
'convolve' => $convolve,
|
||||||
'rotateAfter' => $rotateAfter,
|
'rotateAfter' => $rotateAfter,
|
||||||
|
'interlace' => $interlace,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => $outputFormat,
|
'outputFormat' => $outputFormat,
|
||||||
|
@@ -38,7 +38,7 @@ $config = array(
|
|||||||
|
|
||||||
|
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.7.19 (2017-03-31)");
|
define("CIMAGE_VERSION", "v0.7.23 (2020-05-06)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
@@ -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.
|
* 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.
|
* @return void or array.
|
||||||
*/
|
*/
|
||||||
function verbose($msg = null)
|
function verbose($msg = null, $arg = "")
|
||||||
{
|
{
|
||||||
global $verbose, $verboseFile;
|
global $verbose, $verboseFile;
|
||||||
static $log = array();
|
static $log = array();
|
||||||
@@ -196,7 +215,15 @@ function verbose($msg = null)
|
|||||||
return $log;
|
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.
|
* Image copy strategy, defaults to RESAMPLE.
|
||||||
*/
|
*/
|
||||||
@@ -1948,6 +1982,7 @@ class CImage
|
|||||||
'blur' => null,
|
'blur' => null,
|
||||||
'convolve' => null,
|
'convolve' => null,
|
||||||
'rotateAfter' => null,
|
'rotateAfter' => null,
|
||||||
|
'interlace' => null,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => null,
|
'outputFormat' => null,
|
||||||
@@ -2133,13 +2168,15 @@ class CImage
|
|||||||
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
|
$this->log("Init dimension (before) newWidth x newHeight is {$this->newWidth} x {$this->newHeight}.");
|
||||||
|
|
||||||
// width as %
|
// width as %
|
||||||
if ($this->newWidth[strlen($this->newWidth)-1] == '%') {
|
if ($this->newWidth
|
||||||
|
&& $this->newWidth[strlen($this->newWidth)-1] == '%') {
|
||||||
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
|
$this->newWidth = $this->width * substr($this->newWidth, 0, -1) / 100;
|
||||||
$this->log("Setting new width based on % to {$this->newWidth}");
|
$this->log("Setting new width based on % to {$this->newWidth}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// height as %
|
// height as %
|
||||||
if ($this->newHeight[strlen($this->newHeight)-1] == '%') {
|
if ($this->newHeight
|
||||||
|
&& $this->newHeight[strlen($this->newHeight)-1] == '%') {
|
||||||
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
|
$this->newHeight = $this->height * substr($this->newHeight, 0, -1) / 100;
|
||||||
$this->log("Setting new height based on % to {$this->newHeight}");
|
$this->log("Setting new height based on % to {$this->newHeight}");
|
||||||
}
|
}
|
||||||
@@ -2510,6 +2547,7 @@ class CImage
|
|||||||
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
||||||
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
||||||
$lossy = $this->lossy ? "_l" : null;
|
$lossy = $this->lossy ? "_l" : null;
|
||||||
|
$interlace = $this->interlace ? "_i" : null;
|
||||||
|
|
||||||
$saveAs = $this->normalizeFileExtension();
|
$saveAs = $this->normalizeFileExtension();
|
||||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||||
@@ -2576,7 +2614,7 @@ class CImage
|
|||||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||||
. $optimize . $compress
|
. $optimize . $compress
|
||||||
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
||||||
. $convolve . $copyStrat . $lossy . $saveAs;
|
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
|
||||||
|
|
||||||
return $this->setTarget($file, $base);
|
return $this->setTarget($file, $base);
|
||||||
}
|
}
|
||||||
@@ -3548,6 +3586,12 @@ class CImage
|
|||||||
|
|
||||||
case 'jpeg':
|
case 'jpeg':
|
||||||
case 'jpg':
|
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}.");
|
$this->Log("Saving image as JPEG to cache using quality = {$this->quality}.");
|
||||||
imagejpeg($this->image, $this->cacheFileName, $this->quality);
|
imagejpeg($this->image, $this->cacheFileName, $this->quality);
|
||||||
|
|
||||||
@@ -4834,7 +4878,7 @@ if (isset($sizes[$newWidth])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Support width as % of original width
|
// Support width as % of original width
|
||||||
if ($newWidth[strlen($newWidth)-1] == '%') {
|
if ($newWidth && $newWidth[strlen($newWidth)-1] == '%') {
|
||||||
is_numeric(substr($newWidth, 0, -1))
|
is_numeric(substr($newWidth, 0, -1))
|
||||||
or errorPage('Width % not numeric.', 404);
|
or errorPage('Width % not numeric.', 404);
|
||||||
} else {
|
} else {
|
||||||
@@ -4859,7 +4903,7 @@ if (isset($sizes[$newHeight])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// height
|
// height
|
||||||
if ($newHeight[strlen($newHeight)-1] == '%') {
|
if ($newHeight && $newHeight[strlen($newHeight)-1] == '%') {
|
||||||
is_numeric(substr($newHeight, 0, -1))
|
is_numeric(substr($newHeight, 0, -1))
|
||||||
or errorPage('Height % out of range.', 404);
|
or errorPage('Height % out of range.', 404);
|
||||||
} else {
|
} else {
|
||||||
@@ -4890,7 +4934,7 @@ $aspectRatioConstant = getConfig('aspect_ratio_constant', function () {
|
|||||||
|
|
||||||
// Check to replace predefined aspect ratio
|
// Check to replace predefined aspect ratio
|
||||||
$aspectRatios = call_user_func($aspectRatioConstant);
|
$aspectRatios = call_user_func($aspectRatioConstant);
|
||||||
$negateAspectRatio = ($aspectRatio[0] == '!') ? true : false;
|
$negateAspectRatio = ($aspectRatio && $aspectRatio[0] == '!') ? true : false;
|
||||||
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
|
$aspectRatio = $negateAspectRatio ? substr($aspectRatio, 1) : $aspectRatio;
|
||||||
|
|
||||||
if (isset($aspectRatios[$aspectRatio])) {
|
if (isset($aspectRatios[$aspectRatio])) {
|
||||||
@@ -5314,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.
|
* Prepare a dummy image and use it as source image.
|
||||||
*/
|
*/
|
||||||
@@ -5475,6 +5531,7 @@ if (is_callable($hookBeforeCImage)) {
|
|||||||
'blur' => $blur,
|
'blur' => $blur,
|
||||||
'convolve' => $convolve,
|
'convolve' => $convolve,
|
||||||
'rotateAfter' => $rotateAfter,
|
'rotateAfter' => $rotateAfter,
|
||||||
|
'interlace' => $interlace,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => $outputFormat,
|
'outputFormat' => $outputFormat,
|
||||||
@@ -5563,6 +5620,7 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
|
|||||||
'blur' => $blur,
|
'blur' => $blur,
|
||||||
'convolve' => $convolve,
|
'convolve' => $convolve,
|
||||||
'rotateAfter' => $rotateAfter,
|
'rotateAfter' => $rotateAfter,
|
||||||
|
'interlace' => $interlace,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => $outputFormat,
|
'outputFormat' => $outputFormat,
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user