1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-07-30 21:20:11 +02:00

Adding option which defaults to 1. Set to 2 to get a twice as large image. Useful for Retina displays. Basically a shortcut to enlarge the image. #25

This commit is contained in:
Mikael Roos
2014-11-21 23:44:19 +01:00
parent 1f5f8c02a4
commit 35dd5c9064
3 changed files with 30 additions and 0 deletions

View File

@@ -173,6 +173,12 @@ class CImage
private $newHeight;
private $newHeightOrig; // Save original value
/**
* Change target height & width when different ppi, ppi 2 means double image dimensions.
*/
private $ppi = 1;
/**
* Array with details on how to crop, incoming as argument and calculated.
@@ -353,6 +359,7 @@ class CImage
// Output format
'outputFormat' => null,
'ppi' => 1,
// Options for saving
//'quality' => null,
@@ -521,6 +528,18 @@ class CImage
$this->log("Setting new height based on aspect ratio to {$this->newHeight}");
}
// Change width & height based on ppi
if ($this->ppi != 1) {
if (!is_null($this->newWidth)) {
$this->newWidth = round($this->newWidth * $this->ppi);
$this->log("Setting new width based on ppi={$this->ppi} - w={$this->newWidth}");
}
if (!is_null($this->newHeight)) {
$this->newHeight = round($this->newHeight * $this->ppi);
$this->log("Setting new height based on ppi={$this->ppi} - h={$this->newHeight}");
}
}
// Check values to be within domain
is_null($this->newWidth)
or is_numeric($this->newWidth)