1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-08-01 22:00:31 +02:00

webp partly working

This commit is contained in:
Mikael Roos
2016-08-09 09:32:02 +02:00
parent bbfd895c4c
commit 66c5a07767
3 changed files with 18 additions and 11 deletions

View File

@@ -941,7 +941,7 @@ class CImage
is_readable($file) is_readable($file)
or $this->raiseError('Image file does not exist.'); or $this->raiseError('Image file does not exist.');
$info = list($this->width, $this->height, $this->fileType) = getimagesize($this->pathToImage); $info = list($this->width, $this->height, $this->fileType) = getimagesize($file);
if (empty($info)) { if (empty($info)) {
// To support webp // To support webp
$this->fileType = false; $this->fileType = false;
@@ -1506,8 +1506,12 @@ class CImage
$this->loadImageDetails(); $this->loadImageDetails();
$imageAsString = file_get_contents($this->pathToImage); if ($this->fileType === IMG_WEBP) {
$this->image = imagecreatefromstring($imageAsString); $this->image = imagecreatefromwebp($this->pathToImage);
} else {
$imageAsString = file_get_contents($this->pathToImage);
$this->image = imagecreatefromstring($imageAsString);
}
if ($this->image === false) { if ($this->image === false) {
throw new Exception("Could not load image."); throw new Exception("Could not load image.");
} }
@@ -2368,9 +2372,11 @@ class CImage
// switch on mimetype // switch on mimetype
if (isset($this->extension)) { if (isset($this->extension)) {
return strtolower($this->extension); return strtolower($this->extension);
} else { } elseif ($this->fileType === IMG_WEBP) {
return substr(image_type_to_extension($this->fileType), 1); return "webp";
} }
return substr(image_type_to_extension($this->fileType), 1);
} }
@@ -2619,6 +2625,7 @@ class CImage
$format = $this->outputFormat; $format = $this->outputFormat;
} }
$this->log("### Output");
$this->log("Output format is: $format"); $this->log("Output format is: $format");
if (!$this->verbose && $format == 'json') { if (!$this->verbose && $format == 'json') {
@@ -2652,7 +2659,8 @@ class CImage
$this->fastTrackCache->addHeader($header); $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) { if ($this->verbose) {
$this->log("304 not modified"); $this->log("304 not modified");
@@ -2667,10 +2675,8 @@ class CImage
} else { } else {
// Get details on image $this->loadImageDetails($file);
$info = getimagesize($file); $mime = $this->getMimeType();
!empty($info) or $this->raiseError("The file doesn't seem to be an image.");
$mime = $info['mime'];
$size = filesize($file); $size = filesize($file);
if ($this->verbose) { if ($this->verbose) {
@@ -2833,6 +2839,7 @@ class CImage
private function verboseOutput() private function verboseOutput()
{ {
$log = null; $log = null;
$this->log("### Summary of verbose log");
$this->log("As JSON: \n" . $this->json()); $this->log("As JSON: \n" . $this->json());
$this->log("Memory peak: " . round(memory_get_peak_usage() /1024/1024) . "M"); $this->log("Memory peak: " . round(memory_get_peak_usage() /1024/1024) . "M");
$this->log("Memory limit: " . ini_get('memory_limit')); $this->log("Memory limit: " . ini_get('memory_limit'));

View File

@@ -1,6 +1,6 @@
<?php <?php
// Version of cimage and img.php // 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 // For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION); define("CIMAGE_USER_AGENT", "CImage/" . CIMAGE_VERSION);

BIN
webroot/img/webp/1.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB