mirror of
https://github.com/mosbth/cimage.git
synced 2025-08-29 18:39:53 +02:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
cde8bab6e7 | ||
|
5edbfc9b54 | ||
|
9e9c44c935 | ||
|
9088647d3a | ||
|
8ad324b4f5 | ||
|
3b16b4b79d | ||
|
4e940164f9 | ||
|
1943d6606b | ||
|
5eebaa66ce | ||
|
c5cc0314c2 |
44
CImage.php
44
CImage.php
@@ -1098,7 +1098,13 @@ class CImage
|
|||||||
$this->newWidth = round($factor * $width);
|
$this->newWidth = round($factor * $width);
|
||||||
$this->log("New height was set.");
|
$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.
|
// Get image dimensions for pre-resize image.
|
||||||
if ($this->cropToFit || $this->fillToFit) {
|
if ($this->cropToFit || $this->fillToFit) {
|
||||||
@@ -1696,25 +1702,45 @@ class CImage
|
|||||||
// Resize by crop to fit
|
// Resize by crop to fit
|
||||||
$this->log("Resizing using strategy - 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.");
|
$this->log("Resizing - smaller image, do not upscale.");
|
||||||
|
|
||||||
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
//$cropX = round(($this->cropWidth/2) - ($this->width/2));
|
||||||
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
//$cropY = round(($this->cropHeight/2) - ($this->height/2));
|
||||||
|
|
||||||
$posX = 0;
|
$posX = 0;
|
||||||
$posY = 0;
|
$posY = 0;
|
||||||
|
$cropX = 0;
|
||||||
|
$cropY = 0;
|
||||||
|
|
||||||
if ($this->newWidth > $this->width) {
|
if ($this->newWidth > $this->width) {
|
||||||
$posX = round(($this->newWidth - $this->width) / 2);
|
$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) {
|
if ($this->newHeight > $this->height) {
|
||||||
$posY = round(($this->newHeight - $this->height) / 2);
|
$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);
|
$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 {
|
} else {
|
||||||
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
||||||
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
||||||
@@ -1747,14 +1773,14 @@ class CImage
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->upscale
|
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.");
|
$this->log("Resizing - smaller image, do not upscale.");
|
||||||
$posX = round(($this->fillWidth - $this->width) / 2);
|
$posX = round(($this->newWidth - $this->width) / 2);
|
||||||
$posY = round(($this->fillHeight - $this->height) / 2);
|
$posY = round(($this->newHeight - $this->height) / 2);
|
||||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
$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 {
|
} else {
|
||||||
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
|
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
|
||||||
@@ -1798,7 +1824,7 @@ class CImage
|
|||||||
|
|
||||||
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
|
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
|
||||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
$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->image = $imageResized;
|
||||||
$this->width = $this->newWidth;
|
$this->width = $this->newWidth;
|
||||||
$this->height = $this->newHeight;
|
$this->height = $this->newHeight;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
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
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
@@ -26,6 +26,7 @@ http://dbwebb.se/opensource/cimage
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Requirements
|
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).
|
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.
|
I prefer cloning like this. Do switch to the latest stable version.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone git://github.com/mosbth/cimage.git
|
git clone git://github.com/mosbth/cimage.git
|
||||||
cd cimage
|
cd cimage
|
||||||
git checkout v0.7.9
|
git checkout v0.7.12
|
||||||
```
|
```
|
||||||
|
|
||||||
Make the cache-directory writable by the webserver.
|
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.
|
Dowload the version of your choice like this.
|
||||||
|
|
||||||
```bash
|
```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.
|
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.
|
||||||
|
13
REVISION.md
13
REVISION.md
@@ -5,6 +5,19 @@ Revision history
|
|||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/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)
|
v0.7.10 (2016-04-01)
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$version = "v0.7.9* (2015-12-07)";
|
$version = "v0.7.12 (2016-06-01)";
|
||||||
|
|
||||||
// For CRemoteImage
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/$version");
|
define("CIMAGE_USER_AGENT", "CImage/$version");
|
||||||
@@ -699,8 +699,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
|||||||
$useOriginalDefault = getConfig('skip_original', false);
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
if ($useOriginalDefault === true) {
|
if ($useOriginalDefault === true) {
|
||||||
verbose("use original is default ON");
|
verbose("skip original is default ON");
|
||||||
$useOriginal = true;
|
$useOriginal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
BIN
webroot/img/apple.jpg
Normal file
BIN
webroot/img/apple.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@@ -10,6 +10,15 @@ return array(
|
|||||||
/**
|
/**
|
||||||
* Set mode as 'strict', 'production' or 'development'.
|
* 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:
|
* Default values:
|
||||||
* mode: 'production'
|
* 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:
|
* Default values:
|
||||||
* autoloader: null // used from v0.6.2
|
* autoloader: null // used from v0.6.2
|
||||||
@@ -153,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
|
* A function (hook) can be called after img.php has processed all
|
||||||
* configuration options and before processing the image using CImage.
|
* configuration options and before processing the image using CImage.
|
||||||
@@ -394,7 +415,7 @@ return array(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* default options for ascii image.
|
* Default options for ascii image.
|
||||||
*
|
*
|
||||||
* Default values as specified below in the array.
|
* Default values as specified below in the array.
|
||||||
* ascii-options:
|
* ascii-options:
|
||||||
|
@@ -2022,7 +2022,13 @@ class CImage
|
|||||||
$this->newWidth = round($factor * $width);
|
$this->newWidth = round($factor * $width);
|
||||||
$this->log("New height was set.");
|
$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.
|
// Get image dimensions for pre-resize image.
|
||||||
if ($this->cropToFit || $this->fillToFit) {
|
if ($this->cropToFit || $this->fillToFit) {
|
||||||
@@ -2620,25 +2626,45 @@ class CImage
|
|||||||
// Resize by crop to fit
|
// Resize by crop to fit
|
||||||
$this->log("Resizing using strategy - 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.");
|
$this->log("Resizing - smaller image, do not upscale.");
|
||||||
|
|
||||||
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
//$cropX = round(($this->cropWidth/2) - ($this->width/2));
|
||||||
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
//$cropY = round(($this->cropHeight/2) - ($this->height/2));
|
||||||
|
|
||||||
$posX = 0;
|
$posX = 0;
|
||||||
$posY = 0;
|
$posY = 0;
|
||||||
|
$cropX = 0;
|
||||||
|
$cropY = 0;
|
||||||
|
|
||||||
if ($this->newWidth > $this->width) {
|
if ($this->newWidth > $this->width) {
|
||||||
$posX = round(($this->newWidth - $this->width) / 2);
|
$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) {
|
if ($this->newHeight > $this->height) {
|
||||||
$posY = round(($this->newHeight - $this->height) / 2);
|
$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);
|
$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 {
|
} else {
|
||||||
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
||||||
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
||||||
@@ -2671,14 +2697,14 @@ class CImage
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->upscale
|
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.");
|
$this->log("Resizing - smaller image, do not upscale.");
|
||||||
$posX = round(($this->fillWidth - $this->width) / 2);
|
$posX = round(($this->newWidth - $this->width) / 2);
|
||||||
$posY = round(($this->fillHeight - $this->height) / 2);
|
$posY = round(($this->newHeight - $this->height) / 2);
|
||||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
$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 {
|
} else {
|
||||||
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
|
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
|
||||||
@@ -2722,7 +2748,7 @@ class CImage
|
|||||||
|
|
||||||
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
|
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
|
||||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
$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->image = $imageResized;
|
||||||
$this->width = $this->newWidth;
|
$this->width = $this->newWidth;
|
||||||
$this->height = $this->newHeight;
|
$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
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/$version");
|
define("CIMAGE_USER_AGENT", "CImage/$version");
|
||||||
@@ -4508,8 +4534,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
|||||||
$useOriginalDefault = getConfig('skip_original', false);
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
if ($useOriginalDefault === true) {
|
if ($useOriginalDefault === true) {
|
||||||
verbose("use original is default ON");
|
verbose("skip original is default ON");
|
||||||
$useOriginal = true;
|
$useOriginal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
@@ -2022,7 +2022,13 @@ class CImage
|
|||||||
$this->newWidth = round($factor * $width);
|
$this->newWidth = round($factor * $width);
|
||||||
$this->log("New height was set.");
|
$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.
|
// Get image dimensions for pre-resize image.
|
||||||
if ($this->cropToFit || $this->fillToFit) {
|
if ($this->cropToFit || $this->fillToFit) {
|
||||||
@@ -2620,25 +2626,45 @@ class CImage
|
|||||||
// Resize by crop to fit
|
// Resize by crop to fit
|
||||||
$this->log("Resizing using strategy - 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.");
|
$this->log("Resizing - smaller image, do not upscale.");
|
||||||
|
|
||||||
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
//$cropX = round(($this->cropWidth/2) - ($this->width/2));
|
||||||
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
//$cropY = round(($this->cropHeight/2) - ($this->height/2));
|
||||||
|
|
||||||
$posX = 0;
|
$posX = 0;
|
||||||
$posY = 0;
|
$posY = 0;
|
||||||
|
$cropX = 0;
|
||||||
|
$cropY = 0;
|
||||||
|
|
||||||
if ($this->newWidth > $this->width) {
|
if ($this->newWidth > $this->width) {
|
||||||
$posX = round(($this->newWidth - $this->width) / 2);
|
$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) {
|
if ($this->newHeight > $this->height) {
|
||||||
$posY = round(($this->newHeight - $this->height) / 2);
|
$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);
|
$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 {
|
} else {
|
||||||
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
||||||
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
||||||
@@ -2671,14 +2697,14 @@ class CImage
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->upscale
|
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.");
|
$this->log("Resizing - smaller image, do not upscale.");
|
||||||
$posX = round(($this->fillWidth - $this->width) / 2);
|
$posX = round(($this->newWidth - $this->width) / 2);
|
||||||
$posY = round(($this->fillHeight - $this->height) / 2);
|
$posY = round(($this->newHeight - $this->height) / 2);
|
||||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
$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 {
|
} else {
|
||||||
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
|
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
|
||||||
@@ -2722,7 +2748,7 @@ class CImage
|
|||||||
|
|
||||||
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
|
//$this->log("posX=$posX, posY=$posY, cropX=$cropX, cropY=$cropY.");
|
||||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
$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->image = $imageResized;
|
||||||
$this->width = $this->newWidth;
|
$this->width = $this->newWidth;
|
||||||
$this->height = $this->newHeight;
|
$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
|
// For CRemoteImage
|
||||||
define("CIMAGE_USER_AGENT", "CImage/$version");
|
define("CIMAGE_USER_AGENT", "CImage/$version");
|
||||||
@@ -4508,8 +4534,8 @@ $useOriginal = getDefined(array('skip-original', 'so'), false, true);
|
|||||||
$useOriginalDefault = getConfig('skip_original', false);
|
$useOriginalDefault = getConfig('skip_original', false);
|
||||||
|
|
||||||
if ($useOriginalDefault === true) {
|
if ($useOriginalDefault === true) {
|
||||||
verbose("use original is default ON");
|
verbose("skip original is default ON");
|
||||||
$useOriginal = true;
|
$useOriginal = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("use original = $useOriginal");
|
verbose("use original = $useOriginal");
|
||||||
|
File diff suppressed because one or more lines are too long
@@ -17,12 +17,13 @@ $description = "Do not upscale image when original image (slice) is smaller than
|
|||||||
// Use these images in the test
|
// Use these images in the test
|
||||||
$images = array(
|
$images = array(
|
||||||
'car.png',
|
'car.png',
|
||||||
|
'apple.jpg',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// For each image, apply these testcases
|
// For each image, apply these testcases
|
||||||
$nc = null; //"&nc"; //null; //&nc';
|
$nc = "&bgc=660000"; //null; //"&nc"; //null; //&nc';
|
||||||
$testcase = array(
|
$testcase = array(
|
||||||
$nc . '&w=600',
|
$nc . '&w=600',
|
||||||
$nc . '&w=600&no-upscale',
|
$nc . '&w=600&no-upscale',
|
||||||
@@ -34,16 +35,20 @@ $testcase = array(
|
|||||||
$nc . '&w=700&h=400&no-upscale&stretch',
|
$nc . '&w=700&h=400&no-upscale&stretch',
|
||||||
$nc . '&w=700&h=200&stretch',
|
$nc . '&w=700&h=200&stretch',
|
||||||
$nc . '&w=700&h=200&no-upscale&stretch',
|
$nc . '&w=700&h=200&no-upscale&stretch',
|
||||||
$nc . '&w=300&h=400&stretch',
|
$nc . '&w=250&h=400&stretch',
|
||||||
$nc . '&w=300&h=400&no-upscale&stretch',
|
$nc . '&w=250&h=400&no-upscale&stretch',
|
||||||
$nc . '&w=600&h=400&crop-to-fit',
|
$nc . '&w=700&h=400&crop-to-fit',
|
||||||
$nc . '&w=600&h=400&no-upscale&crop-to-fit',
|
$nc . '&w=700&h=400&no-upscale&crop-to-fit',
|
||||||
$nc . '&w=600&h=200&crop-to-fit',
|
$nc . '&w=700&h=200&crop-to-fit',
|
||||||
$nc . '&w=600&h=200&no-upscale&crop-to-fit',
|
$nc . '&w=700&h=200&no-upscale&crop-to-fit',
|
||||||
$nc . '&w=300&h=400&crop-to-fit',
|
$nc . '&w=250&h=400&crop-to-fit',
|
||||||
$nc . '&w=300&h=400&no-upscale&crop-to-fit',
|
$nc . '&w=250&h=400&no-upscale&crop-to-fit',
|
||||||
$nc . '&w=600&h=400&fill-to-fit',
|
$nc . '&w=600&h=500&fill-to-fit',
|
||||||
$nc . '&w=600&h=400&no-upscale&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',
|
||||||
$nc . '&w=600&ar=1.6&no-upscale',
|
$nc . '&w=600&ar=1.6&no-upscale',
|
||||||
|
Reference in New Issue
Block a user