mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-30 02:49:50 +02:00
Compare commits
37 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
4c0ac8ed23 | ||
|
39b86628db | ||
|
5f4280d387 | ||
|
dd315dbd21 | ||
|
493118e1c5 | ||
|
e41b3d9877 | ||
|
bb60001c36 | ||
|
adeca3f9f9 | ||
|
a5662690fe | ||
|
3cfa9a6a98 | ||
|
4ecebcd5b4 | ||
|
9196d1ee41 | ||
|
0249056761 | ||
|
4ea72be49a | ||
|
2ce1f18fe5 | ||
|
0f1f537b62 | ||
|
1411adc828 | ||
|
86737af69e | ||
|
c563275ed5 | ||
|
8fec09b195 | ||
|
ac16343cd7 | ||
|
cd142c5880 | ||
|
91dd92d483 | ||
|
4b64d921d1 | ||
|
4211d7e0e6 | ||
|
dd8878c8bd | ||
|
f9604518e4 | ||
|
61aa52854e | ||
|
401478c839 | ||
|
f0ab9479d6 | ||
|
9ff7a61ca9 | ||
|
3170beb832 | ||
|
8001f72a1a | ||
|
0f9e0220f1 | ||
|
e59ef91991 | ||
|
2337dbe94c | ||
|
c5de59a754 |
33
CImage.php
33
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}");
|
||||||
}
|
}
|
||||||
@@ -1365,6 +1375,7 @@ class CImage
|
|||||||
&& !$this->autoRotate
|
&& !$this->autoRotate
|
||||||
&& !$this->bgColor
|
&& !$this->bgColor
|
||||||
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
||||||
|
&& !$this->lossy
|
||||||
) {
|
) {
|
||||||
$this->log("Using original image.");
|
$this->log("Using original image.");
|
||||||
$this->output($this->pathToImage);
|
$this->output($this->pathToImage);
|
||||||
@@ -1398,6 +1409,8 @@ class CImage
|
|||||||
$compress = $this->compress ? "_co{$this->compress}" : null;
|
$compress = $this->compress ? "_co{$this->compress}" : null;
|
||||||
$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;
|
||||||
|
$interlace = $this->interlace ? "_i" : null;
|
||||||
|
|
||||||
$saveAs = $this->normalizeFileExtension();
|
$saveAs = $this->normalizeFileExtension();
|
||||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||||
@@ -1464,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 . $saveAs;
|
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
|
||||||
|
|
||||||
return $this->setTarget($file, $base);
|
return $this->setTarget($file, $base);
|
||||||
}
|
}
|
||||||
@@ -2436,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);
|
||||||
|
|
||||||
@@ -2774,18 +2793,18 @@ class CImage
|
|||||||
$lastModified = filemtime($this->pathToImage);
|
$lastModified = filemtime($this->pathToImage);
|
||||||
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$details['cache'] = basename($this->cacheFileName);
|
$details['cache'] = basename($this->cacheFileName ?? "");
|
||||||
$lastModified = filemtime($this->cacheFileName);
|
$lastModified = filemtime($this->cacheFileName ?? "");
|
||||||
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$this->load($file);
|
$this->load($file);
|
||||||
|
|
||||||
$details['filename'] = basename($file);
|
$details['filename'] = basename($file ?? "");
|
||||||
$details['mimeType'] = $this->getMimeType($this->fileType);
|
$details['mimeType'] = $this->getMimeType($this->fileType);
|
||||||
$details['width'] = $this->width;
|
$details['width'] = $this->width;
|
||||||
$details['height'] = $this->height;
|
$details['height'] = $this->height;
|
||||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||||
$details['size'] = filesize($file);
|
$details['size'] = filesize($file ?? "");
|
||||||
$details['colors'] = $this->colorsTotal($this->image);
|
$details['colors'] = $this->colorsTotal($this->image);
|
||||||
$details['includedFiles'] = count(get_included_files());
|
$details['includedFiles'] = count(get_included_files());
|
||||||
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
||||||
|
@@ -49,14 +49,14 @@ There are several ways of installing. You either install the whole project which
|
|||||||
|
|
||||||
The [sourcode is available on GitHub](https://github.com/mosbth/cimage). Clone, fork or [download as zip](https://github.com/mosbth/cimage/archive/master.zip).
|
The [sourcode is available on GitHub](https://github.com/mosbth/cimage). Clone, fork or [download as zip](https://github.com/mosbth/cimage/archive/master.zip).
|
||||||
|
|
||||||
**Latest stable version is v0.7.16 released 2016-08-09.**
|
**Latest stable version is v0.7.18 released 2016-08-09.**
|
||||||
|
|
||||||
I prefer cloning like this. Do switch to the latest stable version.
|
I prefer cloning like this. Do switch to the latest stable version.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone git://github.com/mosbth/cimage.git
|
git clone git://github.com/mosbth/cimage.git
|
||||||
cd cimage
|
cd cimage
|
||||||
git checkout v0.7.16
|
git checkout v0.7.18
|
||||||
```
|
```
|
||||||
|
|
||||||
Make the cache-directory writable by the webserver.
|
Make the cache-directory writable by the webserver.
|
||||||
@@ -79,7 +79,7 @@ There are some all-included bundles of `img.php` that can be downloaded and used
|
|||||||
Dowload the version of your choice like this.
|
Dowload the version of your choice like this.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
wget https://raw.githubusercontent.com/mosbth/cimage/v0.7.16/webroot/imgp.php
|
wget https://raw.githubusercontent.com/mosbth/cimage/v0.7.18/webroot/imgp.php
|
||||||
```
|
```
|
||||||
|
|
||||||
Open up the file in your editor and edit the array `$config`. Ensure that the paths to the image directory and the cache directory matches your environment, or create an own config-file for the script.
|
Open up the file in your editor and edit the array `$config`. Ensure that the paths to the image directory and the cache directory matches your environment, or create an own config-file for the script.
|
||||||
|
82
REVISION.md
82
REVISION.md
@@ -5,6 +5,88 @@ Revision history
|
|||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
||||||
|
|
||||||
|
|
||||||
|
v0.8.3 (2022-05-24)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Support PHP 8.1 and remove deprecated messages when run in in development mode.
|
||||||
|
* Generate prebuilt all include files for various settings
|
||||||
|
* Fix deprecated for PHP 8.1
|
||||||
|
* Fix deprecated for PHP 8.1
|
||||||
|
* Add php version as output in verbose mode
|
||||||
|
* Add PHP 81 as test environment
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
v0.8.2 (2021-10-27)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Remove bad configuration.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
v0.8.1 (2020-06-08)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Updated version number in define.php.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Move exception handler from functions.php to img.php #166.
|
||||||
|
* Correct XSS injection in `check_system.php`.
|
||||||
|
* Composer suggests ext-imagick and ext-curl.
|
||||||
|
|
||||||
|
|
||||||
|
v0.7.18 (2016-08-09)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Made `&lossless` a requirement to not use the original image.
|
||||||
|
|
||||||
|
|
||||||
|
v0.7.17 (2016-08-09)
|
||||||
|
-------------------------------------
|
||||||
|
|
||||||
|
* Made `&lossless` part of the generated cache filename.
|
||||||
|
|
||||||
|
|
||||||
v0.7.16 (2016-08-09)
|
v0.7.16 (2016-08-09)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
|
6
SECURITY.md
Normal file
6
SECURITY.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Security policy
|
||||||
|
======================
|
||||||
|
|
||||||
|
To report security vulnerabilities in the project, send en email to mikael.t.h.roos@gmail.com.
|
||||||
|
|
||||||
|
For other security related issues, please open an issue on the project.
|
@@ -18,11 +18,13 @@
|
|||||||
"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-exif": "*",
|
||||||
|
"ext-gd": "*",
|
||||||
|
"ext-imagick": "*"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"files": [
|
"files": [
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.7.16 (2016-08-09)");
|
define("CIMAGE_VERSION", "v0.8.3 (2022-05-24)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
|
88
docker-compose.yaml
Normal file
88
docker-compose.yaml
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
cli:
|
||||||
|
image: anax/dev
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
apache:
|
||||||
|
image: anax/dev:apache
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
ports: [ "11000:80" ]
|
||||||
|
|
||||||
|
remserver:
|
||||||
|
image: anax/dev:apache
|
||||||
|
ports:
|
||||||
|
- "8090:80"
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php81:
|
||||||
|
image: anax/dev:php81
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php81-apache:
|
||||||
|
image: anax/dev:php81-apache
|
||||||
|
ports: [ "11081:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php80:
|
||||||
|
image: anax/dev:php80
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php80-apache:
|
||||||
|
image: anax/dev:php80-apache
|
||||||
|
ports: [ "11080:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php74:
|
||||||
|
image: anax/dev:php74
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php74-apache:
|
||||||
|
image: anax/dev:php74-apache
|
||||||
|
ports: [ "11074:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php73:
|
||||||
|
image: anax/dev:php73
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php73-apache:
|
||||||
|
image: anax/dev:php73-apache
|
||||||
|
ports: [ "11073:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php72:
|
||||||
|
image: anax/dev:php72
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php72-apache:
|
||||||
|
image: anax/dev:php72-apache
|
||||||
|
ports: [ "11072:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php71:
|
||||||
|
image: anax/dev:php71
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php71-apache:
|
||||||
|
image: anax/dev:php71-apache
|
||||||
|
ports: [ "11071:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php70:
|
||||||
|
image: anax/dev:php70
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php70:
|
||||||
|
image: anax/dev:php70-apache
|
||||||
|
ports: [ "11070:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php56:
|
||||||
|
image: anax/dev:php56
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
||||||
|
|
||||||
|
php56:
|
||||||
|
image: anax/dev:php56-apache
|
||||||
|
ports: [ "11056:80" ]
|
||||||
|
volumes: [ ".:/home/anax/repo" ]
|
@@ -67,22 +67,6 @@ function errorPage($msg, $type = 500)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom exception handler.
|
|
||||||
*/
|
|
||||||
set_exception_handler(function ($exception) {
|
|
||||||
errorPage(
|
|
||||||
"<p><b>img.php: Uncaught exception:</b> <p>"
|
|
||||||
. $exception->getMessage()
|
|
||||||
. "</p><pre>"
|
|
||||||
. $exception->getTraceAsString()
|
|
||||||
. "</pre>",
|
|
||||||
500
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get input from query string or return default value if not set.
|
* Get input from query string or return default value if not set.
|
||||||
*
|
*
|
||||||
@@ -123,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.
|
||||||
*
|
*
|
||||||
@@ -148,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();
|
||||||
@@ -161,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
echo 'Current PHP version: ' . phpversion() . '<br><br>';
|
echo 'Current PHP version: ' . phpversion() . '<br><br>';
|
||||||
|
|
||||||
echo 'Running on: ' . $_SERVER['SERVER_SOFTWARE'] . '<br><br>';
|
echo 'Running on: ' . htmlentities($_SERVER['SERVER_SOFTWARE']) . '<br><br>';
|
||||||
|
|
||||||
$no = extension_loaded('exif') ? null : 'NOT';
|
$no = extension_loaded('exif') ? null : 'NOT';
|
||||||
echo "Extension exif is $no loaded.<br>";
|
echo "Extension exif is $no loaded.<br>";
|
||||||
|
@@ -3,6 +3,12 @@
|
|||||||
<head>
|
<head>
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
function e($str) {
|
||||||
|
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
body {
|
body {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,15 +134,15 @@ if (isset($_GET['input1'])) {
|
|||||||
// Use incoming from querystring as defaults
|
// Use incoming from querystring as defaults
|
||||||
?>
|
?>
|
||||||
CImage.compare({
|
CImage.compare({
|
||||||
"input1": "<?=$_GET['input1']?>",
|
"input1": "<?=e($_GET['input1'])?>",
|
||||||
"input2": "<?=$_GET['input2']?>",
|
"input2": "<?=e($_GET['input2'])?>",
|
||||||
"input3": "<?=$_GET['input3']?>",
|
"input3": "<?=e($_GET['input3'])?>",
|
||||||
"input4": "<?=$_GET['input4']?>",
|
"input4": "<?=e($_GET['input4'])?>",
|
||||||
"input5": "<?=$_GET['input5']?>",
|
"input5": "<?=e($_GET['input5'])?>",
|
||||||
"input6": "<?=$_GET['input6']?>",
|
"input6": "<?=e($_GET['input6'])?>",
|
||||||
"json": <?=$_GET['json']?>,
|
"json": <?=e($_GET['json'])?>,
|
||||||
"stack": <?=$_GET['stack']?>,
|
"stack": <?=e($_GET['stack'])?>,
|
||||||
"bg": <?=$_GET['bg']?>
|
"bg": <?=e($_GET['bg'])?>
|
||||||
});
|
});
|
||||||
<?php
|
<?php
|
||||||
} elseif (isset($script)) {
|
} elseif (isset($script)) {
|
||||||
|
@@ -8,6 +8,22 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom exception handler.
|
||||||
|
*/
|
||||||
|
set_exception_handler(function ($exception) {
|
||||||
|
errorPage(
|
||||||
|
"<p><b>img.php: Uncaught exception:</b> <p>"
|
||||||
|
. $exception->getMessage()
|
||||||
|
. "</p><pre>"
|
||||||
|
. $exception->getTraceAsString()
|
||||||
|
. "</pre>",
|
||||||
|
500
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get configuration options from file, if the file exists, else use $config
|
* Get configuration options from file, if the file exists, else use $config
|
||||||
* if its defined or create an empty $config.
|
* if its defined or create an empty $config.
|
||||||
@@ -170,7 +186,7 @@ $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array());
|
|||||||
|
|
||||||
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
||||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
||||||
$refererHost = parse_url($referer, PHP_URL_HOST);
|
$refererHost = parse_url($referer ?? "", PHP_URL_HOST);
|
||||||
|
|
||||||
if (!$allowHotlinking) {
|
if (!$allowHotlinking) {
|
||||||
if ($passwordMatch) {
|
if ($passwordMatch) {
|
||||||
@@ -307,7 +323,7 @@ $srcImage = urldecode(get('src'))
|
|||||||
or errorPage('Must set src-attribute.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
// Get settings for src-alt as backup image
|
// Get settings for src-alt as backup image
|
||||||
$srcAltImage = urldecode(get('src-alt', null));
|
$srcAltImage = urldecode(get('src-alt', ""));
|
||||||
$srcAltConfig = getConfig('src_alt', null);
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
if (empty($srcAltImage)) {
|
if (empty($srcAltImage)) {
|
||||||
$srcAltImage = $srcAltConfig;
|
$srcAltImage = $srcAltConfig;
|
||||||
@@ -424,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 {
|
||||||
@@ -449,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 {
|
||||||
@@ -480,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])) {
|
||||||
@@ -904,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.
|
||||||
*/
|
*/
|
||||||
@@ -1065,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,
|
||||||
@@ -1120,7 +1149,8 @@ EOD;
|
|||||||
/**
|
/**
|
||||||
* Load, process and output the image
|
* Load, process and output the image
|
||||||
*/
|
*/
|
||||||
$img->log("Incoming arguments: " . print_r(verbose(), 1))
|
$img->log("PHP version: " . phpversion())
|
||||||
|
->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||||
->setSaveFolder($cachePath)
|
->setSaveFolder($cachePath)
|
||||||
->useCache($useCache)
|
->useCache($useCache)
|
||||||
->setSource($srcImage, $imagePath)
|
->setSource($srcImage, $imagePath)
|
||||||
@@ -1153,6 +1183,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',
|
||||||
|
|
||||||
|
|
||||||
@@ -342,7 +342,7 @@ return array(
|
|||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
'postprocessing' => array(
|
'postprocessing' => array(
|
||||||
'png_lossy' => false,
|
'png_lossy' => null,
|
||||||
'png_lossy_cmd' => '/usr/local/bin/pngquant --force --output',
|
'png_lossy_cmd' => '/usr/local/bin/pngquant --force --output',
|
||||||
|
|
||||||
'png_filter' => false,
|
'png_filter' => false,
|
||||||
@@ -485,6 +485,18 @@ return array(
|
|||||||
"scale" => 14,
|
"scale" => 14,
|
||||||
"luminanceStrategy" => 3,
|
"luminanceStrategy" => 3,
|
||||||
"customCharacterSet" => null,
|
"customCharacterSet" => null,
|
||||||
);
|
), */
|
||||||
},*/
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default options for creating interlaced progressive JPEG images. Set
|
||||||
|
* to true to always render jpeg images as interlaced. This setting can
|
||||||
|
* be overridden by using `?interlace`, `?interlace=true` or
|
||||||
|
* `?interlace=false`.
|
||||||
|
*
|
||||||
|
* Default values are:
|
||||||
|
* interlace: false
|
||||||
|
*/
|
||||||
|
/*'interlace' => false,*/
|
||||||
);
|
);
|
||||||
|
217
webroot/imgd.php
217
webroot/imgd.php
@@ -38,7 +38,7 @@ $config = array(
|
|||||||
|
|
||||||
|
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.7.15 (2016-08-09)");
|
define("CIMAGE_VERSION", "v0.8.3 (2022-05-24)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
@@ -118,22 +118,6 @@ function errorPage($msg, $type = 500)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom exception handler.
|
|
||||||
*/
|
|
||||||
set_exception_handler(function ($exception) {
|
|
||||||
errorPage(
|
|
||||||
"<p><b>img.php: Uncaught exception:</b> <p>"
|
|
||||||
. $exception->getMessage()
|
|
||||||
. "</p><pre>"
|
|
||||||
. $exception->getTraceAsString()
|
|
||||||
. "</pre>",
|
|
||||||
500
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get input from query string or return default value if not set.
|
* Get input from query string or return default value if not set.
|
||||||
*
|
*
|
||||||
@@ -174,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.
|
||||||
*
|
*
|
||||||
@@ -199,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();
|
||||||
@@ -212,7 +215,36 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log when verbose mode, when used without argument it returns the result.
|
||||||
|
*
|
||||||
|
* @param string $msg to log.
|
||||||
|
*
|
||||||
|
* @return void or array.
|
||||||
|
*/
|
||||||
|
function checkExternalCommand($what, $enabled, $commandString)
|
||||||
|
{
|
||||||
|
$no = $enabled ? null : 'NOT';
|
||||||
|
$text = "Post processing $what is $no enabled.<br>";
|
||||||
|
|
||||||
|
list($command) = explode(" ", $commandString);
|
||||||
|
$no = is_executable($command) ? null : 'NOT';
|
||||||
|
$text .= "The command for $what is $no an executable.<br>";
|
||||||
|
|
||||||
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1260,6 +1292,13 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do lossy output using external postprocessing tools.
|
||||||
|
*/
|
||||||
|
private $lossy = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verbose mode to print out a trace and display the created image
|
* Verbose mode to print out a trace and display the created image
|
||||||
*/
|
*/
|
||||||
@@ -1295,7 +1334,15 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path to command for filter optimize, for example optipng or null.
|
* Path to command for lossy optimize, for example pngquant.
|
||||||
|
*/
|
||||||
|
private $pngLossy;
|
||||||
|
private $pngLossyCmd;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path to command for filter optimize, for example optipng.
|
||||||
*/
|
*/
|
||||||
private $pngFilter;
|
private $pngFilter;
|
||||||
private $pngFilterCmd;
|
private $pngFilterCmd;
|
||||||
@@ -1303,7 +1350,7 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path to command for deflate optimize, for example pngout or null.
|
* Path to command for deflate optimize, for example pngout.
|
||||||
*/
|
*/
|
||||||
private $pngDeflate;
|
private $pngDeflate;
|
||||||
private $pngDeflateCmd;
|
private $pngDeflateCmd;
|
||||||
@@ -1513,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.
|
||||||
*/
|
*/
|
||||||
@@ -1928,10 +1982,14 @@ class CImage
|
|||||||
'blur' => null,
|
'blur' => null,
|
||||||
'convolve' => null,
|
'convolve' => null,
|
||||||
'rotateAfter' => null,
|
'rotateAfter' => null,
|
||||||
|
'interlace' => null,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => null,
|
'outputFormat' => null,
|
||||||
'dpr' => 1,
|
'dpr' => 1,
|
||||||
|
|
||||||
|
// Postprocessing using external tools
|
||||||
|
'lossy' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Convert crop settings from string to array
|
// Convert crop settings from string to array
|
||||||
@@ -2110,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}");
|
||||||
}
|
}
|
||||||
@@ -2452,6 +2512,7 @@ class CImage
|
|||||||
&& !$this->autoRotate
|
&& !$this->autoRotate
|
||||||
&& !$this->bgColor
|
&& !$this->bgColor
|
||||||
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
||||||
|
&& !$this->lossy
|
||||||
) {
|
) {
|
||||||
$this->log("Using original image.");
|
$this->log("Using original image.");
|
||||||
$this->output($this->pathToImage);
|
$this->output($this->pathToImage);
|
||||||
@@ -2485,6 +2546,8 @@ class CImage
|
|||||||
$compress = $this->compress ? "_co{$this->compress}" : null;
|
$compress = $this->compress ? "_co{$this->compress}" : null;
|
||||||
$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;
|
||||||
|
$interlace = $this->interlace ? "_i" : null;
|
||||||
|
|
||||||
$saveAs = $this->normalizeFileExtension();
|
$saveAs = $this->normalizeFileExtension();
|
||||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||||
@@ -2551,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 . $saveAs;
|
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
|
||||||
|
|
||||||
return $this->setTarget($file, $base);
|
return $this->setTarget($file, $base);
|
||||||
}
|
}
|
||||||
@@ -3450,6 +3513,14 @@ class CImage
|
|||||||
$this->jpegOptimizeCmd = null;
|
$this->jpegOptimizeCmd = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists("png_lossy", $options)
|
||||||
|
&& $options['png_lossy'] !== false) {
|
||||||
|
$this->pngLossy = $options['png_lossy'];
|
||||||
|
$this->pngLossyCmd = $options['png_lossy_cmd'];
|
||||||
|
} else {
|
||||||
|
$this->pngLossyCmd = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($options['png_filter']) && $options['png_filter']) {
|
if (isset($options['png_filter']) && $options['png_filter']) {
|
||||||
$this->pngFilterCmd = $options['png_filter_cmd'];
|
$this->pngFilterCmd = $options['png_filter_cmd'];
|
||||||
} else {
|
} else {
|
||||||
@@ -3515,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);
|
||||||
|
|
||||||
@@ -3551,6 +3628,24 @@ class CImage
|
|||||||
imagesavealpha($this->image, true);
|
imagesavealpha($this->image, true);
|
||||||
imagepng($this->image, $this->cacheFileName, $this->compress);
|
imagepng($this->image, $this->cacheFileName, $this->compress);
|
||||||
|
|
||||||
|
// Use external program to process lossy PNG, if defined
|
||||||
|
$lossyEnabled = $this->pngLossy === true;
|
||||||
|
$lossySoftEnabled = $this->pngLossy === null;
|
||||||
|
$lossyActiveEnabled = $this->lossy === true;
|
||||||
|
if ($lossyEnabled || ($lossySoftEnabled && $lossyActiveEnabled)) {
|
||||||
|
if ($this->verbose) {
|
||||||
|
clearstatcache();
|
||||||
|
$this->log("Lossy enabled: $lossyEnabled");
|
||||||
|
$this->log("Lossy soft enabled: $lossySoftEnabled");
|
||||||
|
$this->Log("Filesize before lossy optimize: " . filesize($this->cacheFileName) . " bytes.");
|
||||||
|
}
|
||||||
|
$res = array();
|
||||||
|
$cmd = $this->pngLossyCmd . " $this->cacheFileName $this->cacheFileName";
|
||||||
|
exec($cmd, $res);
|
||||||
|
$this->Log($cmd);
|
||||||
|
$this->Log($res);
|
||||||
|
}
|
||||||
|
|
||||||
// Use external program to filter PNG, if defined
|
// Use external program to filter PNG, if defined
|
||||||
if ($this->pngFilterCmd) {
|
if ($this->pngFilterCmd) {
|
||||||
if ($this->verbose) {
|
if ($this->verbose) {
|
||||||
@@ -3835,18 +3930,18 @@ class CImage
|
|||||||
$lastModified = filemtime($this->pathToImage);
|
$lastModified = filemtime($this->pathToImage);
|
||||||
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$details['cache'] = basename($this->cacheFileName);
|
$details['cache'] = basename($this->cacheFileName ?? "");
|
||||||
$lastModified = filemtime($this->cacheFileName);
|
$lastModified = filemtime($this->cacheFileName ?? "");
|
||||||
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$this->load($file);
|
$this->load($file);
|
||||||
|
|
||||||
$details['filename'] = basename($file);
|
$details['filename'] = basename($file ?? "");
|
||||||
$details['mimeType'] = $this->getMimeType($this->fileType);
|
$details['mimeType'] = $this->getMimeType($this->fileType);
|
||||||
$details['width'] = $this->width;
|
$details['width'] = $this->width;
|
||||||
$details['height'] = $this->height;
|
$details['height'] = $this->height;
|
||||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||||
$details['size'] = filesize($file);
|
$details['size'] = filesize($file ?? "");
|
||||||
$details['colors'] = $this->colorsTotal($this->image);
|
$details['colors'] = $this->colorsTotal($this->image);
|
||||||
$details['includedFiles'] = count(get_included_files());
|
$details['includedFiles'] = count(get_included_files());
|
||||||
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
||||||
@@ -4351,6 +4446,22 @@ class CFastTrackCache
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom exception handler.
|
||||||
|
*/
|
||||||
|
set_exception_handler(function ($exception) {
|
||||||
|
errorPage(
|
||||||
|
"<p><b>img.php: Uncaught exception:</b> <p>"
|
||||||
|
. $exception->getMessage()
|
||||||
|
. "</p><pre>"
|
||||||
|
. $exception->getTraceAsString()
|
||||||
|
. "</pre>",
|
||||||
|
500
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get configuration options from file, if the file exists, else use $config
|
* Get configuration options from file, if the file exists, else use $config
|
||||||
* if its defined or create an empty $config.
|
* if its defined or create an empty $config.
|
||||||
@@ -4513,7 +4624,7 @@ $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array());
|
|||||||
|
|
||||||
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
||||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
||||||
$refererHost = parse_url($referer, PHP_URL_HOST);
|
$refererHost = parse_url($referer ?? "", PHP_URL_HOST);
|
||||||
|
|
||||||
if (!$allowHotlinking) {
|
if (!$allowHotlinking) {
|
||||||
if ($passwordMatch) {
|
if ($passwordMatch) {
|
||||||
@@ -4650,7 +4761,7 @@ $srcImage = urldecode(get('src'))
|
|||||||
or errorPage('Must set src-attribute.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
// Get settings for src-alt as backup image
|
// Get settings for src-alt as backup image
|
||||||
$srcAltImage = urldecode(get('src-alt', null));
|
$srcAltImage = urldecode(get('src-alt', ""));
|
||||||
$srcAltConfig = getConfig('src_alt', null);
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
if (empty($srcAltImage)) {
|
if (empty($srcAltImage)) {
|
||||||
$srcAltImage = $srcAltConfig;
|
$srcAltImage = $srcAltConfig;
|
||||||
@@ -4767,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 {
|
||||||
@@ -4792,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 {
|
||||||
@@ -4823,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])) {
|
||||||
@@ -5183,6 +5294,9 @@ verbose("upscale = $upscale");
|
|||||||
* Get details for post processing
|
* Get details for post processing
|
||||||
*/
|
*/
|
||||||
$postProcessing = getConfig('postprocessing', array(
|
$postProcessing = getConfig('postprocessing', array(
|
||||||
|
'png_lossy' => false,
|
||||||
|
'png_lossy_cmd' => '/usr/local/bin/pngquant --force --output',
|
||||||
|
|
||||||
'png_filter' => false,
|
'png_filter' => false,
|
||||||
'png_filter_cmd' => '/usr/local/bin/optipng -q',
|
'png_filter_cmd' => '/usr/local/bin/optipng -q',
|
||||||
|
|
||||||
@@ -5195,6 +5309,15 @@ $postProcessing = getConfig('postprocessing', array(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lossy - Do lossy postprocessing, if available.
|
||||||
|
*/
|
||||||
|
$lossy = getDefined(array('lossy'), true, null);
|
||||||
|
|
||||||
|
verbose("lossy = $lossy");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* alias - Save resulting image to another alias name.
|
* alias - Save resulting image to another alias name.
|
||||||
* Password always apply, must be defined.
|
* Password always apply, must be defined.
|
||||||
@@ -5235,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.
|
||||||
*/
|
*/
|
||||||
@@ -5313,7 +5448,7 @@ if ($status) {
|
|||||||
$res = $cache->getStatusOfSubdir("srgb");
|
$res = $cache->getStatusOfSubdir("srgb");
|
||||||
$text .= "Cache srgb $res\n";
|
$text .= "Cache srgb $res\n";
|
||||||
|
|
||||||
$res = $cache->getStatusOfSubdir($fasttrackCache);
|
$res = $cache->getStatusOfSubdir($fastTrackCache);
|
||||||
$text .= "Cache fasttrack $res\n";
|
$text .= "Cache fasttrack $res\n";
|
||||||
|
|
||||||
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
||||||
@@ -5330,6 +5465,11 @@ if ($status) {
|
|||||||
$no = extension_loaded('gd') ? null : 'NOT';
|
$no = extension_loaded('gd') ? null : 'NOT';
|
||||||
$text .= "Extension gd is $no loaded.<br>";
|
$text .= "Extension gd is $no loaded.<br>";
|
||||||
|
|
||||||
|
$text .= checkExternalCommand("PNG LOSSY", $postProcessing["png_lossy"], $postProcessing["png_lossy_cmd"]);
|
||||||
|
$text .= checkExternalCommand("PNG FILTER", $postProcessing["png_filter"], $postProcessing["png_filter_cmd"]);
|
||||||
|
$text .= checkExternalCommand("PNG DEFLATE", $postProcessing["png_deflate"], $postProcessing["png_deflate_cmd"]);
|
||||||
|
$text .= checkExternalCommand("JPEG OPTIMIZE", $postProcessing["jpeg_optimize"], $postProcessing["jpeg_optimize_cmd"]);
|
||||||
|
|
||||||
if (!$no) {
|
if (!$no) {
|
||||||
$text .= print_r(gd_info(), 1);
|
$text .= print_r(gd_info(), 1);
|
||||||
}
|
}
|
||||||
@@ -5391,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,
|
||||||
@@ -5398,6 +5539,7 @@ if (is_callable($hookBeforeCImage)) {
|
|||||||
|
|
||||||
// Other
|
// Other
|
||||||
'postProcessing' => $postProcessing,
|
'postProcessing' => $postProcessing,
|
||||||
|
'lossy' => $lossy,
|
||||||
));
|
));
|
||||||
verbose(print_r($allConfig, 1));
|
verbose(print_r($allConfig, 1));
|
||||||
extract($allConfig);
|
extract($allConfig);
|
||||||
@@ -5445,7 +5587,8 @@ EOD;
|
|||||||
/**
|
/**
|
||||||
* Load, process and output the image
|
* Load, process and output the image
|
||||||
*/
|
*/
|
||||||
$img->log("Incoming arguments: " . print_r(verbose(), 1))
|
$img->log("PHP version: " . phpversion())
|
||||||
|
->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||||
->setSaveFolder($cachePath)
|
->setSaveFolder($cachePath)
|
||||||
->useCache($useCache)
|
->useCache($useCache)
|
||||||
->setSource($srcImage, $imagePath)
|
->setSource($srcImage, $imagePath)
|
||||||
@@ -5478,10 +5621,14 @@ $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,
|
||||||
'dpr' => $dpr,
|
'dpr' => $dpr,
|
||||||
|
|
||||||
|
// Postprocessing using external tools
|
||||||
|
'lossy' => $lossy,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
->loadImageDetails()
|
->loadImageDetails()
|
||||||
|
217
webroot/imgp.php
217
webroot/imgp.php
@@ -38,7 +38,7 @@ $config = array(
|
|||||||
|
|
||||||
|
|
||||||
// Version of cimage and img.php
|
// Version of cimage and img.php
|
||||||
define("CIMAGE_VERSION", "v0.7.15 (2016-08-09)");
|
define("CIMAGE_VERSION", "v0.8.3 (2022-05-24)");
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||||
@@ -118,22 +118,6 @@ function errorPage($msg, $type = 500)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom exception handler.
|
|
||||||
*/
|
|
||||||
set_exception_handler(function ($exception) {
|
|
||||||
errorPage(
|
|
||||||
"<p><b>img.php: Uncaught exception:</b> <p>"
|
|
||||||
. $exception->getMessage()
|
|
||||||
. "</p><pre>"
|
|
||||||
. $exception->getTraceAsString()
|
|
||||||
. "</pre>",
|
|
||||||
500
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get input from query string or return default value if not set.
|
* Get input from query string or return default value if not set.
|
||||||
*
|
*
|
||||||
@@ -174,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.
|
||||||
*
|
*
|
||||||
@@ -199,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();
|
||||||
@@ -212,7 +215,36 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log when verbose mode, when used without argument it returns the result.
|
||||||
|
*
|
||||||
|
* @param string $msg to log.
|
||||||
|
*
|
||||||
|
* @return void or array.
|
||||||
|
*/
|
||||||
|
function checkExternalCommand($what, $enabled, $commandString)
|
||||||
|
{
|
||||||
|
$no = $enabled ? null : 'NOT';
|
||||||
|
$text = "Post processing $what is $no enabled.<br>";
|
||||||
|
|
||||||
|
list($command) = explode(" ", $commandString);
|
||||||
|
$no = is_executable($command) ? null : 'NOT';
|
||||||
|
$text .= "The command for $what is $no an executable.<br>";
|
||||||
|
|
||||||
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1260,6 +1292,13 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do lossy output using external postprocessing tools.
|
||||||
|
*/
|
||||||
|
private $lossy = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verbose mode to print out a trace and display the created image
|
* Verbose mode to print out a trace and display the created image
|
||||||
*/
|
*/
|
||||||
@@ -1295,7 +1334,15 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path to command for filter optimize, for example optipng or null.
|
* Path to command for lossy optimize, for example pngquant.
|
||||||
|
*/
|
||||||
|
private $pngLossy;
|
||||||
|
private $pngLossyCmd;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path to command for filter optimize, for example optipng.
|
||||||
*/
|
*/
|
||||||
private $pngFilter;
|
private $pngFilter;
|
||||||
private $pngFilterCmd;
|
private $pngFilterCmd;
|
||||||
@@ -1303,7 +1350,7 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path to command for deflate optimize, for example pngout or null.
|
* Path to command for deflate optimize, for example pngout.
|
||||||
*/
|
*/
|
||||||
private $pngDeflate;
|
private $pngDeflate;
|
||||||
private $pngDeflateCmd;
|
private $pngDeflateCmd;
|
||||||
@@ -1513,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.
|
||||||
*/
|
*/
|
||||||
@@ -1928,10 +1982,14 @@ class CImage
|
|||||||
'blur' => null,
|
'blur' => null,
|
||||||
'convolve' => null,
|
'convolve' => null,
|
||||||
'rotateAfter' => null,
|
'rotateAfter' => null,
|
||||||
|
'interlace' => null,
|
||||||
|
|
||||||
// Output format
|
// Output format
|
||||||
'outputFormat' => null,
|
'outputFormat' => null,
|
||||||
'dpr' => 1,
|
'dpr' => 1,
|
||||||
|
|
||||||
|
// Postprocessing using external tools
|
||||||
|
'lossy' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Convert crop settings from string to array
|
// Convert crop settings from string to array
|
||||||
@@ -2110,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}");
|
||||||
}
|
}
|
||||||
@@ -2452,6 +2512,7 @@ class CImage
|
|||||||
&& !$this->autoRotate
|
&& !$this->autoRotate
|
||||||
&& !$this->bgColor
|
&& !$this->bgColor
|
||||||
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
||||||
|
&& !$this->lossy
|
||||||
) {
|
) {
|
||||||
$this->log("Using original image.");
|
$this->log("Using original image.");
|
||||||
$this->output($this->pathToImage);
|
$this->output($this->pathToImage);
|
||||||
@@ -2485,6 +2546,8 @@ class CImage
|
|||||||
$compress = $this->compress ? "_co{$this->compress}" : null;
|
$compress = $this->compress ? "_co{$this->compress}" : null;
|
||||||
$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;
|
||||||
|
$interlace = $this->interlace ? "_i" : null;
|
||||||
|
|
||||||
$saveAs = $this->normalizeFileExtension();
|
$saveAs = $this->normalizeFileExtension();
|
||||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||||
@@ -2551,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 . $saveAs;
|
. $convolve . $copyStrat . $lossy . $interlace . $saveAs;
|
||||||
|
|
||||||
return $this->setTarget($file, $base);
|
return $this->setTarget($file, $base);
|
||||||
}
|
}
|
||||||
@@ -3450,6 +3513,14 @@ class CImage
|
|||||||
$this->jpegOptimizeCmd = null;
|
$this->jpegOptimizeCmd = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists("png_lossy", $options)
|
||||||
|
&& $options['png_lossy'] !== false) {
|
||||||
|
$this->pngLossy = $options['png_lossy'];
|
||||||
|
$this->pngLossyCmd = $options['png_lossy_cmd'];
|
||||||
|
} else {
|
||||||
|
$this->pngLossyCmd = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($options['png_filter']) && $options['png_filter']) {
|
if (isset($options['png_filter']) && $options['png_filter']) {
|
||||||
$this->pngFilterCmd = $options['png_filter_cmd'];
|
$this->pngFilterCmd = $options['png_filter_cmd'];
|
||||||
} else {
|
} else {
|
||||||
@@ -3515,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);
|
||||||
|
|
||||||
@@ -3551,6 +3628,24 @@ class CImage
|
|||||||
imagesavealpha($this->image, true);
|
imagesavealpha($this->image, true);
|
||||||
imagepng($this->image, $this->cacheFileName, $this->compress);
|
imagepng($this->image, $this->cacheFileName, $this->compress);
|
||||||
|
|
||||||
|
// Use external program to process lossy PNG, if defined
|
||||||
|
$lossyEnabled = $this->pngLossy === true;
|
||||||
|
$lossySoftEnabled = $this->pngLossy === null;
|
||||||
|
$lossyActiveEnabled = $this->lossy === true;
|
||||||
|
if ($lossyEnabled || ($lossySoftEnabled && $lossyActiveEnabled)) {
|
||||||
|
if ($this->verbose) {
|
||||||
|
clearstatcache();
|
||||||
|
$this->log("Lossy enabled: $lossyEnabled");
|
||||||
|
$this->log("Lossy soft enabled: $lossySoftEnabled");
|
||||||
|
$this->Log("Filesize before lossy optimize: " . filesize($this->cacheFileName) . " bytes.");
|
||||||
|
}
|
||||||
|
$res = array();
|
||||||
|
$cmd = $this->pngLossyCmd . " $this->cacheFileName $this->cacheFileName";
|
||||||
|
exec($cmd, $res);
|
||||||
|
$this->Log($cmd);
|
||||||
|
$this->Log($res);
|
||||||
|
}
|
||||||
|
|
||||||
// Use external program to filter PNG, if defined
|
// Use external program to filter PNG, if defined
|
||||||
if ($this->pngFilterCmd) {
|
if ($this->pngFilterCmd) {
|
||||||
if ($this->verbose) {
|
if ($this->verbose) {
|
||||||
@@ -3835,18 +3930,18 @@ class CImage
|
|||||||
$lastModified = filemtime($this->pathToImage);
|
$lastModified = filemtime($this->pathToImage);
|
||||||
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['srcGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$details['cache'] = basename($this->cacheFileName);
|
$details['cache'] = basename($this->cacheFileName ?? "");
|
||||||
$lastModified = filemtime($this->cacheFileName);
|
$lastModified = filemtime($this->cacheFileName ?? "");
|
||||||
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||||
|
|
||||||
$this->load($file);
|
$this->load($file);
|
||||||
|
|
||||||
$details['filename'] = basename($file);
|
$details['filename'] = basename($file ?? "");
|
||||||
$details['mimeType'] = $this->getMimeType($this->fileType);
|
$details['mimeType'] = $this->getMimeType($this->fileType);
|
||||||
$details['width'] = $this->width;
|
$details['width'] = $this->width;
|
||||||
$details['height'] = $this->height;
|
$details['height'] = $this->height;
|
||||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||||
$details['size'] = filesize($file);
|
$details['size'] = filesize($file ?? "");
|
||||||
$details['colors'] = $this->colorsTotal($this->image);
|
$details['colors'] = $this->colorsTotal($this->image);
|
||||||
$details['includedFiles'] = count(get_included_files());
|
$details['includedFiles'] = count(get_included_files());
|
||||||
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
$details['memoryPeek'] = round(memory_get_peak_usage()/1024/1024, 3) . " MB" ;
|
||||||
@@ -4351,6 +4446,22 @@ class CFastTrackCache
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom exception handler.
|
||||||
|
*/
|
||||||
|
set_exception_handler(function ($exception) {
|
||||||
|
errorPage(
|
||||||
|
"<p><b>img.php: Uncaught exception:</b> <p>"
|
||||||
|
. $exception->getMessage()
|
||||||
|
. "</p><pre>"
|
||||||
|
. $exception->getTraceAsString()
|
||||||
|
. "</pre>",
|
||||||
|
500
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get configuration options from file, if the file exists, else use $config
|
* Get configuration options from file, if the file exists, else use $config
|
||||||
* if its defined or create an empty $config.
|
* if its defined or create an empty $config.
|
||||||
@@ -4513,7 +4624,7 @@ $hotlinkingWhitelist = getConfig('hotlinking_whitelist', array());
|
|||||||
|
|
||||||
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
$serverName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
|
||||||
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
|
||||||
$refererHost = parse_url($referer, PHP_URL_HOST);
|
$refererHost = parse_url($referer ?? "", PHP_URL_HOST);
|
||||||
|
|
||||||
if (!$allowHotlinking) {
|
if (!$allowHotlinking) {
|
||||||
if ($passwordMatch) {
|
if ($passwordMatch) {
|
||||||
@@ -4650,7 +4761,7 @@ $srcImage = urldecode(get('src'))
|
|||||||
or errorPage('Must set src-attribute.', 404);
|
or errorPage('Must set src-attribute.', 404);
|
||||||
|
|
||||||
// Get settings for src-alt as backup image
|
// Get settings for src-alt as backup image
|
||||||
$srcAltImage = urldecode(get('src-alt', null));
|
$srcAltImage = urldecode(get('src-alt', ""));
|
||||||
$srcAltConfig = getConfig('src_alt', null);
|
$srcAltConfig = getConfig('src_alt', null);
|
||||||
if (empty($srcAltImage)) {
|
if (empty($srcAltImage)) {
|
||||||
$srcAltImage = $srcAltConfig;
|
$srcAltImage = $srcAltConfig;
|
||||||
@@ -4767,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 {
|
||||||
@@ -4792,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 {
|
||||||
@@ -4823,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])) {
|
||||||
@@ -5183,6 +5294,9 @@ verbose("upscale = $upscale");
|
|||||||
* Get details for post processing
|
* Get details for post processing
|
||||||
*/
|
*/
|
||||||
$postProcessing = getConfig('postprocessing', array(
|
$postProcessing = getConfig('postprocessing', array(
|
||||||
|
'png_lossy' => false,
|
||||||
|
'png_lossy_cmd' => '/usr/local/bin/pngquant --force --output',
|
||||||
|
|
||||||
'png_filter' => false,
|
'png_filter' => false,
|
||||||
'png_filter_cmd' => '/usr/local/bin/optipng -q',
|
'png_filter_cmd' => '/usr/local/bin/optipng -q',
|
||||||
|
|
||||||
@@ -5195,6 +5309,15 @@ $postProcessing = getConfig('postprocessing', array(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lossy - Do lossy postprocessing, if available.
|
||||||
|
*/
|
||||||
|
$lossy = getDefined(array('lossy'), true, null);
|
||||||
|
|
||||||
|
verbose("lossy = $lossy");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* alias - Save resulting image to another alias name.
|
* alias - Save resulting image to another alias name.
|
||||||
* Password always apply, must be defined.
|
* Password always apply, must be defined.
|
||||||
@@ -5235,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.
|
||||||
*/
|
*/
|
||||||
@@ -5313,7 +5448,7 @@ if ($status) {
|
|||||||
$res = $cache->getStatusOfSubdir("srgb");
|
$res = $cache->getStatusOfSubdir("srgb");
|
||||||
$text .= "Cache srgb $res\n";
|
$text .= "Cache srgb $res\n";
|
||||||
|
|
||||||
$res = $cache->getStatusOfSubdir($fasttrackCache);
|
$res = $cache->getStatusOfSubdir($fastTrackCache);
|
||||||
$text .= "Cache fasttrack $res\n";
|
$text .= "Cache fasttrack $res\n";
|
||||||
|
|
||||||
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
||||||
@@ -5330,6 +5465,11 @@ if ($status) {
|
|||||||
$no = extension_loaded('gd') ? null : 'NOT';
|
$no = extension_loaded('gd') ? null : 'NOT';
|
||||||
$text .= "Extension gd is $no loaded.<br>";
|
$text .= "Extension gd is $no loaded.<br>";
|
||||||
|
|
||||||
|
$text .= checkExternalCommand("PNG LOSSY", $postProcessing["png_lossy"], $postProcessing["png_lossy_cmd"]);
|
||||||
|
$text .= checkExternalCommand("PNG FILTER", $postProcessing["png_filter"], $postProcessing["png_filter_cmd"]);
|
||||||
|
$text .= checkExternalCommand("PNG DEFLATE", $postProcessing["png_deflate"], $postProcessing["png_deflate_cmd"]);
|
||||||
|
$text .= checkExternalCommand("JPEG OPTIMIZE", $postProcessing["jpeg_optimize"], $postProcessing["jpeg_optimize_cmd"]);
|
||||||
|
|
||||||
if (!$no) {
|
if (!$no) {
|
||||||
$text .= print_r(gd_info(), 1);
|
$text .= print_r(gd_info(), 1);
|
||||||
}
|
}
|
||||||
@@ -5391,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,
|
||||||
@@ -5398,6 +5539,7 @@ if (is_callable($hookBeforeCImage)) {
|
|||||||
|
|
||||||
// Other
|
// Other
|
||||||
'postProcessing' => $postProcessing,
|
'postProcessing' => $postProcessing,
|
||||||
|
'lossy' => $lossy,
|
||||||
));
|
));
|
||||||
verbose(print_r($allConfig, 1));
|
verbose(print_r($allConfig, 1));
|
||||||
extract($allConfig);
|
extract($allConfig);
|
||||||
@@ -5445,7 +5587,8 @@ EOD;
|
|||||||
/**
|
/**
|
||||||
* Load, process and output the image
|
* Load, process and output the image
|
||||||
*/
|
*/
|
||||||
$img->log("Incoming arguments: " . print_r(verbose(), 1))
|
$img->log("PHP version: " . phpversion())
|
||||||
|
->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||||
->setSaveFolder($cachePath)
|
->setSaveFolder($cachePath)
|
||||||
->useCache($useCache)
|
->useCache($useCache)
|
||||||
->setSource($srcImage, $imagePath)
|
->setSource($srcImage, $imagePath)
|
||||||
@@ -5478,10 +5621,14 @@ $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,
|
||||||
'dpr' => $dpr,
|
'dpr' => $dpr,
|
||||||
|
|
||||||
|
// Postprocessing using external tools
|
||||||
|
'lossy' => $lossy,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
->loadImageDetails()
|
->loadImageDetails()
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user