diff --git a/CImage.php b/CImage.php index d641411..ccb286f 100644 --- a/CImage.php +++ b/CImage.php @@ -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) diff --git a/README.md b/README.md index 4db93ee..5379779 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,7 @@ Revision history v0.5.x (latest) +* Adding option `ppi` 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. * Adding utility `cache.bash` to ease gathering stats on cache usage. #21 * Cache-directory can now be readonly and serve all cached files, still failing when need to save files. #5 * Cache now uses same file extension as original image #37. diff --git a/webroot/img.php b/webroot/img.php index ca5700b..2763eaf 100644 --- a/webroot/img.php +++ b/webroot/img.php @@ -463,6 +463,15 @@ verbose("json = $outputFormat"); +/** + * ppi - change to get larger image to easier support larger ppi, such as retina. + */ +$ppi = get('ppi', 1); + +verbose("ppi = $ppi"); + + + /** * Display image if verbose mode */ @@ -522,6 +531,7 @@ $img->setVerbose($verbose) // Output format 'outputFormat' => $outputFormat, + 'ppi' => $ppi, ) ) ->loadImageDetails()