mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-03 14:47:47 +02:00
Corrected behaviour for skip-original. Fix #60
This commit is contained in:
52
CImage.php
52
CImage.php
@@ -34,6 +34,13 @@ class CImage
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is the quality level set from external use (true) or is it default (false)?
|
||||
*/
|
||||
private $useQuality = false;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constant for default image quality when not set
|
||||
*/
|
||||
@@ -48,6 +55,14 @@ class CImage
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Is the compress level set from external use (true) or is it default (false)?
|
||||
*/
|
||||
private $useCompress = false;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Default background color, red, green, blue, alpha.
|
||||
*
|
||||
@@ -548,22 +563,26 @@ class CImage
|
||||
/**
|
||||
* Load image details from original image file.
|
||||
*
|
||||
* @param string $file the file to load or null to use $this->pathToImage.
|
||||
*
|
||||
* @return $this
|
||||
* @throws Exception
|
||||
*/
|
||||
public function loadImageDetails()
|
||||
public function loadImageDetails($file = null)
|
||||
{
|
||||
is_readable($this->pathToImage)
|
||||
$file = $file ? $file : $this->pathToImage;
|
||||
|
||||
is_readable($file)
|
||||
or $this->raiseError('Image file does not exist.');
|
||||
|
||||
// Get details on image
|
||||
$info = list($this->width, $this->height, $this->type, $this->attr) = getimagesize($this->pathToImage);
|
||||
$info = list($this->width, $this->height, $this->type, $this->attr) = getimagesize($file);
|
||||
!empty($info) or $this->raiseError("The file doesn't seem to be an image.");
|
||||
|
||||
if ($this->verbose) {
|
||||
$this->log("Image file: {$this->pathToImage}");
|
||||
$this->log("Image file: {$file}");
|
||||
$this->log("Image width x height (type): {$this->width} x {$this->height} ({$this->type}).");
|
||||
$this->log("Image filesize: " . filesize($this->pathToImage) . " bytes.");
|
||||
$this->log("Image filesize: " . filesize($file) . " bytes.");
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -813,6 +832,10 @@ class CImage
|
||||
*/
|
||||
public function setJpegQuality($quality = null)
|
||||
{
|
||||
if ($quality) {
|
||||
$this->useQuality = true;
|
||||
}
|
||||
|
||||
$this->quality = isset($quality)
|
||||
? $quality
|
||||
: self::JPEG_QUALITY_DEFAULT;
|
||||
@@ -836,6 +859,10 @@ class CImage
|
||||
*/
|
||||
public function setPngCompression($compress = null)
|
||||
{
|
||||
if ($compress) {
|
||||
$this->useCompress = true;
|
||||
}
|
||||
|
||||
$this->compress = isset($compress)
|
||||
? $compress
|
||||
: self::PNG_COMPRESSION_DEFAULT;
|
||||
@@ -872,8 +899,8 @@ class CImage
|
||||
&& !$this->blur
|
||||
&& !$this->convolve
|
||||
&& !$this->palette
|
||||
&& !$this->quality
|
||||
&& !$this->compress
|
||||
&& !$this->useQuality
|
||||
&& !$this->useCompress
|
||||
&& !$this->saveAs
|
||||
&& !$this->rotateBefore
|
||||
&& !$this->rotateAfter
|
||||
@@ -883,6 +910,7 @@ class CImage
|
||||
$this->log("Using original image.");
|
||||
$this->output($this->pathToImage);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -1919,10 +1947,14 @@ class CImage
|
||||
/**
|
||||
* Create a JSON object from the image details.
|
||||
*
|
||||
* @param string $file the file to output.
|
||||
*
|
||||
* @return string json-encoded representation of the image.
|
||||
*/
|
||||
public function json()
|
||||
public function json($file = null)
|
||||
{
|
||||
$file = $file ? $file : $this->cacheFileName;
|
||||
|
||||
$details = array();
|
||||
|
||||
clearstatcache();
|
||||
@@ -1935,9 +1967,13 @@ class CImage
|
||||
$lastModified = filemtime($this->cacheFileName);
|
||||
$details['cacheGmdate'] = gmdate("D, d M Y H:i:s", $lastModified);
|
||||
|
||||
$this->loadImageDetails($file);
|
||||
|
||||
$details['filename'] = basename($file);
|
||||
$details['width'] = $this->width;
|
||||
$details['height'] = $this->height;
|
||||
$details['aspectRatio'] = round($this->width / $this->height, 3);
|
||||
$details['size'] = filesize($file);
|
||||
|
||||
$options = null;
|
||||
if (defined("JSON_PRETTY_PRINT") && defined("JSON_UNESCAPED_SLASHES")) {
|
||||
|
@@ -278,6 +278,11 @@ Revision history
|
||||
-------------------------------------
|
||||
|
||||
|
||||
v0.6.x (latest)
|
||||
|
||||
* Corrected behaviour for skip-original. Fix #60.
|
||||
|
||||
|
||||
v0.6 (2014-12-06)
|
||||
|
||||
* Rewrote and added documentation.
|
||||
|
@@ -341,7 +341,7 @@ verbose("area = $area");
|
||||
/**
|
||||
* skip-original, so - skip the original image and always process a new image
|
||||
*/
|
||||
$useOriginal = getDefined(array('save-as', 'sa'), false, true);
|
||||
$useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
||||
|
||||
verbose("use original = $useOriginal");
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
window.getDetails = function (url, id) {
|
||||
$.getJSON(url, function(data) {
|
||||
element = document.getElementById(id);
|
||||
element.innerHTML = "width: " + data.width + "\nheigh: " + data.height + "\naspect-ratio: " + data.aspectRatio;
|
||||
element.innerHTML = "filename: " + data.filename + "\nsize: " + data.size + "\nwidth: " + data.width + "\nheigh: " + data.height + "\naspect-ratio: " + data.aspectRatio;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
33
webroot/test/test_issue60.php
Normal file
33
webroot/test/test_issue60.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// Include config for all testcases
|
||||
include __DIR__ . "/config.php";
|
||||
|
||||
|
||||
|
||||
// The title of the test case
|
||||
$title = "Testing issue 60 - skip original";
|
||||
|
||||
|
||||
|
||||
// Provide a short description of the testcase.
|
||||
$description = "Always use the original if suitable, use skip-original to force using the cached version.";
|
||||
|
||||
|
||||
|
||||
// Use these images in the test
|
||||
$images = array(
|
||||
'car.png',
|
||||
);
|
||||
|
||||
|
||||
|
||||
// For each image, apply these testcases
|
||||
$testcase = array(
|
||||
'',
|
||||
'&so',
|
||||
);
|
||||
|
||||
|
||||
|
||||
// Apply testcases and present results
|
||||
include __DIR__ . "/template.php";
|
Reference in New Issue
Block a user