From 05c11ca9fca14782fcbe51f139c9281d7ed3cc4e Mon Sep 17 00:00:00 2001 From: Mikael Roos Date: Mon, 7 Dec 2015 16:01:47 +0100 Subject: [PATCH] refixing new cache management for remote images --- CImage.php | 39 +++++++++++++++++++++++---------------- CRemoteImage.php | 2 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CImage.php b/CImage.php index 88a7c3f..604bc76 100644 --- a/CImage.php +++ b/CImage.php @@ -208,8 +208,8 @@ class CImage /** * Path to command to optimize jpeg images, for example jpegtran or null. */ - private $jpegOptimize; - private $jpegOptimizeCmd; + private $jpegOptimize; + private $jpegOptimizeCmd; @@ -344,20 +344,27 @@ class CImage /** - * Calculate target dimension for image when using fill-to-fit resize strategy. - */ + * Calculate target dimension for image when using fill-to-fit resize strategy. + */ private $fillWidth; private $fillHeight; /** - * Allow remote file download, default is to disallow remote file download. - */ + * Allow remote file download, default is to disallow remote file download. + */ private $allowRemote = false; + /** + * Path to cache for remote download. + */ + private $remoteCache; + + + /** * Pattern to recognize a remote file. */ @@ -400,7 +407,7 @@ class CImage */ const RESIZE = 1; const RESAMPLE = 2; - private $copyStrategy = null; + private $copyStrategy = NULL; @@ -631,7 +638,7 @@ class CImage if ($extension == 'jpeg') { $extension = 'jpg'; - } + } return $extension; } @@ -1619,11 +1626,11 @@ class CImage * * @return $this */ - public function setCopyResizeStrategy($strategy) - { - $this->copyStrategy = $strategy; - return $this; - } + public function setCopyResizeStrategy($strategy) + { + $this->copyStrategy = $strategy; + return $this; + } @@ -1634,7 +1641,7 @@ class CImage */ public function imageCopyResampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) { - if ($this->copyStrategy == self::RESIZE) { + if($this->copyStrategy == self::RESIZE) { $this->log("Copy by resize"); imagecopyresized($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); } else { @@ -2312,7 +2319,7 @@ class CImage $type = $this->getTargetImageExtension(); $this->Log("Saving image as " . $type); - switch ($type) { + switch($type) { case 'jpeg': case 'jpg': @@ -2549,7 +2556,7 @@ class CImage header('Last-Modified: ' . $gmdate . " GMT"); } - foreach ($this->HTTPHeader as $key => $val) { + foreach($this->HTTPHeader as $key => $val) { header("$key: $val"); } diff --git a/CRemoteImage.php b/CRemoteImage.php index 4eb418e..ec070fb 100644 --- a/CRemoteImage.php +++ b/CRemoteImage.php @@ -101,7 +101,7 @@ class CRemoteImage */ public function setCache($path) { - $this->saveFolder = $path; + $this->saveFolder = rtrim($path, "/") . "/"; return $this; }