mirror of
https://github.com/mosbth/cimage.git
synced 2025-07-23 09:41:39 +02:00
resize-strategies together with no upscale
This commit is contained in:
@@ -5,6 +5,7 @@ Image conversion on the fly using PHP
|
|||||||
[](https://travis-ci.org/mosbth/cimage)
|
[](https://travis-ci.org/mosbth/cimage)
|
||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/resize)
|
[](https://scrutinizer-ci.com/g/mosbth/cimage/build-status/resize)
|
||||||
[](https://scrutinizer-ci.com/g/mosbth/cimage/?branch=resize)
|
[](https://scrutinizer-ci.com/g/mosbth/cimage/?branch=resize)
|
||||||
|
[](https://scrutinizer-ci.com/g/mosbth/cimage/?branch=resize)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@ v0.8.* (2015-12-05) (branch resize)
|
|||||||
|
|
||||||
* Improving build phase using travis and scrutinizer.
|
* Improving build phase using travis and scrutinizer.
|
||||||
* Code validating with phpunit and phpcs.
|
* Code validating with phpunit and phpcs.
|
||||||
* Moved classes to src/, adding namespace and support PSR-4.
|
* Moved classes to src/, adding namespace and (only) support PSR-4.
|
||||||
* Require PHP 5.4.
|
* Require PHP 5.4.
|
||||||
|
|
||||||
|
|
||||||
|
@@ -973,21 +973,26 @@ class CImage
|
|||||||
$imres = $this->imageResizer;
|
$imres = $this->imageResizer;
|
||||||
$strategy = null;
|
$strategy = null;
|
||||||
|
|
||||||
if ($this->keepRatio == true) {
|
|
||||||
$strategy = $imres::KEEP_RATIO;
|
$strategy = $imres::KEEP_RATIO;
|
||||||
|
|
||||||
|
if ($this->keepRatio == false) {
|
||||||
|
$strategy = $imres::STRETCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->cropToFit == true) {
|
if ($this->cropToFit == true) {
|
||||||
$strategy = $imres::CROP_TO_FIT;
|
$strategy = $imres::CROP_TO_FIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->fillToFit == true) {
|
if ($this->fillToFit == true) {
|
||||||
$strategy = $imres::FILL_TO_FIT;
|
$strategy = $imres::FILL_TO_FIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
$imres->setResizeStrategy($strategy)
|
$imres->setResizeStrategy($strategy)
|
||||||
|
->allowUpscale($this->upscale)
|
||||||
->calculateTargetWidthAndHeight();
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
$this->newWidth = $imres->width();
|
//$this->newWidth = $imres->getTargetWidth();
|
||||||
$this->newHeight = $imres->height();
|
//$this->newHeight = $imres->getTargetHeight();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Crop, use cropped width and height as base for calulations
|
// Crop, use cropped width and height as base for calulations
|
||||||
@@ -1275,6 +1280,7 @@ class CImage
|
|||||||
$filename = basename($this->pathToImage);
|
$filename = basename($this->pathToImage);
|
||||||
$cropToFit = $this->cropToFit ? '_cf' : null;
|
$cropToFit = $this->cropToFit ? '_cf' : null;
|
||||||
$fillToFit = $this->fillToFit ? '_ff' : null;
|
$fillToFit = $this->fillToFit ? '_ff' : null;
|
||||||
|
$stretch = $this->keepRatio === false ? '_st' : null;
|
||||||
$crop_x = $this->crop_x ? "_x{$this->crop_x}" : null;
|
$crop_x = $this->crop_x ? "_x{$this->crop_x}" : null;
|
||||||
$crop_y = $this->crop_y ? "_y{$this->crop_y}" : null;
|
$crop_y = $this->crop_y ? "_y{$this->crop_y}" : null;
|
||||||
$scale = $this->scale ? "_s{$this->scale}" : null;
|
$scale = $this->scale ? "_s{$this->scale}" : null;
|
||||||
@@ -1344,7 +1350,7 @@ class CImage
|
|||||||
}
|
}
|
||||||
|
|
||||||
$file = $prefix . $subdir . $filename . $width . $height
|
$file = $prefix . $subdir . $filename . $width . $height
|
||||||
. $offset . $crop . $cropToFit . $fillToFit
|
. $offset . $crop . $cropToFit . $fillToFit . $stretch
|
||||||
. $crop_x . $crop_y . $upscale
|
. $crop_x . $crop_y . $upscale
|
||||||
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
. $quality . $filters . $sharpen . $emboss . $blur . $palette
|
||||||
. $optimize . $compress
|
. $optimize . $compress
|
||||||
@@ -1392,8 +1398,7 @@ class CImage
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load image from disk. Try to load image without verbose error message,
|
* Load image from disk.
|
||||||
* if fail, load again and display error messages.
|
|
||||||
*
|
*
|
||||||
* @param string $src of image.
|
* @param string $src of image.
|
||||||
* @param string $dir as base directory where images are.
|
* @param string $dir as base directory where images are.
|
||||||
@@ -1627,10 +1632,32 @@ class CImage
|
|||||||
*/
|
*/
|
||||||
public function resize()
|
public function resize()
|
||||||
{
|
{
|
||||||
$imgres = $this->imageResizer;
|
$res = $this->imageResizer;
|
||||||
|
|
||||||
$this->log("### Starting to Resize()");
|
$this->log("### Starting to Resize()");
|
||||||
$this->log("Upscale = '$this->upscale'");
|
$this->log(" Upscale = '$this->upscale'");
|
||||||
|
|
||||||
|
$sw = $res->getSourceWidth();
|
||||||
|
$sh = $res->getSourceHeight();
|
||||||
|
$tw = $res->getTargetWidth();
|
||||||
|
$th = $res->getTargetHeight();
|
||||||
|
$cx = $res->getCropX();
|
||||||
|
$cy = $res->getCropY();
|
||||||
|
$cw = $res->getCropWidth();
|
||||||
|
$ch = $res->getCropHeight();
|
||||||
|
$dx = $res->getDestinationX();
|
||||||
|
$dy = $res->getDestinationY();
|
||||||
|
$dw = $res->getDestinationWidth();
|
||||||
|
$dh = $res->getDestinationHeight();
|
||||||
|
|
||||||
|
$img = $this->CreateImageKeepTransparency($tw, $th);
|
||||||
|
$this->imageCopyResampled($img, $this->image, $dx, $dy, $cx, $cy, $dw, $dh, $cw, $ch);
|
||||||
|
$this->image = $img;
|
||||||
|
$this->width = $tw;
|
||||||
|
$this->height = $th;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
|
||||||
|
|
||||||
// Only use a specified area of the image, $this->offset is defining the area to use
|
// Only use a specified area of the image, $this->offset is defining the area to use
|
||||||
if (isset($this->offset)) {
|
if (isset($this->offset)) {
|
||||||
@@ -2417,7 +2444,7 @@ class CImage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only covert if cachedir is writable
|
// Only convert if cachedir is writable
|
||||||
if (is_writable($this->saveFolder)) {
|
if (is_writable($this->saveFolder)) {
|
||||||
// Load file and check if conversion is needed
|
// Load file and check if conversion is needed
|
||||||
$image = new Imagick($this->pathToImage);
|
$image = new Imagick($this->pathToImage);
|
||||||
|
@@ -24,12 +24,20 @@ class CImageResizer
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set as expected target image dimensions.
|
* Set as expected target image/canvas dimensions.
|
||||||
*/
|
*/
|
||||||
private $targetWidth;
|
private $targetWidth;
|
||||||
//private $targetWidthOrig; // Save original value
|
|
||||||
private $targetHeight;
|
private $targetHeight;
|
||||||
//private $targetheightOrig; // Save original value
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where should the image go on the canvas.
|
||||||
|
*/
|
||||||
|
private $destinationX;
|
||||||
|
private $destinationY;
|
||||||
|
private $destinationWidth;
|
||||||
|
private $destinationHeight;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -114,7 +122,14 @@ class CImageResizer
|
|||||||
/**
|
/**
|
||||||
* The currently selected resize strategy.
|
* The currently selected resize strategy.
|
||||||
*/
|
*/
|
||||||
private $resizeStrategy;
|
private $resizeStrategy = self::KEEP_RATIO;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow upscale of smaller images by default, set to false to disallow.
|
||||||
|
*/
|
||||||
|
private $upscale = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -186,6 +201,10 @@ class CImageResizer
|
|||||||
return "FILL_TO_FIT";
|
return "FILL_TO_FIT";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case self::STRETCH:
|
||||||
|
return "STRETCH";
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
@@ -210,6 +229,42 @@ class CImageResizer
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow or disallow upscale smaller images.
|
||||||
|
*
|
||||||
|
* @param boolean $upscale
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function allowUpscale($upscale)
|
||||||
|
{
|
||||||
|
$this->upscale = $upscale;
|
||||||
|
$this->log("# Allow upscale is $this->upscale.");
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a value is upscaled or not by compare $current to $orig,
|
||||||
|
* if $current is larger than $orig then check if upscaled is allowed.
|
||||||
|
*
|
||||||
|
* @param float &$current value to check and change.
|
||||||
|
* @param float $orig value to check against.
|
||||||
|
*
|
||||||
|
* @return float as the value respected by the upscale setting.
|
||||||
|
*/
|
||||||
|
public function respectUpscale(&$current, $orig)
|
||||||
|
{
|
||||||
|
if (!$this->upscale && $current > $orig) {
|
||||||
|
$this->log("# Disallowed upscale of $orig to $current");
|
||||||
|
$current = $orig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set base for requested width and height.
|
* Set base for requested width and height.
|
||||||
*
|
*
|
||||||
@@ -437,18 +492,6 @@ class CImageResizer
|
|||||||
$this->log("# Calculate new width and height.");
|
$this->log("# Calculate new width and height.");
|
||||||
$this->log(" Source size {$this->srcWidth}x{$this->srcHeight}.");
|
$this->log(" Source size {$this->srcWidth}x{$this->srcHeight}.");
|
||||||
$this->log(" Target dimension (before) {$this->targetWidth}x{$this->targetHeight}.");
|
$this->log(" Target dimension (before) {$this->targetWidth}x{$this->targetHeight}.");
|
||||||
/*
|
|
||||||
// Set default values to crop area to be whole source image
|
|
||||||
$aspectRatio = $this->srcWidth / $this->srcHeight;
|
|
||||||
$this->cropX = 0;
|
|
||||||
$this->cropY = 0;
|
|
||||||
$this->cropWidth = $this->srcWidth;
|
|
||||||
$this->cropHeight = $this->srcHeight;
|
|
||||||
|
|
||||||
// Get relations of original & target image
|
|
||||||
$width = $this->srcWidth;
|
|
||||||
$height = $this->srcHeight;
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Set default values to crop area to be whole source image
|
// Set default values to crop area to be whole source image
|
||||||
$sw = $this->srcWidth;
|
$sw = $this->srcWidth;
|
||||||
@@ -456,10 +499,17 @@ class CImageResizer
|
|||||||
$ar = $sw / $sh;
|
$ar = $sw / $sh;
|
||||||
$tw = $this->targetWidth;
|
$tw = $this->targetWidth;
|
||||||
$th = $this->targetHeight;
|
$th = $this->targetHeight;
|
||||||
|
$dx = 0;
|
||||||
|
$dy = 0;
|
||||||
|
$dw = null;
|
||||||
|
$dh = null;
|
||||||
$cx = 0;
|
$cx = 0;
|
||||||
$cy = 0;
|
$cy = 0;
|
||||||
$cw = $this->srcWidth;
|
$cw = $sw;
|
||||||
$ch = $this->srcHeight;
|
$ch = $sh;
|
||||||
|
$rs = $this->resizeStrategy;
|
||||||
|
$both = isset($tw) && isset($th);
|
||||||
|
$ratio = $both ? $tw / $th : null;
|
||||||
|
|
||||||
if (is_null($tw) && is_null($th)) {
|
if (is_null($tw) && is_null($th)) {
|
||||||
|
|
||||||
@@ -471,109 +521,103 @@ class CImageResizer
|
|||||||
} elseif (isset($tw) && is_null($th)) {
|
} elseif (isset($tw) && is_null($th)) {
|
||||||
|
|
||||||
// Keep aspect ratio, make th based on tw
|
// Keep aspect ratio, make th based on tw
|
||||||
|
$this->respectUpscale($tw, $sw);
|
||||||
$th = $tw / $ar;
|
$th = $tw / $ar;
|
||||||
$this->log(" New th x{$th}");
|
$this->log(" New th x{$th}");
|
||||||
|
|
||||||
} elseif (is_null($tw) && isset($th)) {
|
} elseif (is_null($tw) && isset($th)) {
|
||||||
|
|
||||||
// Keep aspect ratio, make tw based on th
|
// Keep aspect ratio, make tw based on th
|
||||||
|
$this->respectUpscale($th, $sh);
|
||||||
$tw = $th * $ar;
|
$tw = $th * $ar;
|
||||||
$this->log(" New tw {$tw}x");
|
$this->log(" New tw {$tw}x");
|
||||||
|
|
||||||
} elseif (isset($tw) && isset($th)) {
|
} elseif ($rs === CImageResizer::KEEP_RATIO && $both) {
|
||||||
|
|
||||||
// Keep aspect ratio, make fit in imaginary box
|
// Keep aspect ratio, make fit in box not larger than tw/th
|
||||||
if ($ar < 1) {
|
$this->log(" Keep ratio, ratio target=$ratio, source=$ar");
|
||||||
|
|
||||||
|
if ($ratio > $ar) {
|
||||||
|
$this->respectUpscale($th, $sh);
|
||||||
$tw = $th * $ar;
|
$tw = $th * $ar;
|
||||||
$this->log(" New tw {$tw}x");
|
$this->log(" New tw {$tw}x");
|
||||||
} else {
|
} elseif ($ratio < $ar) {
|
||||||
|
$this->respectUpscale($tw, $sw);
|
||||||
$th = $tw / $ar;
|
$th = $tw / $ar;
|
||||||
$this->log(" New th x{$th}");
|
$this->log(" New th x{$th}");
|
||||||
}
|
} else {
|
||||||
|
$this->respectUpscale($tw, $sw);
|
||||||
|
$this->respectUpscale($th, $sh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
} elseif ($rs === CImageResizer::STRETCH && $both) {
|
||||||
if (isset($tw) && isset($th)) {
|
|
||||||
|
|
||||||
// Both new width and height are set.
|
// Stretch to fit, leave as is
|
||||||
// Use targetWidth and targetHeight as max width/height, image
|
$this->log(" Stretch, leave as is");
|
||||||
// should not be larger.
|
$this->respectUpscale($tw, $sw);
|
||||||
$ratioWidth = $width / $this->targetWidth;
|
$this->respectUpscale($th, $sh);
|
||||||
$ratioHeight = $height / $this->targetHeight;
|
|
||||||
$ratio = ($ratioWidth > $ratioHeight) ? $ratioWidth : $ratioHeight;
|
|
||||||
$this->targetWidth = round($width / $ratio);
|
|
||||||
$this->targetHeight = round($height / $ratio);
|
|
||||||
$this->log(" New width and height was set.");
|
|
||||||
|
|
||||||
} elseif (isset($this->targetWidth)) {
|
} elseif ($rs === CImageResizer::CROP_TO_FIT && $both) {
|
||||||
|
|
||||||
// Use new width as max-width
|
// Crop to fit image in box
|
||||||
$factor = (float)$this->targetWidth / (float)$width;
|
// Ignores respectUpscale by intention
|
||||||
$this->targetHeight = round($factor * $height);
|
$this->log(" Crop to fit, ratio target=$ratio, source=$ar");
|
||||||
$this->log(" New height x$this->targetHeight.");
|
|
||||||
|
|
||||||
} elseif (isset($this->targetHeight)) {
|
if ($ratio > $ar) {
|
||||||
|
$ch = $sw / $ratio;
|
||||||
|
$cy = ($sh - $ch) / 2;
|
||||||
|
} elseif ($ratio < $ar) {
|
||||||
|
$cw = $sh * $ratio;
|
||||||
|
$cx = ($sw - $cw) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
// Use new height as max-hight
|
$this->log(" Parts cx=$cx, cy=$cy, cw=$cw, ch=$ch");
|
||||||
$factor = (float)$this->targetHeight / (float)$height;
|
|
||||||
$this->targetWidth = round($factor * $width);
|
} elseif ($rs === CImageResizer::FILL_TO_FIT && $both) {
|
||||||
$this->log(" New width {$this->targetWidth}x.");
|
|
||||||
|
// Fill to fit image in box
|
||||||
|
$this->log(" Fill to fit, ratio target=$ratio, source=$ar");
|
||||||
|
$dw = $tw;
|
||||||
|
$dh = $th;
|
||||||
|
|
||||||
|
if ($ratio > $ar) {
|
||||||
|
$dw = $th * $ar;
|
||||||
|
$dh = $th;
|
||||||
|
} elseif ($ratio < $ar) {
|
||||||
|
$dw = $tw;
|
||||||
|
$dh = $tw / $ar;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->respectUpscale($dw, $sw);
|
||||||
|
$this->respectUpscale($dh, $sh);
|
||||||
|
$dx = ($tw - $dw) / 2;
|
||||||
|
$dy = ($th - $dh) / 2;
|
||||||
|
|
||||||
|
$this->log(" Destination area dx=$dx, dy=$dy, dw=$dw, dh=$dh");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
// All done, sum it up
|
||||||
|
$dw = is_null($dw) ? $tw : $dw;
|
||||||
// No new height or width is set, use existing measures.
|
$dh = is_null($dh) ? $th : $dh;
|
||||||
|
|
||||||
/*
|
|
||||||
$this->targetWidth = isset($this->targetWidth)
|
|
||||||
? $this->targetWidth
|
|
||||||
: $this->srcWidth;
|
|
||||||
$this->targetHeight = isset($this->targetHeight)
|
|
||||||
? $this->targetHeight
|
|
||||||
: $this->srcHeight;
|
|
||||||
*/
|
|
||||||
|
|
||||||
$this->targetWidth = round($tw);
|
$this->targetWidth = round($tw);
|
||||||
$this->targetHeight = round($th);
|
$this->targetHeight = round($th);
|
||||||
|
$this->destinationX = round($dx);
|
||||||
|
$this->destinationY = round($dy);
|
||||||
|
$this->destinationWidth = round($dw);
|
||||||
|
$this->destinationHeight = round($dh);
|
||||||
$this->cropX = round($cx);
|
$this->cropX = round($cx);
|
||||||
$this->cropY = round($cy);
|
$this->cropY = round($cy);
|
||||||
$this->cropWidth = round($cw);
|
$this->cropWidth = round($cw);
|
||||||
$this->cropHeight = round($ch);
|
$this->cropHeight = round($ch);
|
||||||
|
|
||||||
$this->log(" Target dimension (after) {$this->targetWidth}x{$this->targetHeight}.");
|
$this->log(" Target dimension (after) {$this->targetWidth}x{$this->targetHeight}.");
|
||||||
$this->log(" Crop {$this->cropX}x{$this->cropY} by {$this->cropWidth}x{$this->cropHeight}.");
|
$this->log(" Crop area {$this->cropX}x{$this->cropY} by {$this->cropWidth}x{$this->cropHeight}.");
|
||||||
|
$this->log(" Destination area {$this->destinationX}x{$this->destinationY} by {$this->destinationWidth}x{$this->destinationHeight}.");
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$ratioWidth = $this->srcWidth / $this->targetWidth;
|
|
||||||
$ratioHeight = $this->srcHeight / $this->targetHeight;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($this->resizeStrategy === self::CROP_TO_FIT) {
|
|
||||||
|
|
||||||
// Use targetWidth and targetHeight as defined
|
|
||||||
// width/height, image should fit the area.
|
|
||||||
$this->log(" Crop to fit.");
|
|
||||||
$ratio = ($ratioWidth < $ratioHeight) ? $ratioWidth : $ratioHeight;
|
|
||||||
$this->cropWidth = round($width / $ratio);
|
|
||||||
$this->cropHeight = round($height / $ratio);
|
|
||||||
$this->log(" Crop width, height, ratio: $this->cropWidth x $this->cropHeight ($ratio).");
|
|
||||||
|
|
||||||
} elseif ($this->resizeStrategy === self::FILL_TO_FIT) {
|
|
||||||
|
|
||||||
// Use targetWidth and targetHeight as defined
|
|
||||||
// width/height, image should fit the area.
|
|
||||||
$this->log(" Fill to fit.");
|
|
||||||
$ratio = ($ratioWidth < $ratioHeight) ? $ratioHeight : $ratioWidth;
|
|
||||||
$this->fillWidth = round($width / $ratio);
|
|
||||||
$this->fillHeight = round($height / $ratio);
|
|
||||||
$this->log(" Fill width, height, ratio: $this->fillWidth x $this->fillHeight ($ratio).");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// Check if there is an area to crop off
|
// Check if there is an area to crop off
|
||||||
if (isset($this->area)) {
|
if (isset($this->area)) {
|
||||||
@@ -614,85 +658,6 @@ class CImageResizer
|
|||||||
$this->log(" Crop area is width {$width}px, height {$height}px, start_x {$this->crop['start_x']}px, start_y {$this->crop['start_y']}px.");
|
$this->log(" Crop area is width {$width}px, height {$height}px, start_x {$this->crop['start_x']}px, start_y {$this->crop['start_y']}px.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// Calculate new width and height if keeping aspect-ratio.
|
|
||||||
if ($this->resizeStrategy === self::KEEP_RATIO) {
|
|
||||||
|
|
||||||
$this->log(" Keep aspect ratio.");
|
|
||||||
|
|
||||||
// Crop-to-fit and both new width and height are set.
|
|
||||||
if (($this->resizeStrategy === self::CROP_TO_FIT
|
|
||||||
|| $this->resizeStrategy === self::FILL_TO_FIT)
|
|
||||||
&& isset($this->targetWidth)
|
|
||||||
&& isset($this->targetHeight)
|
|
||||||
) {
|
|
||||||
|
|
||||||
// Use targetWidth and targetHeight as width/height, image should
|
|
||||||
// fit in box.
|
|
||||||
$this->log(" Use targetWidth and targetHeight as width/height, image should fit in box.");
|
|
||||||
|
|
||||||
} elseif (isset($this->targetWidth) && isset($this->targetHeight)) {
|
|
||||||
|
|
||||||
// Both new width and height are set.
|
|
||||||
// Use targetWidth and targetHeight as max width/height, image
|
|
||||||
// should not be larger.
|
|
||||||
$ratioWidth = $width / $this->targetWidth;
|
|
||||||
$ratioHeight = $height / $this->targetHeight;
|
|
||||||
$ratio = ($ratioWidth > $ratioHeight) ? $ratioWidth : $ratioHeight;
|
|
||||||
$this->targetWidth = round($width / $ratio);
|
|
||||||
$this->targetHeight = round($height / $ratio);
|
|
||||||
$this->log(" New width and height was set.");
|
|
||||||
|
|
||||||
} elseif (isset($this->targetWidth)) {
|
|
||||||
|
|
||||||
// Use new width as max-width
|
|
||||||
$factor = (float)$this->targetWidth / (float)$width;
|
|
||||||
$this->targetHeight = round($factor * $height);
|
|
||||||
$this->log(" New height x$this->targetHeight.");
|
|
||||||
|
|
||||||
} elseif (isset($this->targetHeight)) {
|
|
||||||
|
|
||||||
// Use new height as max-hight
|
|
||||||
$factor = (float)$this->targetHeight / (float)$height;
|
|
||||||
$this->targetWidth = round($factor * $width);
|
|
||||||
$this->log(" New width {$this->targetWidth}x.");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
// Get image dimensions for pre-resize image.
|
|
||||||
if ($this->resizeStrategy === self::CROP_TO_FIT
|
|
||||||
|| $this->resizeStrategy === self::FILL_TO_FIT
|
|
||||||
) {
|
|
||||||
|
|
||||||
// Get relations of original & target image
|
|
||||||
$ratioWidth = $width / $this->targetWidth;
|
|
||||||
$ratioHeight = $height / $this->targetHeight;
|
|
||||||
|
|
||||||
if ($this->resizeStrategy === self::CROP_TO_FIT) {
|
|
||||||
|
|
||||||
// Use targetWidth and targetHeight as defined
|
|
||||||
// width/height, image should fit the area.
|
|
||||||
$this->log(" Crop to fit.");
|
|
||||||
$ratio = ($ratioWidth < $ratioHeight) ? $ratioWidth : $ratioHeight;
|
|
||||||
$this->cropWidth = round($width / $ratio);
|
|
||||||
$this->cropHeight = round($height / $ratio);
|
|
||||||
$this->log(" Crop width, height, ratio: $this->cropWidth x $this->cropHeight ($ratio).");
|
|
||||||
|
|
||||||
} elseif ($this->resizeStrategy === self::FILL_TO_FIT) {
|
|
||||||
|
|
||||||
// Use targetWidth and targetHeight as defined
|
|
||||||
// width/height, image should fit the area.
|
|
||||||
$this->log(" Fill to fit.");
|
|
||||||
$ratio = ($ratioWidth < $ratioHeight) ? $ratioHeight : $ratioWidth;
|
|
||||||
$this->fillWidth = round($width / $ratio);
|
|
||||||
$this->fillHeight = round($height / $ratio);
|
|
||||||
$this->log(" Fill width, height, ratio: $this->fillWidth x $this->fillHeight ($ratio).");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// Crop, ensure to set new width and height
|
// Crop, ensure to set new width and height
|
||||||
@@ -706,26 +671,45 @@ class CImageResizer
|
|||||||
: $this->crop['height']);
|
: $this->crop['height']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill to fit, ensure to set new width and height
|
*/
|
||||||
/*if ($this->fillToFit) {
|
|
||||||
$this->log("FillToFit.");
|
|
||||||
$this->targetWidth = round(isset($this->targetWidth) ? $this->targetWidth : $this->crop['width']);
|
|
||||||
$this->targetHeight = round(isset($this->targetHeight) ? $this->targetHeight : $this->crop['height']);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get source width.
|
||||||
|
*
|
||||||
|
* @return integer as source width
|
||||||
|
*/
|
||||||
|
public function getSourceWidth()
|
||||||
|
{
|
||||||
|
return $this->srcWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get source height.
|
||||||
|
*
|
||||||
|
* @return integer as source height
|
||||||
|
*/
|
||||||
|
public function getSourceHeight()
|
||||||
|
{
|
||||||
|
return $this->srcHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get target width.
|
* Get target width.
|
||||||
*
|
*
|
||||||
* @return integer as target width
|
* @return integer as target width
|
||||||
*/
|
*/
|
||||||
public function getTargetwidth()
|
public function getTargetWidth()
|
||||||
{
|
{
|
||||||
return $this->targetWidth ? round($this->targetWidth) : null;
|
return $this->targetWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -735,9 +719,57 @@ class CImageResizer
|
|||||||
*
|
*
|
||||||
* @return integer as target height
|
* @return integer as target height
|
||||||
*/
|
*/
|
||||||
public function getTargetheight()
|
public function getTargetHeight()
|
||||||
{
|
{
|
||||||
return $this->targetHeight ? round($this->targetHeight) : null;
|
return $this->targetHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get destination x.
|
||||||
|
*
|
||||||
|
* @return integer as destination x
|
||||||
|
*/
|
||||||
|
public function getDestinationX()
|
||||||
|
{
|
||||||
|
return $this->destinationX;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get destination y.
|
||||||
|
*
|
||||||
|
* @return integer as destination y
|
||||||
|
*/
|
||||||
|
public function getDestinationY()
|
||||||
|
{
|
||||||
|
return $this->destinationY;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get destination width.
|
||||||
|
*
|
||||||
|
* @return integer as destination width
|
||||||
|
*/
|
||||||
|
public function getDestinationWidth()
|
||||||
|
{
|
||||||
|
return $this->destinationWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get destination height.
|
||||||
|
*
|
||||||
|
* @return integer as destination height
|
||||||
|
*/
|
||||||
|
public function getDestinationHeight()
|
||||||
|
{
|
||||||
|
return $this->destinationHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -750,14 +782,6 @@ class CImageResizer
|
|||||||
public function getCropX()
|
public function getCropX()
|
||||||
{
|
{
|
||||||
return $this->cropX;
|
return $this->cropX;
|
||||||
/*
|
|
||||||
$cropX = 0;
|
|
||||||
|
|
||||||
if ($this->cropWidth) {
|
|
||||||
$cropX = round(($this->cropWidth/2) - ($this->targetWidth/2));
|
|
||||||
};
|
|
||||||
|
|
||||||
return $cropX;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -770,14 +794,6 @@ class CImageResizer
|
|||||||
public function getCropY()
|
public function getCropY()
|
||||||
{
|
{
|
||||||
return $this->cropY;
|
return $this->cropY;
|
||||||
/*
|
|
||||||
$cropY = 0;
|
|
||||||
|
|
||||||
if ($this->cropHeight) {
|
|
||||||
$cropY = round(($this->cropHeight/2) - ($this->targetHeight/2));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $cropY;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -790,14 +806,6 @@ class CImageResizer
|
|||||||
public function getCropWidth()
|
public function getCropWidth()
|
||||||
{
|
{
|
||||||
return $this->cropWidth;
|
return $this->cropWidth;
|
||||||
/*
|
|
||||||
$cropWidth = $this->srcWidth;
|
|
||||||
|
|
||||||
if ($this->cropWidth) {
|
|
||||||
$cropWidth = round($this->cropWidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $cropWidth;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -810,13 +818,5 @@ class CImageResizer
|
|||||||
public function getCropHeight()
|
public function getCropHeight()
|
||||||
{
|
{
|
||||||
return $this->cropHeight;
|
return $this->cropHeight;
|
||||||
/*
|
|
||||||
$cropHeight = $this->srcHeight;
|
|
||||||
|
|
||||||
if ($this->cropHeight) {
|
|
||||||
$cropHeight = round($this->cropHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $cropHeight;*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,22 +15,21 @@ class CImageResizerStrategyCropToFitTest extends \PHPUnit_Framework_TestCase
|
|||||||
return array(
|
return array(
|
||||||
|
|
||||||
// Square
|
// Square
|
||||||
array(100, 100, null, null, 100, 100, 0, 0, 100, 100),
|
array(100, 100, 200, 200, 0, 0, 100, 100),
|
||||||
array(100, 100, null, 200, 200, 200, 0, 0, 100, 100),
|
array(100, 100, 200, 100, 0, 25, 100, 50),
|
||||||
array(100, 100, 200, null, 200, 200, 0, 0, 100, 100),
|
array(100, 100, 100, 200, 25, 0, 50, 100),
|
||||||
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
|
||||||
|
|
||||||
// Landscape
|
// Landscape
|
||||||
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
array(200, 100, 400, 200, 0, 0, 200, 100),
|
||||||
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
array(200, 100, 50, 50, 50, 0, 100, 100),
|
||||||
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
array(200, 100, 400, 100, 0, 25, 200, 50),
|
||||||
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
array(200, 100, 100, 400, round(175/2), 0, 25, 100),
|
||||||
|
|
||||||
// Portrait
|
// Portrait
|
||||||
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
array(100, 200, 50, 100, 0, 0, 100, 200),
|
||||||
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
array(100, 200, 50, 50, 0, 50, 100, 100),
|
||||||
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
array(100, 200, 200, 50, 0, round(175/2), 100, 25),
|
||||||
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
array(100, 200, 50, 200, 25, 0, 50, 200),
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -44,21 +43,74 @@ class CImageResizerStrategyCropToFitTest extends \PHPUnit_Framework_TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testResize1($srcWidth, $srcHeight, $targetWidth, $targetHeight, $targetWidthAfter, $targetHeightAfter, $cropX, $cropY, $cropWidth, $cropHeight)
|
public function testResize1($sw, $sh, $tw, $th, $cx, $cy, $cw, $ch)
|
||||||
{
|
{
|
||||||
$img = new CImageResizer(/*'logger'/**/);
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
$img->setSource($srcWidth, $srcHeight)
|
$img->setSource($sw, $sh)
|
||||||
->setBaseWidthHeight($targetWidth, $targetHeight)
|
->setBaseWidthHeight($tw, $th)
|
||||||
->setResizeStrategy(CImageResizer::CROP_TO_FIT)
|
->setResizeStrategy(CImageResizer::CROP_TO_FIT)
|
||||||
->calculateTargetWidthAndHeight();
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
$this->assertEquals($targetWidthAfter, $img->getTargetWidth(), "Target width not correct.");
|
$this->assertEquals($tw, $img->getTargetWidth(), "Target width not correct.");
|
||||||
$this->assertEquals($targetHeightAfter, $img->getTargetHeight(), "Target height not correct.");
|
$this->assertEquals($th, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
$this->assertEquals($cropX, $img->getCropX(), "CropX not correct.");
|
$this->assertEquals($cx, $img->getCropX(), "CropX not correct.");
|
||||||
$this->assertEquals($cropY, $img->getCropY(), "CropY not correct.");
|
$this->assertEquals($cy, $img->getCropY(), "CropY not correct.");
|
||||||
$this->assertEquals($cropWidth, $img->getCropWidth(), "CropWidth not correct.");
|
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
$this->assertEquals($cropHeight, $img->getCropHeight(), "CropHeight not correct.");
|
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages2()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
|
||||||
|
// Square
|
||||||
|
[100, 100, 200, 200, 50, 50, 100, 100],
|
||||||
|
[100, 100, 400, 100, 150, 0, 100, 100],
|
||||||
|
[100, 100, 100, 400, 0, 150, 100, 100],
|
||||||
|
[100, 100, 400, 400, 150, 150, 100, 100],
|
||||||
|
[491, 323, 600, 400, 55, 39, 491, 323],
|
||||||
|
|
||||||
|
// Landscape
|
||||||
|
|
||||||
|
// Portrait
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize2($sw, $sh, $tw, $th, $cx, $cy, $cw, $ch)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
|
$img->setSource($sw, $sh)
|
||||||
|
->setBaseWidthHeight($tw, $th)
|
||||||
|
->setResizeStrategy(CImageResizer::CROP_TO_FIT)
|
||||||
|
->allowUpscale(false)
|
||||||
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($tw, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($th, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($cx, $img->getCropX(), "CropX not correct.");
|
||||||
|
$this->assertEquals($cy, $img->getCropY(), "CropY not correct.");
|
||||||
|
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
|
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,22 +15,21 @@ class CImageResizerStrategyFillToFitTest extends \PHPUnit_Framework_TestCase
|
|||||||
return array(
|
return array(
|
||||||
|
|
||||||
// Square
|
// Square
|
||||||
array(100, 100, null, null, 100, 100, 0, 0, 100, 100),
|
array(100, 100, 200, 200, 0, 0, 200, 200),
|
||||||
array(100, 100, null, 200, 200, 200, 0, 0, 100, 100),
|
array(100, 100, 100, 50, 25, 0, 50, 50),
|
||||||
array(100, 100, 200, null, 200, 200, 0, 0, 100, 100),
|
array(100, 100, 50, 100, 0, 25, 50, 50),
|
||||||
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
|
||||||
|
|
||||||
// Landscape
|
// Landscape
|
||||||
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
array(200, 100, 400, 200, 0, 0, 400, 200),
|
||||||
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
array(200, 100, 100, 100, 0, 25, 100, 50),
|
||||||
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
array(200, 100, 400, 100, 100, 0, 200, 100),
|
||||||
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
array(200, 100, 100, 400, 0, 175, 100, 50),
|
||||||
|
|
||||||
// Portrait
|
// Portrait
|
||||||
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
array(100, 200, 200, 400, 0, 0, 200, 400),
|
||||||
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
array(100, 200, 100, 100, 25, 0, 50, 100),
|
||||||
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
array(100, 200, 400, 100, 175, 0, 50, 100),
|
||||||
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
array(100, 200, 100, 400, 0, 100, 100, 200),
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -44,21 +43,76 @@ class CImageResizerStrategyFillToFitTest extends \PHPUnit_Framework_TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testResize1($srcWidth, $srcHeight, $targetWidth, $targetHeight, $targetWidthAfter, $targetHeightAfter, $cropX, $cropY, $cropWidth, $cropHeight)
|
public function testResize1($sw, $sh, $tw, $th, $dx, $dy, $dw, $dh)
|
||||||
{
|
{
|
||||||
$img = new CImageResizer(/*'logger'/**/);
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
$img->setSource($srcWidth, $srcHeight)
|
$img->setSource($sw, $sh)
|
||||||
->setBaseWidthHeight($targetWidth, $targetHeight)
|
->setBaseWidthHeight($tw, $th)
|
||||||
->setResizeStrategy(CImageResizer::FILL_TO_FIT)
|
->setResizeStrategy(CImageResizer::FILL_TO_FIT)
|
||||||
->calculateTargetWidthAndHeight();
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
$this->assertEquals($targetWidthAfter, $img->getTargetWidth(), "Target width not correct.");
|
$this->assertEquals($tw, $img->getTargetWidth(), "Target width not correct.");
|
||||||
$this->assertEquals($targetHeightAfter, $img->getTargetHeight(), "Target height not correct.");
|
$this->assertEquals($th, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($dx, $img->getDestinationX(), "DestinationX not correct.");
|
||||||
|
$this->assertEquals($dy, $img->getDestinationY(), "DestinationY not correct.");
|
||||||
|
$this->assertEquals($dw, $img->getDestinationWidth(), "DestinationWidth not correct.");
|
||||||
|
$this->assertEquals($dh, $img->getDestinationHeight(), "DestinationHeight not correct.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages2()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
|
||||||
|
// Square
|
||||||
|
[100, 100, 200, 200, 50, 50, 100, 100],
|
||||||
|
[100, 100, 400, 100, 150, 0, 100, 100],
|
||||||
|
[100, 100, 100, 400, 0, 150, 100, 100],
|
||||||
|
[100, 100, 400, 400, 150, 150, 100, 100],
|
||||||
|
[491, 323, 600, 400, 55, 39, 491, 323],
|
||||||
|
|
||||||
|
// Landscape
|
||||||
|
|
||||||
|
// Portrait
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages2
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize2($sw, $sh, $tw, $th, $dx, $dy, $dw, $dh)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
|
$img->setSource($sw, $sh)
|
||||||
|
->setBaseWidthHeight($tw, $th)
|
||||||
|
->setResizeStrategy(CImageResizer::FILL_TO_FIT)
|
||||||
|
->allowUpscale(false)
|
||||||
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($tw, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($th, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($dx, $img->getDestinationX(), "DestinationX not correct.");
|
||||||
|
$this->assertEquals($dy, $img->getDestinationY(), "DestinationY not correct.");
|
||||||
|
$this->assertEquals($dw, $img->getDestinationWidth(), "DestinationWidth not correct.");
|
||||||
|
$this->assertEquals($dh, $img->getDestinationHeight(), "DestinationHeight not correct.");
|
||||||
|
|
||||||
$this->assertEquals($cropX, $img->getCropX(), "CropX not correct.");
|
|
||||||
$this->assertEquals($cropY, $img->getCropY(), "CropY not correct.");
|
|
||||||
$this->assertEquals($cropWidth, $img->getCropWidth(), "CropWidth not correct.");
|
|
||||||
$this->assertEquals($cropHeight, $img->getCropHeight(), "CropHeight not correct.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,17 +21,17 @@ class CImageResizerStrategyKeepAspectRatioTest extends \PHPUnit_Framework_TestCa
|
|||||||
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
||||||
|
|
||||||
// Landscape
|
// Landscape
|
||||||
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
|
||||||
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
|
||||||
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
|
||||||
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
|
||||||
|
|
||||||
// Portrait
|
|
||||||
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
||||||
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
||||||
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
||||||
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
|
||||||
|
// Portrait
|
||||||
|
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
||||||
|
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
||||||
|
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,4 +61,66 @@ class CImageResizerStrategyKeepAspectRatioTest extends \PHPUnit_Framework_TestCa
|
|||||||
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages2()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
|
||||||
|
// Square
|
||||||
|
array(100, 100, 100, 100, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, null, 200, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, null, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, 100, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 100, 200, 100, 100, 0, 0, 100, 100),
|
||||||
|
array(100, 100, 200, 200, 100, 100, 0, 0, 100, 100),
|
||||||
|
|
||||||
|
// Landscape
|
||||||
|
//array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
||||||
|
//array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
//array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
||||||
|
//array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
||||||
|
|
||||||
|
// Portrait
|
||||||
|
//array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
||||||
|
//array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
//array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
||||||
|
//array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages2
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize2($sw, $sh, $tw, $th, $twa, $tha, $cx, $cy, $cw, $ch)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
|
$img->setSource($sw, $sh)
|
||||||
|
->setBaseWidthHeight($tw, $th)
|
||||||
|
->setResizeStrategy(CImageResizer::KEEP_RATIO)
|
||||||
|
->allowUpscale(false)
|
||||||
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($twa, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($tha, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($cx, $img->getCropX(), "CropX not correct.");
|
||||||
|
$this->assertEquals($cy, $img->getCropY(), "CropY not correct.");
|
||||||
|
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
|
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,22 +15,17 @@ class CImageResizerStrategyStretchTest extends \PHPUnit_Framework_TestCase
|
|||||||
return array(
|
return array(
|
||||||
|
|
||||||
// Square
|
// Square
|
||||||
array(100, 100, null, null, 100, 100, 0, 0, 100, 100),
|
array(100, 100, 200, 200),
|
||||||
array(100, 100, null, 200, 200, 200, 0, 0, 100, 100),
|
array(100, 100, 200, 100),
|
||||||
array(100, 100, 200, null, 200, 200, 0, 0, 100, 100),
|
array(100, 100, 100, 200),
|
||||||
array(100, 100, 200, 200, 200, 200, 0, 0, 100, 100),
|
|
||||||
|
|
||||||
// Landscape
|
// Landscape
|
||||||
array(100, 200, null, null, 100, 200, 0, 0, 100, 200),
|
array(200, 100, 400, 200),
|
||||||
array(100, 200, null, 100, 50, 100, 0, 0, 100, 200),
|
array(200, 100, 100, 200),
|
||||||
array(100, 200, 50, null, 50, 100, 0, 0, 100, 200),
|
|
||||||
array(100, 200, 50, 100, 50, 100, 0, 0, 100, 200),
|
|
||||||
|
|
||||||
// Portrait
|
// Portrait
|
||||||
array(200, 100, null, null, 200, 100, 0, 0, 200, 100),
|
array(100, 200, 50, 100),
|
||||||
array(200, 100, null, 200, 400, 200, 0, 0, 200, 100),
|
array(100, 200, 100, 100),
|
||||||
array(200, 100, 400, null, 400, 200, 0, 0, 200, 100),
|
|
||||||
array(200, 100, 400, 200, 400, 200, 0, 0, 200, 100),
|
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -44,7 +39,7 @@ class CImageResizerStrategyStretchTest extends \PHPUnit_Framework_TestCase
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testResize1($sw, $sh, $tw, $th, $twa, $tha, $cx, $cy, $cw, $ch)
|
public function testResize1($sw, $sh, $tw, $th)
|
||||||
{
|
{
|
||||||
$img = new CImageResizer(/*'logger'/**/);
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
@@ -53,12 +48,8 @@ class CImageResizerStrategyStretchTest extends \PHPUnit_Framework_TestCase
|
|||||||
->setResizeStrategy(CImageResizer::STRETCH)
|
->setResizeStrategy(CImageResizer::STRETCH)
|
||||||
->calculateTargetWidthAndHeight();
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
$this->assertEquals($twa, $img->getTargetWidth(), "Target width not correct.");
|
$this->assertEquals($tw, $img->getTargetWidth(), "Target width not correct.");
|
||||||
$this->assertEquals($tha, $img->getTargetHeight(), "Target height not correct.");
|
$this->assertEquals($th, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
$this->assertEquals($cx, $img->getCropX(), "CropX not correct.");
|
|
||||||
$this->assertEquals($cy, $img->getCropY(), "CropY not correct.");
|
|
||||||
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
|
||||||
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,97 +8,13 @@ function logger($str)
|
|||||||
echo "$str\n";
|
echo "$str\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loggerDummy($str)
|
||||||
|
{
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
class CImageResizerTest extends \PHPUnit_Framework_TestCase
|
class CImageResizerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Provider
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function providerImages()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
|
|
||||||
// $strategy
|
|
||||||
// $srcWidth, $srcHeight, $targetWidth, $targetHeight,
|
|
||||||
// $aspectRatio, $dpr,
|
|
||||||
// $expectedWidth, $expectedHeight,
|
|
||||||
// $expectedWidth2, $expectedHeight2
|
|
||||||
|
|
||||||
// Same as source, does not set target
|
|
||||||
|
|
||||||
// ===== Keep aspect ratio
|
|
||||||
/*
|
|
||||||
array(1, 100, 100, null, null, null, 1, null, null, 100, 100),
|
|
||||||
array(1, 100, 150, null, null, null, 1, null, null, 100, 150),
|
|
||||||
array(1, 150, 100, null, null, null, 1, null, null, 150, 100),
|
|
||||||
|
|
||||||
// Width & Height as %
|
|
||||||
array(1, 100, 100, '200%', null, null, 1, 200, null, 200, 200),
|
|
||||||
array(1, 100, 100, null, '50%', null, 1, null, 50, 50, 50),
|
|
||||||
|
|
||||||
// dpr
|
|
||||||
//array(1, 100, 100, null, null, null, 2, null, null, 100, 100), // do dpr?
|
|
||||||
/*
|
|
||||||
array(1, 100, 100, 100, null, null, 2, 200, null, 200, 200),
|
|
||||||
array(1, 100, 100, null, 100, null, 2, null, 200, 200, 200),
|
|
||||||
array(1, 100, 100, 100, 100, null, 2, 200, 200, 200, 200),
|
|
||||||
*/
|
|
||||||
|
|
||||||
// ===== Need crop to fit or fill to fit
|
|
||||||
// Aspect ratio
|
|
||||||
/*
|
|
||||||
array(2, 100, 100, null, null, 2, 1, 100, 50, 100, 50),
|
|
||||||
array(2, 100, 200, null, null, 4, 1, 100, 25, 100, 25),
|
|
||||||
array(2, 200, 100, null, null, 4, 1, 200, 50, 200, 50),
|
|
||||||
|
|
||||||
// Aspect ratio inverted
|
|
||||||
array(2, 100, 100, null, null, 1/2, 1, 50, 100, 50, 100),
|
|
||||||
array(2, 100, 200, null, null, 1/4, 1, 50, 200, 50, 200),
|
|
||||||
array(2, 200, 100, null, null, 1/4, 1, 25, 100, 25, 100),
|
|
||||||
|
|
||||||
// Aspect ratio & width
|
|
||||||
array(2, 100, 100, 200, null, 2, 1, 200, 100, 200, 100),
|
|
||||||
|
|
||||||
// Aspect ratio & height
|
|
||||||
array(2, 100, 100, null, 200, 1/2, 1, 100, 200, 100, 200),
|
|
||||||
*/
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test
|
|
||||||
*
|
|
||||||
* @dataProvider providerImages
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
public function testResize1($strategy, $srcWidth, $srcHeight, $targetWidth, $targetHeight, $aspectRatio, $dpr, $expectedWidth, $expectedHeight, $expectedWidth2, $expectedHeight2)
|
|
||||||
{
|
|
||||||
$img = new CImageResizer(/*'logger'*/ /*);
|
|
||||||
//$img = new CImageResizer('logger');
|
|
||||||
|
|
||||||
$img->setSource($srcWidth, $srcHeight)
|
|
||||||
->setResizeStrategy($strategy)
|
|
||||||
->setBaseWidthHeight($targetWidth, $targetHeight)
|
|
||||||
->setBaseAspecRatio($aspectRatio)
|
|
||||||
->setBaseDevicePixelRate($dpr)
|
|
||||||
->prepareTargetDimensions();
|
|
||||||
|
|
||||||
$this->assertEquals($expectedWidth, $img->getTargetWidth(), "Width not correct.");
|
|
||||||
$this->assertEquals($expectedHeight, $img->getTargetHeight(), "Height not correct.");
|
|
||||||
|
|
||||||
$img->calculateTargetWidthAndHeight();
|
|
||||||
$this->assertEquals($expectedWidth2, $img->getTargetWidth(), "Width not correct.");
|
|
||||||
$this->assertEquals($expectedHeight2, $img->getTargetHeight(), "Height not correct.");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider
|
* Provider
|
||||||
*
|
*
|
||||||
@@ -136,6 +52,21 @@ class CImageResizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testLogger()
|
||||||
|
{
|
||||||
|
$img = new CImageResizer('loggerDummy');
|
||||||
|
|
||||||
|
$img->setBaseWidthHeight(100, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider
|
* Provider
|
||||||
*
|
*
|
||||||
@@ -147,6 +78,7 @@ class CImageResizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
array(CImageResizer::KEEP_RATIO, "KEEP_RATIO"),
|
array(CImageResizer::KEEP_RATIO, "KEEP_RATIO"),
|
||||||
array(CImageResizer::CROP_TO_FIT, "CROP_TO_FIT"),
|
array(CImageResizer::CROP_TO_FIT, "CROP_TO_FIT"),
|
||||||
array(CImageResizer::FILL_TO_FIT, "FILL_TO_FIT"),
|
array(CImageResizer::FILL_TO_FIT, "FILL_TO_FIT"),
|
||||||
|
array(CImageResizer::STRETCH, "STRETCH"),
|
||||||
array(-1, "UNKNOWN"),
|
array(-1, "UNKNOWN"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -169,4 +101,104 @@ class CImageResizerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals($str, $res, "Strategy not matching.");
|
$this->assertEquals($str, $res, "Strategy not matching.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerPercent()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(100, 100, "100%", "100%", 100, 100),
|
||||||
|
array(100, 100, "50%", "50%", 50, 50),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerPercent
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testPercent($sw, $sh, $tw, $th, $w, $h)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'*/);
|
||||||
|
|
||||||
|
$img->setSource($sw, $sh)
|
||||||
|
->setBaseWidthHeight($tw, $th);
|
||||||
|
|
||||||
|
$this->assertEquals($w, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($h, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetSource()
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'*/);
|
||||||
|
|
||||||
|
$w = 100;
|
||||||
|
$h = 100;
|
||||||
|
|
||||||
|
$img->setSource($w, $h);
|
||||||
|
|
||||||
|
$this->assertEquals($w, $img->getSourceWidth(), "Source width not correct.");
|
||||||
|
$this->assertEquals($h, $img->getSourceHeight(), "Source height not correct.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function providerImages()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
|
||||||
|
// car.png
|
||||||
|
[CImageResizer::KEEP_RATIO, 491, 324, 500, 200, 303, 200, 0, 0, 491, 324],
|
||||||
|
[CImageResizer::KEEP_RATIO, 491, 324, 500, 500, 500, 330, 0, 0, 491, 324],
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test
|
||||||
|
*
|
||||||
|
* @dataProvider providerImages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testResize($strat, $sw, $sh, $tw, $th, $twa, $tha, $cx, $cy, $cw, $ch)
|
||||||
|
{
|
||||||
|
$img = new CImageResizer(/*'logger'/**/);
|
||||||
|
|
||||||
|
$img->setSource($sw, $sh)
|
||||||
|
->setBaseWidthHeight($tw, $th)
|
||||||
|
->setResizeStrategy($strat)
|
||||||
|
->calculateTargetWidthAndHeight();
|
||||||
|
|
||||||
|
$this->assertEquals($twa, $img->getTargetWidth(), "Target width not correct.");
|
||||||
|
$this->assertEquals($tha, $img->getTargetHeight(), "Target height not correct.");
|
||||||
|
|
||||||
|
$this->assertEquals($cx, $img->getCropX(), "CropX not correct.");
|
||||||
|
$this->assertEquals($cy, $img->getCropY(), "CropY not correct.");
|
||||||
|
$this->assertEquals($cw, $img->getCropWidth(), "CropWidth not correct.");
|
||||||
|
$this->assertEquals($ch, $img->getCropHeight(), "CropHeight not correct.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$version = "v0.7.7* (2015-10-24)";
|
$version = "v0.8.0dev (2015-12-05)";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -315,12 +315,9 @@ verbose("referer host = $refererHost");
|
|||||||
* Get the source files.
|
* Get the source files.
|
||||||
*/
|
*/
|
||||||
$autoloader = getConfig('autoloader', false);
|
$autoloader = getConfig('autoloader', false);
|
||||||
$cimageClass = getConfig('cimage_class', false);
|
|
||||||
|
|
||||||
if ($autoloader) {
|
if ($autoloader) {
|
||||||
require $autoloader;
|
require $autoloader;
|
||||||
} elseif ($cimageClass) {
|
|
||||||
require $cimageClass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -14,6 +14,7 @@ return array(
|
|||||||
* mode: 'production'
|
* mode: 'production'
|
||||||
*/
|
*/
|
||||||
//'mode' => 'production', // 'development', 'strict'
|
//'mode' => 'production', // 'development', 'strict'
|
||||||
|
'mode' => 'development', // 'development', 'strict'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -21,11 +22,9 @@ return array(
|
|||||||
* Where are the sources for the classfiles.
|
* Where are the sources for the classfiles.
|
||||||
*
|
*
|
||||||
* Default values:
|
* Default values:
|
||||||
* autoloader: null // used from v0.6.2
|
* autoloader: null
|
||||||
* cimage_class: null // used until v0.6.1
|
|
||||||
*/
|
*/
|
||||||
'autoloader' => __DIR__ . '/../autoload.php',
|
'autoloader' => __DIR__ . '/../autoload.php',
|
||||||
//'cimage_class' => __DIR__ . '/../CImage.php',
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -75,7 +75,7 @@ window.CImage = (function() {
|
|||||||
area.classList.remove("hidden");
|
area.classList.remove("hidden");
|
||||||
|
|
||||||
$.getJSON(this.value + "&json", function(data) {
|
$.getJSON(this.value + "&json", function(data) {
|
||||||
json.innerHTML = "filename: " + data.filename + "\ncolors: " + data.colors + "\nsize: " + data.size + "\nwidth: " + data.width + "\nheigh: " + data.height + "\naspect-ratio: " + data.aspectRatio + "\npng-type: " + data.pngType;
|
json.innerHTML = "filename: " + data.filename + "\ncolors: " + data.colors + "\nsize: " + data.size + "\nwidth: " + data.width + "\nheight: " + data.height + "\naspect-ratio: " + data.aspectRatio + "\npng-type: " + data.pngType;
|
||||||
})
|
})
|
||||||
.fail(function() {
|
.fail(function() {
|
||||||
json.innerHTML = "Details not available."
|
json.innerHTML = "Details not available."
|
||||||
|
@@ -22,7 +22,8 @@ $images = array(
|
|||||||
|
|
||||||
|
|
||||||
// For each image, apply these testcases
|
// For each image, apply these testcases
|
||||||
$nc = null; //"&nc"; //null; //&nc';
|
$nc = empty($_SERVER['QUERY_STRING']) ? "" : "&" . $_SERVER['QUERY_STRING'];
|
||||||
|
|
||||||
$testcase = array(
|
$testcase = array(
|
||||||
$nc . '&w=600',
|
$nc . '&w=600',
|
||||||
$nc . '&w=600&no-upscale',
|
$nc . '&w=600&no-upscale',
|
||||||
@@ -42,8 +43,8 @@ $testcase = array(
|
|||||||
$nc . '&w=600&h=200&no-upscale&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&crop-to-fit',
|
||||||
$nc . '&w=300&h=400&no-upscale&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=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=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',
|
43
webroot/test/resize-landscape.php
Normal file
43
webroot/test/resize-landscape.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
// Include config for all testcases
|
||||||
|
include __DIR__ . "/config.php";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// The title of the test case
|
||||||
|
$title = "Testing resize landscape image";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Provide a short description of the testcase.
|
||||||
|
$description = "Resize landscape image";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Use these images in the test
|
||||||
|
$images = array(
|
||||||
|
'car.png',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// For each image, apply these testcases
|
||||||
|
$nc = empty($_SERVER['QUERY_STRING']) ? "" : "&" . $_SERVER['QUERY_STRING'];
|
||||||
|
|
||||||
|
$testcase = array(
|
||||||
|
$nc . '&w=500',
|
||||||
|
$nc . '&h=200',
|
||||||
|
$nc . '&w=500&h=500',
|
||||||
|
$nc . '&w=500&h=200',
|
||||||
|
$nc . '&w=500&h=200&crop-to-fit',
|
||||||
|
$nc . '&w=200&h=500&crop-to-fit',
|
||||||
|
$nc . '&w=500&h=200&fill-to-fit',
|
||||||
|
$nc . '&w=200&h=500&fill-to-fit',
|
||||||
|
$nc . '&w=500&h=200&stretch',
|
||||||
|
$nc . '&w=200&h=500&stretch',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Apply testcases and present results
|
||||||
|
include __DIR__ . "/template.php";
|
43
webroot/test/resize-portrait.php
Normal file
43
webroot/test/resize-portrait.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
// Include config for all testcases
|
||||||
|
include __DIR__ . "/config.php";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// The title of the test case
|
||||||
|
$title = "Testing resize portrait image";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Provide a short description of the testcase.
|
||||||
|
$description = "Resize portrait image";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Use these images in the test
|
||||||
|
$images = array(
|
||||||
|
'kodim04.png',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// For each image, apply these testcases
|
||||||
|
$nc = empty($_SERVER['QUERY_STRING']) ? "" : "&" . $_SERVER['QUERY_STRING'];
|
||||||
|
|
||||||
|
$testcase = array(
|
||||||
|
$nc . '&w=500',
|
||||||
|
$nc . '&h=200',
|
||||||
|
$nc . '&w=500&h=500',
|
||||||
|
$nc . '&w=500&h=200',
|
||||||
|
$nc . '&w=500&h=200&crop-to-fit',
|
||||||
|
$nc . '&w=200&h=500&crop-to-fit',
|
||||||
|
$nc . '&w=500&h=200&fill-to-fit',
|
||||||
|
$nc . '&w=200&h=500&fill-to-fit',
|
||||||
|
$nc . '&w=500&h=200&stretch',
|
||||||
|
$nc . '&w=200&h=500&stretch',
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Apply testcases and present results
|
||||||
|
include __DIR__ . "/template.php";
|
Reference in New Issue
Block a user