mirror of
https://github.com/mosbth/cimage.git
synced 2025-07-31 13:40:08 +02:00
updating strategies to use for no-upscale
This commit is contained in:
73
CImage.php
73
CImage.php
@@ -1034,12 +1034,12 @@ class CImage
|
||||
|
||||
$convolve = null;
|
||||
if ($this->convolve) {
|
||||
$convolve = 'convolve' . preg_replace('/[^a-zA-Z0-9]/', '', $this->convolve);
|
||||
$convolve = '_conv' . preg_replace('/[^a-zA-Z0-9]/', '', $this->convolve);
|
||||
}
|
||||
|
||||
$upscale = null;
|
||||
if ($this->upscale !== self::UPSCALE_DEFAULT) {
|
||||
$upscale = 'nu';
|
||||
$upscale = '_nu';
|
||||
}
|
||||
|
||||
$subdir = str_replace('/', '-', dirname($this->imageSrc));
|
||||
@@ -1331,6 +1331,23 @@ class CImage
|
||||
|
||||
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));
|
||||
|
||||
$posX = 0;
|
||||
$posY = 0;
|
||||
|
||||
if ($this->newWidth > $this->width) {
|
||||
$posX = round(($this->newWidth - $this->width) / 2);
|
||||
}
|
||||
|
||||
if ($this->newHeight > $this->height) {
|
||||
$posY = round(($this->newHeight - $this->height) / 2);
|
||||
}
|
||||
|
||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
||||
imagecopy($imageResized, $this->image, $posX, $posY, $cropX, $cropY, $this->newWidth, $this->newHeight);
|
||||
} else {
|
||||
$cropX = round(($this->cropWidth/2) - ($this->newWidth/2));
|
||||
$cropY = round(($this->cropHeight/2) - ($this->newHeight/2));
|
||||
@@ -1338,11 +1355,12 @@ class CImage
|
||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
||||
imagecopyresampled($imgPreCrop, $this->image, 0, 0, 0, 0, $this->cropWidth, $this->cropHeight, $this->width, $this->height);
|
||||
imagecopy($imageResized, $imgPreCrop, 0, 0, $cropX, $cropY, $this->newWidth, $this->newHeight);
|
||||
$this->image = $imageResized;
|
||||
$this->width = $this->newWidth;
|
||||
$this->height = $this->newHeight;
|
||||
}
|
||||
|
||||
$this->image = $imageResized;
|
||||
$this->width = $this->newWidth;
|
||||
$this->height = $this->newHeight;
|
||||
|
||||
} else if ($this->fillToFit) {
|
||||
|
||||
// Resize by fill to fit
|
||||
@@ -1361,34 +1379,63 @@ class CImage
|
||||
$posY = round(($this->newHeight - $this->fillHeight) / 2);
|
||||
}
|
||||
|
||||
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.");
|
||||
$posX = round(($this->fillWidth - $this->width) / 2);
|
||||
$posY = round(($this->fillHeight - $this->height) / 2);
|
||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
||||
imagecopy($imageResized, $this->image, $posX, $posY, 0, 0, $this->fillWidth, $this->fillHeight);
|
||||
$this->image = $imageResized;
|
||||
$this->width = $this->newWidth;
|
||||
$this->height = $this->newHeight;
|
||||
|
||||
} else {
|
||||
$imgPreFill = $this->CreateImageKeepTransparency($this->fillWidth, $this->fillHeight);
|
||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
||||
imagecopyresampled($imgPreFill, $this->image, 0, 0, 0, 0, $this->fillWidth, $this->fillHeight, $this->width, $this->height);
|
||||
imagecopy($imageResized, $imgPreFill, $posX, $posY, 0, 0, $this->fillWidth, $this->fillHeight);
|
||||
$this->image = $imageResized;
|
||||
$this->width = $this->newWidth;
|
||||
$this->height = $this->newHeight;
|
||||
}
|
||||
|
||||
$this->image = $imageResized;
|
||||
$this->width = $this->newWidth;
|
||||
$this->height = $this->newHeight;
|
||||
|
||||
} else if (!($this->newWidth == $this->width && $this->newHeight == $this->height)) {
|
||||
|
||||
// Resize it
|
||||
$this->log("Resizing, new height and/or width");
|
||||
|
||||
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.");
|
||||
|
||||
if (!$this->keepRatio) {
|
||||
$this->log("Resizing - stretch to fit selected.");
|
||||
|
||||
$posX = 0;
|
||||
$posY = 0;
|
||||
$cropX = 0;
|
||||
$cropY = 0;
|
||||
|
||||
if ($this->newWidth > $this->width && $this->newHeight > $this->height) {
|
||||
$posX = round(($this->newWidth - $this->width) / 2);
|
||||
$posY = round(($this->newHeight - $this->height) / 2);
|
||||
} else if ($this->newWidth > $this->width) {
|
||||
$posX = round(($this->newWidth - $this->width) / 2);
|
||||
$cropY = round(($this->height - $this->newHeight) / 2);
|
||||
} else if ($this->newHeight > $this->height) {
|
||||
$posY = round(($this->newHeight - $this->height) / 2);
|
||||
$cropX = round(($this->width - $this->newWidth) / 2);
|
||||
}
|
||||
|
||||
//$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);
|
||||
$this->image = $imageResized;
|
||||
$this->width = $this->newWidth;
|
||||
$this->height = $this->newHeight;
|
||||
}
|
||||
} else {
|
||||
$imageResized = $this->CreateImageKeepTransparency($this->newWidth, $this->newHeight);
|
||||
imagecopyresampled($imageResized, $this->image, 0, 0, 0, 0, $this->newWidth, $this->newHeight, $this->width, $this->height);
|
||||
|
@@ -550,9 +550,21 @@ if ($verbose) {
|
||||
unset($query['nc']);
|
||||
unset($query['json']);
|
||||
$url1 = '?' . htmlentities(urldecode(http_build_query($query)));
|
||||
$url2 = '?' . urldecode(http_build_query($query));
|
||||
echo <<<EOD
|
||||
<a href=$url1><code>$url1</code></a><br>
|
||||
<img src='{$url1}' />
|
||||
<pre id="json"></pre>
|
||||
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
window.getDetails = function (url, id) {
|
||||
$.getJSON(url, function(data) {
|
||||
element = document.getElementById(id);
|
||||
element.innerHTML = "filename: " + data.filename + "\\ncolors: " + data.colors + "\\nsize: " + data.size + "\\nwidth: " + data.width + "\\nheigh: " + data.height + "\\naspect-ratio: " + data.aspectRatio;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript">window.getDetails("{$url2}&json", "json")</script>
|
||||
EOD;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ $images = array(
|
||||
|
||||
|
||||
// For each image, apply these testcases
|
||||
$nc = null; //"&nc"; //null; //&nc';
|
||||
$nc = "&nc"; //null; //&nc';
|
||||
$testcase = array(
|
||||
$nc . '&w=600',
|
||||
$nc . '&w=600&no-upscale',
|
||||
@@ -30,10 +30,18 @@ $testcase = array(
|
||||
$nc . '&h=400&no-upscale',
|
||||
$nc . '&w=600&h=400',
|
||||
$nc . '&w=600&h=400&no-upscale',
|
||||
$nc . '&w=600&h=400&stretch',
|
||||
$nc . '&w=600&h=400&no-upscale&stretch',
|
||||
$nc . '&w=700&h=400&stretch',
|
||||
$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',
|
||||
/*
|
||||
|
Reference in New Issue
Block a user