mirror of
https://github.com/mosbth/cimage.git
synced 2025-07-31 13:40:08 +02:00
prepare to tag v0.7.15
This commit is contained in:
@@ -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.14 released 2016-08-08.**
|
||||
**Latest stable version is v0.7.15 released 2016-08-08.**
|
||||
|
||||
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.14
|
||||
git checkout v0.7.15
|
||||
```
|
||||
|
||||
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.14/webroot/imgp.php
|
||||
wget https://raw.githubusercontent.com/mosbth/cimage/v0.7.15/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.
|
||||
|
@@ -8,8 +8,8 @@ Revision history
|
||||
v0.7.15 (2016-08-08)
|
||||
-------------------------------------
|
||||
|
||||
* Added the [Lenna/Lena sample image](http://www.cs.cmu.edu/~chuck/lennapg/) as tif and created a png, jpeg and webp version using Imagick convert `convert lena.tif lena.{png,jpg,webp}`.
|
||||
* Support saving to imgp format through `sa=webp`, #132.
|
||||
* Added the [Lenna/Lena sample image](http://www.cs.cmu.edu/~chuck/lennapg/) as tif and created a png, jpeg and webp version using Imagick convert `convert lena.tif lena.{png,jpg,webp}`, #152.
|
||||
* Limited and basic support for WEBP format, se #132.
|
||||
|
||||
|
||||
v0.7.14 (2016-08-08)
|
||||
|
@@ -38,11 +38,16 @@ $config = array(
|
||||
|
||||
|
||||
// Version of cimage and img.php
|
||||
define("CIMAGE_VERSION", "v0.7.13 (2016-08-08)");
|
||||
define("CIMAGE_VERSION", "v0.7.15 (2016-08-09)");
|
||||
|
||||
// For CRemoteImage
|
||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||
|
||||
// Image type IMG_WEBP is only defined from 5.6.25
|
||||
if (!defined("IMG_WEBP")) {
|
||||
define("IMG_WEBP", -1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -1740,7 +1745,7 @@ class CImage
|
||||
*/
|
||||
private function checkFileExtension($extension)
|
||||
{
|
||||
$valid = array('jpg', 'jpeg', 'png', 'gif');
|
||||
$valid = array('jpg', 'jpeg', 'png', 'gif', 'webp');
|
||||
|
||||
in_array(strtolower($extension), $valid)
|
||||
or $this->raiseError('Not a valid file extension.');
|
||||
@@ -1763,7 +1768,7 @@ class CImage
|
||||
|
||||
if ($extension == 'jpeg') {
|
||||
$extension = 'jpg';
|
||||
}
|
||||
}
|
||||
|
||||
return $extension;
|
||||
}
|
||||
@@ -2041,17 +2046,34 @@ class CImage
|
||||
is_readable($file)
|
||||
or $this->raiseError('Image file does not exist.');
|
||||
|
||||
// Get details on image
|
||||
$info = list($this->width, $this->height, $this->fileType, $this->attr) = getimagesize($file);
|
||||
$info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
|
||||
if (empty($info)) {
|
||||
throw new Exception("The file doesn't seem to be a valid image.");
|
||||
// To support webp
|
||||
$this->fileType = false;
|
||||
if (function_exists("exif_imagetype")) {
|
||||
$this->fileType = exif_imagetype($file);
|
||||
if ($this->fileType === false) {
|
||||
if (function_exists("imagecreatefromwebp")) {
|
||||
$webp = imagecreatefromwebp($file);
|
||||
if ($webp !== false) {
|
||||
$this->width = imagesx($webp);
|
||||
$this->height = imagesy($webp);
|
||||
$this->fileType = IMG_WEBP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->fileType) {
|
||||
throw new Exception("Loading image details, the file doesn't seem to be a valid image.");
|
||||
}
|
||||
|
||||
if ($this->verbose) {
|
||||
$this->log("Loading image details for: {$file}");
|
||||
$this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType}).");
|
||||
$this->log(" Image filesize: " . filesize($file) . " bytes.");
|
||||
$this->log(" Image mimetype: " . image_type_to_mime_type($this->fileType));
|
||||
$this->log(" Image mimetype: " . $this->getMimeType());
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -2059,6 +2081,23 @@ class CImage
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get mime type for image type.
|
||||
*
|
||||
* @return $this
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getMimeType()
|
||||
{
|
||||
if ($this->fileType === IMG_WEBP) {
|
||||
return "image/webp";
|
||||
}
|
||||
|
||||
return image_type_to_mime_type($this->fileType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Init new width and height and do some sanity checks on constraints, before any
|
||||
* processing can be done.
|
||||
@@ -2570,9 +2609,14 @@ class CImage
|
||||
$this->setSource($src, $dir);
|
||||
}
|
||||
|
||||
$this->loadImageDetails($this->pathToImage);
|
||||
$this->loadImageDetails();
|
||||
|
||||
$this->image = imagecreatefromstring(file_get_contents($this->pathToImage));
|
||||
if ($this->fileType === IMG_WEBP) {
|
||||
$this->image = imagecreatefromwebp($this->pathToImage);
|
||||
} else {
|
||||
$imageAsString = file_get_contents($this->pathToImage);
|
||||
$this->image = imagecreatefromstring($imageAsString);
|
||||
}
|
||||
if ($this->image === false) {
|
||||
throw new Exception("Could not load image.");
|
||||
}
|
||||
@@ -3433,9 +3477,11 @@ class CImage
|
||||
// switch on mimetype
|
||||
if (isset($this->extension)) {
|
||||
return strtolower($this->extension);
|
||||
} else {
|
||||
return substr(image_type_to_extension($this->fileType), 1);
|
||||
} elseif ($this->fileType === IMG_WEBP) {
|
||||
return "webp";
|
||||
}
|
||||
|
||||
return substr(image_type_to_extension($this->fileType), 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -3491,6 +3537,11 @@ class CImage
|
||||
imagegif($this->image, $this->cacheFileName);
|
||||
break;
|
||||
|
||||
case 'webp':
|
||||
$this->Log("Saving image as WEBP to cache using quality = {$this->quality}.");
|
||||
imagewebp($this->image, $this->cacheFileName, $this->quality);
|
||||
break;
|
||||
|
||||
case 'png':
|
||||
default:
|
||||
$this->Log("Saving image as PNG to cache using compression = {$this->compress}.");
|
||||
@@ -3679,6 +3730,7 @@ class CImage
|
||||
$format = $this->outputFormat;
|
||||
}
|
||||
|
||||
$this->log("### Output");
|
||||
$this->log("Output format is: $format");
|
||||
|
||||
if (!$this->verbose && $format == 'json') {
|
||||
@@ -3712,7 +3764,8 @@ class CImage
|
||||
$this->fastTrackCache->addHeader($header);
|
||||
}
|
||||
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified) {
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
&& strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified) {
|
||||
|
||||
if ($this->verbose) {
|
||||
$this->log("304 not modified");
|
||||
@@ -3727,10 +3780,8 @@ class CImage
|
||||
|
||||
} else {
|
||||
|
||||
// Get details on image
|
||||
$info = getimagesize($file);
|
||||
!empty($info) or $this->raiseError("The file doesn't seem to be an image.");
|
||||
$mime = $info['mime'];
|
||||
$this->loadImageDetails($file);
|
||||
$mime = $this->getMimeType();
|
||||
$size = filesize($file);
|
||||
|
||||
if ($this->verbose) {
|
||||
@@ -3791,7 +3842,7 @@ class CImage
|
||||
$this->load($file);
|
||||
|
||||
$details['filename'] = basename($file);
|
||||
$details['mimeType'] = image_type_to_mime_type($this->fileType);
|
||||
$details['mimeType'] = $this->getMimeType($this->fileType);
|
||||
$details['width'] = $this->width;
|
||||
$details['height'] = $this->height;
|
||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||
@@ -3893,6 +3944,7 @@ class CImage
|
||||
private function verboseOutput()
|
||||
{
|
||||
$log = null;
|
||||
$this->log("### Summary of verbose log");
|
||||
$this->log("As JSON: \n" . $this->json());
|
||||
$this->log("Memory peak: " . round(memory_get_peak_usage() /1024/1024) . "M");
|
||||
$this->log("Memory limit: " . ini_get('memory_limit'));
|
||||
|
@@ -38,11 +38,16 @@ $config = array(
|
||||
|
||||
|
||||
// Version of cimage and img.php
|
||||
define("CIMAGE_VERSION", "v0.7.13 (2016-08-08)");
|
||||
define("CIMAGE_VERSION", "v0.7.15 (2016-08-09)");
|
||||
|
||||
// For CRemoteImage
|
||||
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);
|
||||
|
||||
// Image type IMG_WEBP is only defined from 5.6.25
|
||||
if (!defined("IMG_WEBP")) {
|
||||
define("IMG_WEBP", -1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -1740,7 +1745,7 @@ class CImage
|
||||
*/
|
||||
private function checkFileExtension($extension)
|
||||
{
|
||||
$valid = array('jpg', 'jpeg', 'png', 'gif');
|
||||
$valid = array('jpg', 'jpeg', 'png', 'gif', 'webp');
|
||||
|
||||
in_array(strtolower($extension), $valid)
|
||||
or $this->raiseError('Not a valid file extension.');
|
||||
@@ -1763,7 +1768,7 @@ class CImage
|
||||
|
||||
if ($extension == 'jpeg') {
|
||||
$extension = 'jpg';
|
||||
}
|
||||
}
|
||||
|
||||
return $extension;
|
||||
}
|
||||
@@ -2041,17 +2046,34 @@ class CImage
|
||||
is_readable($file)
|
||||
or $this->raiseError('Image file does not exist.');
|
||||
|
||||
// Get details on image
|
||||
$info = list($this->width, $this->height, $this->fileType, $this->attr) = getimagesize($file);
|
||||
$info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
|
||||
if (empty($info)) {
|
||||
throw new Exception("The file doesn't seem to be a valid image.");
|
||||
// To support webp
|
||||
$this->fileType = false;
|
||||
if (function_exists("exif_imagetype")) {
|
||||
$this->fileType = exif_imagetype($file);
|
||||
if ($this->fileType === false) {
|
||||
if (function_exists("imagecreatefromwebp")) {
|
||||
$webp = imagecreatefromwebp($file);
|
||||
if ($webp !== false) {
|
||||
$this->width = imagesx($webp);
|
||||
$this->height = imagesy($webp);
|
||||
$this->fileType = IMG_WEBP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->fileType) {
|
||||
throw new Exception("Loading image details, the file doesn't seem to be a valid image.");
|
||||
}
|
||||
|
||||
if ($this->verbose) {
|
||||
$this->log("Loading image details for: {$file}");
|
||||
$this->log(" Image width x height (type): {$this->width} x {$this->height} ({$this->fileType}).");
|
||||
$this->log(" Image filesize: " . filesize($file) . " bytes.");
|
||||
$this->log(" Image mimetype: " . image_type_to_mime_type($this->fileType));
|
||||
$this->log(" Image mimetype: " . $this->getMimeType());
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -2059,6 +2081,23 @@ class CImage
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get mime type for image type.
|
||||
*
|
||||
* @return $this
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getMimeType()
|
||||
{
|
||||
if ($this->fileType === IMG_WEBP) {
|
||||
return "image/webp";
|
||||
}
|
||||
|
||||
return image_type_to_mime_type($this->fileType);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Init new width and height and do some sanity checks on constraints, before any
|
||||
* processing can be done.
|
||||
@@ -2570,9 +2609,14 @@ class CImage
|
||||
$this->setSource($src, $dir);
|
||||
}
|
||||
|
||||
$this->loadImageDetails($this->pathToImage);
|
||||
$this->loadImageDetails();
|
||||
|
||||
$this->image = imagecreatefromstring(file_get_contents($this->pathToImage));
|
||||
if ($this->fileType === IMG_WEBP) {
|
||||
$this->image = imagecreatefromwebp($this->pathToImage);
|
||||
} else {
|
||||
$imageAsString = file_get_contents($this->pathToImage);
|
||||
$this->image = imagecreatefromstring($imageAsString);
|
||||
}
|
||||
if ($this->image === false) {
|
||||
throw new Exception("Could not load image.");
|
||||
}
|
||||
@@ -3433,9 +3477,11 @@ class CImage
|
||||
// switch on mimetype
|
||||
if (isset($this->extension)) {
|
||||
return strtolower($this->extension);
|
||||
} else {
|
||||
return substr(image_type_to_extension($this->fileType), 1);
|
||||
} elseif ($this->fileType === IMG_WEBP) {
|
||||
return "webp";
|
||||
}
|
||||
|
||||
return substr(image_type_to_extension($this->fileType), 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -3491,6 +3537,11 @@ class CImage
|
||||
imagegif($this->image, $this->cacheFileName);
|
||||
break;
|
||||
|
||||
case 'webp':
|
||||
$this->Log("Saving image as WEBP to cache using quality = {$this->quality}.");
|
||||
imagewebp($this->image, $this->cacheFileName, $this->quality);
|
||||
break;
|
||||
|
||||
case 'png':
|
||||
default:
|
||||
$this->Log("Saving image as PNG to cache using compression = {$this->compress}.");
|
||||
@@ -3679,6 +3730,7 @@ class CImage
|
||||
$format = $this->outputFormat;
|
||||
}
|
||||
|
||||
$this->log("### Output");
|
||||
$this->log("Output format is: $format");
|
||||
|
||||
if (!$this->verbose && $format == 'json') {
|
||||
@@ -3712,7 +3764,8 @@ class CImage
|
||||
$this->fastTrackCache->addHeader($header);
|
||||
}
|
||||
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified) {
|
||||
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])
|
||||
&& strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified) {
|
||||
|
||||
if ($this->verbose) {
|
||||
$this->log("304 not modified");
|
||||
@@ -3727,10 +3780,8 @@ class CImage
|
||||
|
||||
} else {
|
||||
|
||||
// Get details on image
|
||||
$info = getimagesize($file);
|
||||
!empty($info) or $this->raiseError("The file doesn't seem to be an image.");
|
||||
$mime = $info['mime'];
|
||||
$this->loadImageDetails($file);
|
||||
$mime = $this->getMimeType();
|
||||
$size = filesize($file);
|
||||
|
||||
if ($this->verbose) {
|
||||
@@ -3791,7 +3842,7 @@ class CImage
|
||||
$this->load($file);
|
||||
|
||||
$details['filename'] = basename($file);
|
||||
$details['mimeType'] = image_type_to_mime_type($this->fileType);
|
||||
$details['mimeType'] = $this->getMimeType($this->fileType);
|
||||
$details['width'] = $this->width;
|
||||
$details['height'] = $this->height;
|
||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||
@@ -3893,6 +3944,7 @@ class CImage
|
||||
private function verboseOutput()
|
||||
{
|
||||
$log = null;
|
||||
$this->log("### Summary of verbose log");
|
||||
$this->log("As JSON: \n" . $this->json());
|
||||
$this->log("Memory peak: " . round(memory_get_peak_usage() /1024/1024) . "M");
|
||||
$this->log("Memory limit: " . ini_get('memory_limit'));
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user