From b8f7b557d94395ad670284e130d008fa0b453345 Mon Sep 17 00:00:00 2001 From: Tam Date: Tue, 28 Apr 2020 13:51:06 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c277e2..9e11897 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ Will disable the automatic injection of the lazy loading JavaScript. Will convert the lazy loading to eager loading when true, meaning the image will instantly load in most cases. -**`title`** [bool] +**`title`** [string] The title that will be output in the image tag. From 39f013dbeda44b65cd14d808f7f4005c1ee9e781 Mon Sep 17 00:00:00 2001 From: Tam Date: Tue, 28 Apr 2020 14:09:09 +0100 Subject: [PATCH 2/2] Cache dimensions of remote image --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/RemoteAsset.php | 12 +++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 375f4b6..f650f54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.7 - 2020-04-28 +### Improved +- Remote assets will now cache their calculated dimensions + ## 1.0.6 - 2020-04-28 ### Added - Add `title` option to picture helper diff --git a/composer.json b/composer.json index 4199e3c..8d6e849 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ether/thumbro", "description": "Craft CMS image transformations powered by Thumbor", - "version": "1.0.6", + "version": "1.0.7", "type": "craft-plugin", "license": "proprietary", "minimum-stability": "dev", diff --git a/src/RemoteAsset.php b/src/RemoteAsset.php index f2d3c30..4434be3 100644 --- a/src/RemoteAsset.php +++ b/src/RemoteAsset.php @@ -8,6 +8,8 @@ namespace ether\thumbro; +use Craft; + /** * Class RemoteAsset * @@ -26,9 +28,17 @@ class RemoteAsset public function __construct ($url, $title = '') { + $cache = Craft::$app->getCache(); + $key = 'thumbro_size_cache_' . urlencode($url); + $this->url = $url; $this->title = $title; - $size = getimagesize($url); + if ($cache->exists($key)) { + $size = $cache->get($key); + } else { + $size = getimagesize($url); + $cache->set($key, $size); + } $this->width = $size[0]; $this->height = $size[1]; $this->extension = [