diff --git a/CImage.php b/CImage.php
index a1fd817..dc64329 100644
--- a/CImage.php
+++ b/CImage.php
@@ -155,6 +155,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
*/
@@ -190,7 +197,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;
@@ -198,7 +213,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;
@@ -827,6 +842,9 @@ class CImage
// Output format
'outputFormat' => null,
'dpr' => 1,
+
+ // Postprocessing using external tools
+ 'lossy' => null,
);
// Convert crop settings from string to array
@@ -2345,6 +2363,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 {
@@ -2446,6 +2472,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) {
diff --git a/README.md b/README.md
index f256a4a..c01b5cc 100644
--- a/README.md
+++ b/README.md
@@ -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.15 released 2016-08-09.**
+**Latest stable version is v0.7.16 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.15
+git checkout v0.7.16
```
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.15/webroot/imgp.php
+wget https://raw.githubusercontent.com/mosbth/cimage/v0.7.16/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.
diff --git a/REVISION.md b/REVISION.md
index 667360e..ee6c4f0 100644
--- a/REVISION.md
+++ b/REVISION.md
@@ -5,6 +5,14 @@ Revision history
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
+v0.7.16 (2016-08-09)
+-------------------------------------
+
+* Fix default mode to be production.
+* Added pngquant as extra postprocessing utility for PNG-images, #154.
+* Bug `&status` wrong variable name for fast track cache.
+
+
v0.7.15 (2016-08-09)
-------------------------------------
diff --git a/defines.php b/defines.php
index 4789fd1..3cc5c5e 100644
--- a/defines.php
+++ b/defines.php
@@ -1,6 +1,6 @@
";
+
+ list($command) = explode(" ", $commandString);
+ $no = is_executable($command) ? null : 'NOT';
+ $text .= "The command for $what is $no an executable.
";
+
+ return $text;
+}
diff --git a/webroot/check_system.php b/webroot/check_system.php
index b101998..1443de8 100644
--- a/webroot/check_system.php
+++ b/webroot/check_system.php
@@ -21,6 +21,9 @@ if (!$no) {
echo "Checking path for postprocessing tools";
+echo "
pngquant: ";
+system("which pngquant");
+
echo "
optipng: ";
system("which optipng");
diff --git a/webroot/img.php b/webroot/img.php
index 15d4a96..f93227e 100644
--- a/webroot/img.php
+++ b/webroot/img.php
@@ -840,6 +840,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',
@@ -852,6 +855,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.
@@ -970,7 +982,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";
@@ -987,6 +999,11 @@ if ($status) {
$no = extension_loaded('gd') ? null : 'NOT';
$text .= "Extension gd is $no loaded.
";
+ $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);
}
@@ -1055,6 +1072,7 @@ if (is_callable($hookBeforeCImage)) {
// Other
'postProcessing' => $postProcessing,
+ 'lossy' => $lossy,
));
verbose(print_r($allConfig, 1));
extract($allConfig);
@@ -1139,6 +1157,9 @@ $img->log("Incoming arguments: " . print_r(verbose(), 1))
// Output format
'outputFormat' => $outputFormat,
'dpr' => $dpr,
+
+ // Postprocessing using external tools
+ 'lossy' => $lossy,
)
)
->loadImageDetails()
diff --git a/webroot/img/duke.png b/webroot/img/duke.png
new file mode 100644
index 0000000..5927b8f
Binary files /dev/null and b/webroot/img/duke.png differ
diff --git a/webroot/img_config.php b/webroot/img_config.php
index 9654dd5..6da433a 100644
--- a/webroot/img_config.php
+++ b/webroot/img_config.php
@@ -41,7 +41,7 @@ return array(
* mode: 'production'
*/
//'mode' => 'production',
- 'mode' => 'development',
+ //'mode' => 'development',
//'mode' => 'strict',
@@ -321,8 +321,16 @@ return array(
* Post processing of images using external tools, set to true or false
* and set command to be executed.
*
+ * The png_lossy can alos have a value of null which means that its
+ * enabled but not used as default. Each image having the option
+ * &lossy will be processed. This means one can individually choose
+ * when to use the lossy processing.
+ *
* Default values.
*
+ * png_lossy: false
+ * png_lossy_cmd: '/usr/local/bin/pngquant --force --output'
+ *
* png_filter: false
* png_filter_cmd: '/usr/local/bin/optipng -q'
*
@@ -334,6 +342,9 @@ return array(
*/
/*
'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',