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

Compare commits

..

18 Commits
079 ... v0.7.12

Author SHA1 Message Date
Mikael Roos
cde8bab6e7 tagging v0.7.12 2016-06-01 09:37:28 +02:00
Mikael Roos
5edbfc9b54 prepare to tag v0.7.12 2016-06-01 09:34:30 +02:00
Mikael Roos
9e9c44c935 Fixed to correctly display image when using a resize strategy without height or width. 2016-06-01 09:31:28 +02:00
Mikael Roos
9088647d3a Fixed background color for option , #144. 2016-06-01 09:30:18 +02:00
Mikael Roos
8ad324b4f5 update readme with latest version number 2016-04-18 16:09:49 +02:00
Mikael Roos
3b16b4b79d prepare to tag v0.7.11 2016-04-18 15:58:39 +02:00
Mikael Roos
4e940164f9 Add option for skip_original to config file to always skip original, #118. 2016-04-18 15:53:55 +02:00
Mikael Roos
1943d6606b update years in license 2016-04-01 11:25:36 +02:00
Mikael Roos
5eebaa66ce update to latest version 2016-04-01 10:32:44 +02:00
Mikael Roos
c5cc0314c2 prepare to tag v0.7.10 2016-04-01 10:30:25 +02:00
Mikael Roos
71816261f2 prepare to merge master 2016-04-01 10:27:33 +02:00
Mikael Roos
a62d7cb6c2 Add backup option for images src-alt, #141. 2016-04-01 10:24:24 +02:00
Mikael Roos
ccbd08949f add for testcase #134 2016-01-26 17:40:10 +01:00
Mikael Roos
6467fcc748 Add require of ext-gd in composer.json, #133. 2016-01-14 16:19:00 +01:00
Mikael Roos
14d22a18e5 Merge pull request #133 from abcdmitry/patch-1
Add GD extension to the composer requiremets
2016-01-14 16:17:43 +01:00
Dmitry Lukashin
6d3687d838 Add PHP extensions to the composer requirements 2016-01-14 16:03:13 +03:00
Mikael Roos
ad8f6c12ee creating bundles 2015-12-07 17:40:00 +01:00
Mikael Roos
ad4930c3ae Fix strict mode only reporting 404 when failure, #127. 2015-12-07 17:39:34 +01:00
13 changed files with 340 additions and 102 deletions

View File

@@ -1098,7 +1098,13 @@ class CImage
$this->newWidth = round($factor * $width);
$this->log("New height was set.");
} else {
// Use existing width and height as new width and height.
$this->newWidth = $width;
$this->newHeight = $height;
}
// Get image dimensions for pre-resize image.
if ($this->cropToFit || $this->fillToFit) {
@@ -1696,25 +1702,45 @@ class CImage
// Resize by crop to fit
$this->log("Resizing using strategy - Crop to fit");
if (!$this->upscale && ($this->width < $this->newWidth || $this->height < $this->newHeight)) {
if (!$this->upscale
&& ($this->width < $this->newWidth || $this->height < $this->newHeight)) {
$this->log("Resizing - smaller image, do not upscale.");
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
//$cropX = round(($this->cropWidth/2) - ($this->width/2));
//$cropY = round(($this->cropHeight/2) - ($this->height/2));
$posX = 0;
$posY = 0;
$cropX = 0;
$cropY = 0;
if ($this->newWidth > $this->width) {
$posX = round(($this->newWidth - $this->width) / 2);
}
if ($this->newWidth < $this->width) {
$cropX = round(($this->width/2) - ($this->newWidth/2));
}
if ($this->newHeight > $this->height) {
$posY = round(($this->newHeight - $this->height) / 2);
}
if ($this->newHeight < $this->height) {
$cropY = round(($this->height/2) - ($this->newHeight/2));
}
$this->log(" cwidth: $this->cropWidth");
$this->log(" cheight: $this->cropHeight");
$this->log(" nwidth: $this->newWidth");
$this->log(" nheight: $this->newHeight");
$this->log(" width: $this->width");
$this->log(" height: $this->height");
$this->log(" posX: $posX");
$this->log(" posY: $posY");
$this->log(" cropX: $cropX");
$this->log(" cropY: $cropY");
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->newWidth, $this->newHeight);
//imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->width, $this->height);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->width, $this->height);
} else {
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
@@ -1747,14 +1773,14 @@ class CImage
}
if (!$this->upscale
&& ($this->width < $this->newWidth || $this->height < $this->newHeight)
&& ($this->width < $this->newWidth && $this->height < $this->newHeight)
) {
$this->log("Resizing - smaller image, do not upscale.");
$posX = round(($this->fillWidth - $this->width) / 2);
$posY = round(($this->fillHeight - $this->height) / 2);
$posX = round(($this->newWidth - $this->width) / 2);
$posY = round(($this->newHeight - $this->height) / 2);
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->fillWidth, $this->fillHeight);
imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->width, $this->height);
} else {
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
@@ -1798,7 +1824,7 @@ class CImage
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->width, $this->height);
$this->image = $imageResized;
$this->width = $this->newWidth;
$this->height = $this->newHeight;

