mirror of
https://github.com/mosbth/cimage.git
synced 2025-04-21 17:31:58 +02:00
Fixed background color for option , #144.
This commit is contained in:
parent
8ad324b4f5
commit
9088647d3a
39
CImage.php
39
CImage.php
@ -1099,6 +1099,7 @@ class CImage
|
||||
$this->log("New height was set.");
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Get image dimensions for pre-resize image.
|
||||
if ($this->cropToFit || $this->fillToFit) {
|
||||
@ -1696,25 +1697,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 +1768,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 +1819,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;
|
||||
|
@ -5,6 +5,12 @@ Revision history
|
||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/master)
|
||||
|
||||
|
||||
v0.7.12 (2016-05-31)
|
||||
-------------------------------------
|
||||
|
||||
* Fixed background color for option `no-upscale`, #144.
|
||||
|
||||
|
||||
v0.7.11 (2016-04-18)
|
||||
-------------------------------------
|
||||
|
||||
|
BIN
webroot/img/apple.jpg
Normal file
BIN
webroot/img/apple.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -23,7 +23,7 @@ return array(
|
||||
* mode: 'production'
|
||||
*/
|
||||
//'mode' => 'production',
|
||||
//'mode' => 'development',
|
||||
'mode' => 'development',
|
||||
//'mode' => 'strict',
|
||||
|
||||
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user