mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-26 17:14:27 +02:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
f9604518e4 | ||
|
61aa52854e | ||
|
401478c839 | ||
|
f0ab9479d6 | ||
|
9ff7a61ca9 | ||
|
3170beb832 | ||
|
8001f72a1a | ||
|
0f9e0220f1 | ||
|
e59ef91991 | ||
|
2337dbe94c | ||
|
c5de59a754 |
@@ -1365,6 +1365,7 @@ class CImage
|
||||
&& !$this->autoRotate
|
||||
&& !$this->bgColor
|
||||
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
||||
&& !$this->lossy
|
||||
) {
|
||||
$this->log("Using original image.");
|
||||
$this->output($this->pathToImage);
|
||||
@@ -1398,6 +1399,7 @@ class CImage
|
||||
$compress = $this->compress ? "_co{$this->compress}" : null;
|
||||
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
||||
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
||||
$lossy = $this->lossy ? "_l" : null;
|
||||
|
||||
$saveAs = $this->normalizeFileExtension();
|
||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||
@@ -1464,7 +1466,7 @@ class CImage
|
||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||
. $optimize . $compress
|
||||
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
||||
. $convolve . $copyStrat . $saveAs;
|
||||
. $convolve . $copyStrat . $lossy . $saveAs;
|
||||
|
||||
return $this->setTarget($file, $base);
|
||||
}
|
||||
|
@@ -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).
|
||||
|
||||
**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.
|
||||
|
||||
```bash
|
||||
git clone git://github.com/mosbth/cimage.git
|
||||
cd cimage
|
||||
git checkout v0.7.16
|
||||
git checkout v0.7.18
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
```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.
|
||||
|
20
REVISION.md
20
REVISION.md
@@ -5,6 +5,26 @@ Revision history
|
||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
||||
|
||||
|
||||
v0.7.19 (2017-03-31)
|
||||
-------------------------------------
|
||||
|
||||
* Move exception handler from functions.php to img.php.
|
||||
* 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)
|
||||
-------------------------------------
|
||||
|
||||
|
@@ -22,7 +22,9 @@
|
||||
"ext-gd": "*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-exif": "*"
|
||||
"ext-exif": "*",
|
||||
"ext-curl": "*",
|
||||
"ext-imagick": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
// Version of cimage and img.php
|
||||
define("CIMAGE_VERSION", "v0.7.16 (2016-08-09)");
|
||||
define("CIMAGE_VERSION", "v0.7.19 (2017-03-31)");
|
||||
|
||||
// For CRemoteImage
|
||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||
|
@@ -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.
|
||||
*
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
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';
|
||||
echo "Extension exif is $no loaded.<br>";
|
||||
|
@@ -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
|
||||
* if its defined or create an empty $config.
|
||||
|
@@ -342,7 +342,7 @@ return array(
|
||||
*/
|
||||
/*
|
||||
'postprocessing' => array(
|
||||
'png_lossy' => false,
|
||||
'png_lossy' => null,
|
||||
'png_lossy_cmd' => '/usr/local/bin/pngquant --force --output',
|
||||
|
||||
'png_filter' => false,
|
||||
|
130
webroot/imgd.php
130
webroot/imgd.php
@@ -38,7 +38,7 @@ $config = array(
|
||||
|
||||
|
||||
// Version of cimage and img.php
|
||||
define("CIMAGE_VERSION", "v0.7.15 (2016-08-09)");
|
||||
define("CIMAGE_VERSION", "v0.7.19 (2017-03-31)");
|
||||
|
||||
// For CRemoteImage
|
||||
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.
|
||||
*
|
||||
@@ -217,6 +201,27 @@ function verbose($msg = null)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a image from a remote server using HTTP GET and If-Modified-Since.
|
||||
*
|
||||
@@ -1260,6 +1265,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
|
||||
*/
|
||||
@@ -1295,7 +1307,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 $pngFilterCmd;
|
||||
@@ -1303,7 +1323,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 $pngDeflateCmd;
|
||||
@@ -1932,6 +1952,9 @@ class CImage
|
||||
// Output format
|
||||
'outputFormat' => null,
|
||||
'dpr' => 1,
|
||||
|
||||
// Postprocessing using external tools
|
||||
'lossy' => null,
|
||||
);
|
||||
|
||||
// Convert crop settings from string to array
|
||||
@@ -2452,6 +2475,7 @@ class CImage
|
||||
&& !$this->autoRotate
|
||||
&& !$this->bgColor
|
||||
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
||||
&& !$this->lossy
|
||||
) {
|
||||
$this->log("Using original image.");
|
||||
$this->output($this->pathToImage);
|
||||
@@ -2485,6 +2509,7 @@ class CImage
|
||||
$compress = $this->compress ? "_co{$this->compress}" : null;
|
||||
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
||||
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
||||
$lossy = $this->lossy ? "_l" : null;
|
||||
|
||||
$saveAs = $this->normalizeFileExtension();
|
||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||
@@ -2551,7 +2576,7 @@ class CImage
|
||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||
. $optimize . $compress
|
||||
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
||||
. $convolve . $copyStrat . $saveAs;
|
||||
. $convolve . $copyStrat . $lossy . $saveAs;
|
||||
|
||||
return $this->setTarget($file, $base);
|
||||
}
|
||||
@@ -3450,6 +3475,14 @@ class CImage
|
||||
$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']) {
|
||||
$this->pngFilterCmd = $options['png_filter_cmd'];
|
||||
} else {
|
||||
@@ -3551,6 +3584,24 @@ class CImage
|
||||
imagesavealpha($this->image, true);
|
||||
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
|
||||
if ($this->pngFilterCmd) {
|
||||
if ($this->verbose) {
|
||||
@@ -4351,6 +4402,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
|
||||
* if its defined or create an empty $config.
|
||||
@@ -5183,6 +5250,9 @@ verbose("upscale = $upscale");
|
||||
* Get details for post processing
|
||||
*/
|
||||
$postProcessing = getConfig('postprocessing', array(
|
||||
'png_lossy' => false,
|
||||
'png_lossy_cmd' => '/usr/local/bin/pngquant --force --output',
|
||||
|
||||
'png_filter' => false,
|
||||
'png_filter_cmd' => '/usr/local/bin/optipng -q',
|
||||
|
||||
@@ -5195,6 +5265,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.
|
||||
* Password always apply, must be defined.
|
||||
@@ -5313,7 +5392,7 @@ if ($status) {
|
||||
$res = $cache->getStatusOfSubdir("srgb");
|
||||
$text .= "Cache srgb $res\n";
|
||||
|
||||
$res = $cache->getStatusOfSubdir($fasttrackCache);
|
||||
$res = $cache->getStatusOfSubdir($fastTrackCache);
|
||||
$text .= "Cache fasttrack $res\n";
|
||||
|
||||
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
||||
@@ -5330,6 +5409,11 @@ if ($status) {
|
||||
$no = extension_loaded('gd') ? null : 'NOT';
|
||||
$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) {
|
||||
$text .= print_r(gd_info(), 1);
|
||||
}
|
||||
@@ -5398,6 +5482,7 @@ if (is_callable($hookBeforeCImage)) {
|
||||
|
||||
// Other
|
||||
'postProcessing' => $postProcessing,
|
||||
'lossy' => $lossy,
|
||||
));
|
||||
verbose(print_r($allConfig, 1));
|
||||
extract($allConfig);
|
||||
@@ -5482,6 +5567,9 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||
// Output format
|
||||
'outputFormat' => $outputFormat,
|
||||
'dpr' => $dpr,
|
||||
|
||||
// Postprocessing using external tools
|
||||
'lossy' => $lossy,
|
||||
)
|
||||
)
|
||||
->loadImageDetails()
|
||||
|
130
webroot/imgp.php
130
webroot/imgp.php
@@ -38,7 +38,7 @@ $config = array(
|
||||
|
||||
|
||||
// Version of cimage and img.php
|
||||
define("CIMAGE_VERSION", "v0.7.15 (2016-08-09)");
|
||||
define("CIMAGE_VERSION", "v0.7.19 (2017-03-31)");
|
||||
|
||||
// For CRemoteImage
|
||||
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.
|
||||
*
|
||||
@@ -217,6 +201,27 @@ function verbose($msg = null)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a image from a remote server using HTTP GET and If-Modified-Since.
|
||||
*
|
||||
@@ -1260,6 +1265,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
|
||||
*/
|
||||
@@ -1295,7 +1307,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 $pngFilterCmd;
|
||||
@@ -1303,7 +1323,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 $pngDeflateCmd;
|
||||
@@ -1932,6 +1952,9 @@ class CImage
|
||||
// Output format
|
||||
'outputFormat' => null,
|
||||
'dpr' => 1,
|
||||
|
||||
// Postprocessing using external tools
|
||||
'lossy' => null,
|
||||
);
|
||||
|
||||
// Convert crop settings from string to array
|
||||
@@ -2452,6 +2475,7 @@ class CImage
|
||||
&& !$this->autoRotate
|
||||
&& !$this->bgColor
|
||||
&& ($this->upscale === self::UPSCALE_DEFAULT)
|
||||
&& !$this->lossy
|
||||
) {
|
||||
$this->log("Using original image.");
|
||||
$this->output($this->pathToImage);
|
||||
@@ -2485,6 +2509,7 @@ class CImage
|
||||
$compress = $this->compress ? "_co{$this->compress}" : null;
|
||||
$rotateBefore = $this->rotateBefore ? "_rb{$this->rotateBefore}" : null;
|
||||
$rotateAfter = $this->rotateAfter ? "_ra{$this->rotateAfter}" : null;
|
||||
$lossy = $this->lossy ? "_l" : null;
|
||||
|
||||
$saveAs = $this->normalizeFileExtension();
|
||||
$saveAs = $saveAs ? "_$saveAs" : null;
|
||||
@@ -2551,7 +2576,7 @@ class CImage
|
||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||
. $optimize . $compress
|
||||
. $scale . $rotateBefore . $rotateAfter . $autoRotate . $bgColor
|
||||
. $convolve . $copyStrat . $saveAs;
|
||||
. $convolve . $copyStrat . $lossy . $saveAs;
|
||||
|
||||
return $this->setTarget($file, $base);
|
||||
}
|
||||
@@ -3450,6 +3475,14 @@ class CImage
|
||||
$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']) {
|
||||
$this->pngFilterCmd = $options['png_filter_cmd'];
|
||||
} else {
|
||||
@@ -3551,6 +3584,24 @@ class CImage
|
||||
imagesavealpha($this->image, true);
|
||||
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
|
||||
if ($this->pngFilterCmd) {
|
||||
if ($this->verbose) {
|
||||
@@ -4351,6 +4402,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
|
||||
* if its defined or create an empty $config.
|
||||
@@ -5183,6 +5250,9 @@ verbose("upscale = $upscale");
|
||||
* Get details for post processing
|
||||
*/
|
||||
$postProcessing = getConfig('postprocessing', array(
|
||||
'png_lossy' => false,
|
||||
'png_lossy_cmd' => '/usr/local/bin/pngquant --force --output',
|
||||
|
||||
'png_filter' => false,
|
||||
'png_filter_cmd' => '/usr/local/bin/optipng -q',
|
||||
|
||||
@@ -5195,6 +5265,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.
|
||||
* Password always apply, must be defined.
|
||||
@@ -5313,7 +5392,7 @@ if ($status) {
|
||||
$res = $cache->getStatusOfSubdir("srgb");
|
||||
$text .= "Cache srgb $res\n";
|
||||
|
||||
$res = $cache->getStatusOfSubdir($fasttrackCache);
|
||||
$res = $cache->getStatusOfSubdir($fastTrackCache);
|
||||
$text .= "Cache fasttrack $res\n";
|
||||
|
||||
$text .= "Alias path writable = " . is_writable($aliasPath) . "\n";
|
||||
@@ -5330,6 +5409,11 @@ if ($status) {
|
||||
$no = extension_loaded('gd') ? null : 'NOT';
|
||||
$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) {
|
||||
$text .= print_r(gd_info(), 1);
|
||||
}
|
||||
@@ -5398,6 +5482,7 @@ if (is_callable($hookBeforeCImage)) {
|
||||
|
||||
// Other
|
||||
'postProcessing' => $postProcessing,
|
||||
'lossy' => $lossy,
|
||||
));
|
||||
verbose(print_r($allConfig, 1));
|
||||
extract($allConfig);
|
||||
@@ -5482,6 +5567,9 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
|
||||
// Output format
|
||||
'outputFormat' => $outputFormat,
|
||||
'dpr' => $dpr,
|
||||
|
||||
// Postprocessing using external tools
|
||||
'lossy' => $lossy,
|
||||
)
|
||||
)
|
||||
->loadImageDetails()
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user