View File

@@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2012 - 2014 Mikael Roos, me@mikaelroos.se
Copyright (c) 2012 - 2016 Mikael Roos, https://mikaelroos.se, mos@dbwebb.se
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.

View File

@@ -26,6 +26,7 @@ http://dbwebb.se/opensource/cimage
Requirements
--------------------------------------
@@ -46,14 +47,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.9 released 2015-12-07.**
**Latest stable version is v0.7.12 released 2016-06-01.**
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.9
git checkout v0.7.12
```
Make the cache-directory writable by the webserver.
@@ -76,7 +77,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.9/webroot/imgp.php
wget https://raw.githubusercontent.com/mosbth/cimage/v0.7.12/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.

View File

@@ -5,6 +5,27 @@ Revision history
[![Build Status](https://scrutinizer-ci.com/g/mosbth/cimage/badges/build.png?b=master)](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
v0.7.12 (2016-06-01)
-------------------------------------
* Fixed to correctly display image when using a resize strategy without height or width.
* Fixed background color for option `no-upscale`, #144.
v0.7.11 (2016-04-18)
-------------------------------------
* Add option for `skip_original` to config file to always skip original, #118.
v0.7.10 (2016-04-01)
-------------------------------------
* Add backup option for images `src-alt`, #141.
* Add require of ext-gd in composer.json, #133.
* Fix strict mode only reporting 404 when failure, #127.
v0.7.9 (2015-12-07)
-------------------------------------

View File

@@ -18,7 +18,11 @@
"docs": "http://dbwebb.se/opensource/cimage"
},
"require": {
"php": ">=5.3"
"php": ">=5.3",
"ext-gd": "*"
},
"suggest": {
"ext-exif": "*"
},
"autoload": {
"classmap": [

View File

@@ -8,7 +8,7 @@
*
*/
$version = "v0.7.9 (2015-12-07)";
$version = "v0.7.12 (2016-06-01)";
// For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/$version");
@@ -38,16 +38,16 @@ function errorPage($msg, $type = 500)
$header = "500 Internal Server Error";
}
if ($mode == "strict") {
$header = "404 Not Found";
}
header("HTTP/1.0 $header");
if ($mode == "development") {
die("[img.php] $msg");
}
if ($mode == "strict") {
$header = "404 Not Found";
}
error_log("[img.php] $msg");
die("HTTP/1.0 $header");
}
@@ -409,18 +409,28 @@ if (isset($shortcut)
$srcImage = urldecode(get('src'))
or errorPage('Must set src-attribute.', 404);
// Get settings for src-alt as backup image
$srcAltImage = urldecode(get('src-alt', null));
$srcAltConfig = getConfig('src_alt', null);
if (empty($srcAltImage)) {
$srcAltImage = $srcAltConfig;
}
// Check for valid/invalid characters
$imagePath = getConfig('image_path', __DIR__ . '/img/');
$imagePathConstraint = getConfig('image_path_constraint', true);
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
// Source is remote
$remoteSource = false;
// Dummy image feature
$dummyEnabled = getConfig('dummy_enabled', true);
$dummyFilename = getConfig('dummy_filename', 'dummy');
$dummyImage = false;
preg_match($validFilename, $srcImage)
or errorPage('Filename contains invalid characters.', 404);
or errorPage('Source filename contains invalid characters.', 404);
if ($dummyEnabled && $srcImage === $dummyFilename) {
@@ -430,19 +440,40 @@ if ($dummyEnabled && $srcImage === $dummyFilename) {
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
// If source is a remote file, ignore local file checks.
$remoteSource = true;
} elseif ($imagePathConstraint) {
} else {
// Check that the image is a file below the directory 'image_path'.
// Check if file exists on disk or try using src-alt
$pathToImage = realpath($imagePath . $srcImage);
$imageDir = realpath($imagePath);
is_file($pathToImage)
or errorPage(
'Source image is not a valid file, check the filename and that a
matching file exists on the filesystem.',
404
);
if (!is_file($pathToImage) && !empty($srcAltImage)) {
// Try using the src-alt instead
$srcImage = $srcAltImage;
$pathToImage = realpath($imagePath . $srcImage);
preg_match($validFilename, $srcImage)
or errorPage('Source (alt) filename contains invalid characters.', 404);
if ($dummyEnabled && $srcImage === $dummyFilename) {
// Check if src-alt is the dummy image
$dummyImage = true;
}
}
if (!$dummyImage) {
is_file($pathToImage)
or errorPage(
'Source image is not a valid file, check the filename and that a
matching file exists on the filesystem.',
404
);
}
}
if ($imagePathConstraint && !$dummyImage && !$remoteSource) {
// Check that the image is a file below the directory 'image_path'.
$imageDir = realpath($imagePath);
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
or errorPage(
@@ -668,8 +699,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
$useOriginalDefault = getConfig('skip_original', false);
if ($useOriginalDefault === true) {
verbose("use original is default ON");
$useOriginal = true;
verbose("skip original is default ON");
$useOriginal = false;
}
verbose("use original = $useOriginal");

BIN
webroot/img/apple.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
webroot/img/planet.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

@@ -10,6 +10,15 @@ return array(
/**
* Set mode as 'strict', 'production' or 'development'.
*
* development: Development mode with verbose error reporting. Option
* &verbose and &status enabled.
* production: Production mode logs all errors to file, giving server
* error 500 for bad usage. Option &verbose and &status
* disabled.
* strict: Strict mode logs few errors to file, giving server error
* 500 for bad usage. Stripped from comments and spaces.
* Option &verbose and &status disabled.
*
* Default values:
* mode: 'production'
*/
@@ -20,7 +29,7 @@ return array(
/**
* Where are the sources for the classfiles.
* Where are the sources for the class files.
*
* Default values:
* autoloader: null // used from v0.6.2
@@ -98,6 +107,20 @@ return array(
/**
* Use backup image if src-image is not found on disk. The backup image
* is only available for local images and based on wether the original
* image is found on disk or not. The backup image must be a local image
* or the dummy image.
*
* Default value:
* src_alt: null //disabled by default
*/
//'src_alt' => 'car.png',
//'src_alt' => 'dummy',
/**
* A regexp for validating characters in the image or alias filename.
*
@@ -139,6 +162,18 @@ return array(
/**
* Set skip-original to true to always process the image and use
* the cached version. Default is false and to use the original
* image when its no processing needed.
*
* Default value:
* skip_original: false
*/
//'skip_original' => true,
/**
* A function (hook) can be called after img.php has processed all
* configuration options and before processing the image using CImage.
@@ -188,7 +223,8 @@ return array(
/**
* Check that the imagefile is a file below 'image_path' using realpath().
* Security constraint to avoid reaching images outside image_path.
* This means that symbolic links to images outside the image_path will fail.
* This means that symbolic links to images outside the image_path will
* fail.
*
* Default value:
* image_path_constraint: true
@@ -379,7 +415,7 @@ return array(
/**
* default options for ascii image.
* Default options for ascii image.
*
* Default values as specified below in the array.
* ascii-options:

View File

@@ -2022,7 +2022,13 @@ class CImage
$this->newWidth = round($factor * $width);
$this->log("New height was set.");
} else {
// Use existing width and height as new width and height.
$this->newWidth = $width;
$this->newHeight = $height;
}
// Get image dimensions for pre-resize image.
if ($this->cropToFit || $this->fillToFit) {
@@ -2620,25 +2626,45 @@ class CImage
// Resize by crop to fit
$this->log("Resizing using strategy - Crop to fit");
if (!$this->upscale && ($this->width < $this->newWidth || $this->height < $this->newHeight)) {
if (!$this->upscale
&& ($this->width < $this->newWidth || $this->height < $this->newHeight)) {
$this->log("Resizing - smaller image, do not upscale.");
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
//$cropX = round(($this->cropWidth/2) - ($this->width/2));
//$cropY = round(($this->cropHeight/2) - ($this->height/2));
$posX = 0;
$posY = 0;
$cropX = 0;
$cropY = 0;
if ($this->newWidth > $this->width) {
$posX = round(($this->newWidth - $this->width) / 2);
}
if ($this->newWidth < $this->width) {
$cropX = round(($this->width/2) - ($this->newWidth/2));
}
if ($this->newHeight > $this->height) {
$posY = round(($this->newHeight - $this->height) / 2);
}
if ($this->newHeight < $this->height) {
$cropY = round(($this->height/2) - ($this->newHeight/2));
}
$this->log(" cwidth: $this->cropWidth");
$this->log(" cheight: $this->cropHeight");
$this->log(" nwidth: $this->newWidth");
$this->log(" nheight: $this->newHeight");
$this->log(" width: $this->width");
$this->log(" height: $this->height");
$this->log(" posX: $posX");
$this->log(" posY: $posY");
$this->log(" cropX: $cropX");
$this->log(" cropY: $cropY");
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->newWidth, $this->newHeight);
//imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->width, $this->height);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->width, $this->height);
} else {
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
@@ -2671,14 +2697,14 @@ class CImage
}
if (!$this->upscale
&& ($this->width < $this->newWidth || $this->height < $this->newHeight)
&& ($this->width < $this->newWidth && $this->height < $this->newHeight)
) {
$this->log("Resizing - smaller image, do not upscale.");
$posX = round(($this->fillWidth - $this->width) / 2);
$posY = round(($this->fillHeight - $this->height) / 2);
$posX = round(($this->newWidth - $this->width) / 2);
$posY = round(($this->newHeight - $this->height) / 2);
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->fillWidth, $this->fillHeight);
imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->width, $this->height);
} else {
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
@@ -2722,7 +2748,7 @@ class CImage
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->width, $this->height);
$this->image = $imageResized;
$this->width = $this->newWidth;
$this->height = $this->newHeight;
@@ -3817,7 +3843,7 @@ class CCache
*
*/
$version = "v0.7.9 (2015-12-07)";
$version = "v0.7.11 (2016-04-18)";
// For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/$version");
@@ -3847,16 +3873,16 @@ function errorPage($msg, $type = 500)
$header = "500 Internal Server Error";
}
if ($mode == "strict") {
$header = "404 Not Found";
}
header("HTTP/1.0 $header");
if ($mode == "development") {
die("[img.php] $msg");
}
if ($mode == "strict") {
$header = "404 Not Found";
}
error_log("[img.php] $msg");
die("HTTP/1.0 $header");
}
@@ -4218,18 +4244,28 @@ if (isset($shortcut)
$srcImage = urldecode(get('src'))
or errorPage('Must set src-attribute.', 404);
// Get settings for src-alt as backup image
$srcAltImage = urldecode(get('src-alt', null));
$srcAltConfig = getConfig('src_alt', null);
if (empty($srcAltImage)) {
$srcAltImage = $srcAltConfig;
}
// Check for valid/invalid characters
$imagePath = getConfig('image_path', __DIR__ . '/img/');
$imagePathConstraint = getConfig('image_path_constraint', true);
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
// Source is remote
$remoteSource = false;
// Dummy image feature
$dummyEnabled = getConfig('dummy_enabled', true);
$dummyFilename = getConfig('dummy_filename', 'dummy');
$dummyImage = false;
preg_match($validFilename, $srcImage)
or errorPage('Filename contains invalid characters.', 404);
or errorPage('Source filename contains invalid characters.', 404);
if ($dummyEnabled && $srcImage === $dummyFilename) {
@@ -4239,19 +4275,40 @@ if ($dummyEnabled && $srcImage === $dummyFilename) {
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
// If source is a remote file, ignore local file checks.
$remoteSource = true;
} elseif ($imagePathConstraint) {
} else {
// Check that the image is a file below the directory 'image_path'.
// Check if file exists on disk or try using src-alt
$pathToImage = realpath($imagePath . $srcImage);
$imageDir = realpath($imagePath);
is_file($pathToImage)
or errorPage(
'Source image is not a valid file, check the filename and that a
matching file exists on the filesystem.',
404
);
if (!is_file($pathToImage) && !empty($srcAltImage)) {
// Try using the src-alt instead
$srcImage = $srcAltImage;
$pathToImage = realpath($imagePath . $srcImage);
preg_match($validFilename, $srcImage)
or errorPage('Source (alt) filename contains invalid characters.', 404);
if ($dummyEnabled && $srcImage === $dummyFilename) {
// Check if src-alt is the dummy image
$dummyImage = true;
}
}
if (!$dummyImage) {
is_file($pathToImage)
or errorPage(
'Source image is not a valid file, check the filename and that a
matching file exists on the filesystem.',
404
);
}
}
if ($imagePathConstraint && !$dummyImage && !$remoteSource) {
// Check that the image is a file below the directory 'image_path'.
$imageDir = realpath($imagePath);
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
or errorPage(
@@ -4477,8 +4534,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
$useOriginalDefault = getConfig('skip_original', false);
if ($useOriginalDefault === true) {
verbose("use original is default ON");
$useOriginal = true;
verbose("skip original is default ON");
$useOriginal = false;
}
verbose("use original = $useOriginal");

View File

@@ -2022,7 +2022,13 @@ class CImage
$this->newWidth = round($factor * $width);
$this->log("New height was set.");
} else {
// Use existing width and height as new width and height.
$this->newWidth = $width;
$this->newHeight = $height;
}
// Get image dimensions for pre-resize image.
if ($this->cropToFit || $this->fillToFit) {
@@ -2620,25 +2626,45 @@ class CImage
// Resize by crop to fit
$this->log("Resizing using strategy - Crop to fit");
if (!$this->upscale && ($this->width < $this->newWidth || $this->height < $this->newHeight)) {
if (!$this->upscale
&& ($this->width < $this->newWidth || $this->height < $this->newHeight)) {
$this->log("Resizing - smaller image, do not upscale.");
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
//$cropX = round(($this->cropWidth/2) - ($this->width/2));
//$cropY = round(($this->cropHeight/2) - ($this->height/2));
$posX = 0;
$posY = 0;
$cropX = 0;
$cropY = 0;
if ($this->newWidth > $this->width) {
$posX = round(($this->newWidth - $this->width) / 2);
}
if ($this->newWidth < $this->width) {
$cropX = round(($this->width/2) - ($this->newWidth/2));
}
if ($this->newHeight > $this->height) {
$posY = round(($this->newHeight - $this->height) / 2);
}
if ($this->newHeight < $this->height) {
$cropY = round(($this->height/2) - ($this->newHeight/2));
}
$this->log(" cwidth: $this->cropWidth");
$this->log(" cheight: $this->cropHeight");
$this->log(" nwidth: $this->newWidth");
$this->log(" nheight: $this->newHeight");
$this->log(" width: $this->width");
$this->log(" height: $this->height");
$this->log(" posX: $posX");
$this->log(" posY: $posY");
$this->log(" cropX: $cropX");
$this->log(" cropY: $cropY");
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->newWidth, $this->newHeight);
//imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->width, $this->height);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->width, $this->height);
} else {
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
@@ -2671,14 +2697,14 @@ class CImage
}
if (!$this->upscale
&& ($this->width < $this->newWidth || $this->height < $this->newHeight)
&& ($this->width < $this->newWidth && $this->height < $this->newHeight)
) {
$this->log("Resizing - smaller image, do not upscale.");
$posX = round(($this->fillWidth - $this->width) / 2);
$posY = round(($this->fillHeight - $this->height) / 2);
$posX = round(($this->newWidth - $this->width) / 2);
$posY = round(($this->newHeight - $this->height) / 2);
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->fillWidth, $this->fillHeight);
imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->width, $this->height);
} else {
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
@@ -2722,7 +2748,7 @@ class CImage
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->newWidth, $this->newHeight);
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->width, $this->height);
$this->image = $imageResized;
$this->width = $this->newWidth;
$this->height = $this->newHeight;
@@ -3817,7 +3843,7 @@ class CCache
*
*/
$version = "v0.7.9 (2015-12-07)";
$version = "v0.7.11 (2016-04-18)";
// For CRemoteImage
define("CIMAGE_USER_AGENT", "CImage/$version");
@@ -3847,16 +3873,16 @@ function errorPage($msg, $type = 500)
$header = "500 Internal Server Error";
}
if ($mode == "strict") {
$header = "404 Not Found";
}
header("HTTP/1.0 $header");
if ($mode == "development") {
die("[img.php] $msg");
}
if ($mode == "strict") {
$header = "404 Not Found";
}
error_log("[img.php] $msg");
die("HTTP/1.0 $header");
}
@@ -4218,18 +4244,28 @@ if (isset($shortcut)
$srcImage = urldecode(get('src'))
or errorPage('Must set src-attribute.', 404);
// Get settings for src-alt as backup image
$srcAltImage = urldecode(get('src-alt', null));
$srcAltConfig = getConfig('src_alt', null);
if (empty($srcAltImage)) {
$srcAltImage = $srcAltConfig;
}
// Check for valid/invalid characters
$imagePath = getConfig('image_path', __DIR__ . '/img/');
$imagePathConstraint = getConfig('image_path_constraint', true);
$validFilename = getConfig('valid_filename', '#^[a-z0-9A-Z-/_ \.:]+$#');
// Source is remote
$remoteSource = false;
// Dummy image feature
$dummyEnabled = getConfig('dummy_enabled', true);
$dummyFilename = getConfig('dummy_filename', 'dummy');
$dummyImage = false;
preg_match($validFilename, $srcImage)
or errorPage('Filename contains invalid characters.', 404);
or errorPage('Source filename contains invalid characters.', 404);
if ($dummyEnabled && $srcImage === $dummyFilename) {
@@ -4239,19 +4275,40 @@ if ($dummyEnabled && $srcImage === $dummyFilename) {
} elseif ($allowRemote && $img->isRemoteSource($srcImage)) {
// If source is a remote file, ignore local file checks.
$remoteSource = true;
} elseif ($imagePathConstraint) {
} else {
// Check that the image is a file below the directory 'image_path'.
// Check if file exists on disk or try using src-alt
$pathToImage = realpath($imagePath . $srcImage);
$imageDir = realpath($imagePath);
is_file($pathToImage)
or errorPage(
'Source image is not a valid file, check the filename and that a
matching file exists on the filesystem.',
404
);
if (!is_file($pathToImage) && !empty($srcAltImage)) {
// Try using the src-alt instead
$srcImage = $srcAltImage;
$pathToImage = realpath($imagePath . $srcImage);
preg_match($validFilename, $srcImage)
or errorPage('Source (alt) filename contains invalid characters.', 404);
if ($dummyEnabled && $srcImage === $dummyFilename) {
// Check if src-alt is the dummy image
$dummyImage = true;
}
}
if (!$dummyImage) {
is_file($pathToImage)
or errorPage(
'Source image is not a valid file, check the filename and that a
matching file exists on the filesystem.',
404
);
}
}
if ($imagePathConstraint && !$dummyImage && !$remoteSource) {
// Check that the image is a file below the directory 'image_path'.
$imageDir = realpath($imagePath);
substr_compare($imageDir, $pathToImage, 0, strlen($imageDir)) == 0
or errorPage(
@@ -4477,8 +4534,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
$useOriginalDefault = getConfig('skip_original', false);
if ($useOriginalDefault === true) {
verbose("use original is default ON");
$useOriginal = true;
verbose("skip original is default ON");
$useOriginal = false;
}
verbose("use original = $useOriginal");

File diff suppressed because one or more lines are too long

View File

@@ -17,12 +17,13 @@ $description = "Do not upscale image when original image (slice) is smaller than
// Use these images in the test
$images = array(
'car.png',
'apple.jpg',
);
// For each image, apply these testcases
$nc = null; //"&nc"; //null; //&nc';
$nc = "&bgc=660000"; //null; //"&nc"; //null; //&nc';
$testcase = array(
$nc . '&w=600',
$nc . '&w=600&no-upscale',
@@ -34,16 +35,20 @@ $testcase = array(
$nc . '&w=700&h=400&no-upscale&stretch',
$nc . '&w=700&h=200&stretch',
$nc . '&w=700&h=200&no-upscale&stretch',
$nc . '&w=300&h=400&stretch',
$nc . '&w=300&h=400&no-upscale&stretch',
$nc . '&w=600&h=400&crop-to-fit',
$nc . '&w=600&h=400&no-upscale&crop-to-fit',
$nc . '&w=600&h=200&crop-to-fit',
$nc . '&w=600&h=200&no-upscale&crop-to-fit',
$nc . '&w=300&h=400&crop-to-fit',
$nc . '&w=300&h=400&no-upscale&crop-to-fit',
$nc . '&w=600&h=400&fill-to-fit',
$nc . '&w=600&h=400&no-upscale&fill-to-fit',
$nc . '&w=250&h=400&stretch',
$nc . '&w=250&h=400&no-upscale&stretch',
$nc . '&w=700&h=400&crop-to-fit',
$nc . '&w=700&h=400&no-upscale&crop-to-fit',
$nc . '&w=700&h=200&crop-to-fit',
$nc . '&w=700&h=200&no-upscale&crop-to-fit',
$nc . '&w=250&h=400&crop-to-fit',
$nc . '&w=250&h=400&no-upscale&crop-to-fit',
$nc . '&w=600&h=500&fill-to-fit',
$nc . '&w=600&h=500&no-upscale&fill-to-fit',
$nc . '&w=250&h=400&fill-to-fit',
$nc . '&w=250&h=400&no-upscale&fill-to-fit',
$nc . '&w=700&h=400&fill-to-fit',
$nc . '&w=700&h=400&no-upscale&fill-to-fit',
/*
$nc . '&w=600&ar=1.6',
$nc . '&w=600&ar=1.6&no-upscale',