From a06afb19cdaf0b971c9f56e6b39d90b6e3f2bee3 Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 31 Dec 2021 06:08:27 +0200 Subject: [PATCH] implement avatar image cache --- src/application/controller/api/image.php | 16 ++++++++++++++-- src/cache/image/index.html | 0 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 src/cache/image/index.html diff --git a/src/application/controller/api/image.php b/src/application/controller/api/image.php index d0a4587..22b71dd 100755 --- a/src/application/controller/api/image.php +++ b/src/application/controller/api/image.php @@ -2,8 +2,20 @@ if (isset($_GET['hash'])) { - $icon = new Icon(); + $filename = md5($_GET['hash']); + $filepath = PROJECT_DIR . '/cache/image/' . $filename . '.jpeg'; + + if (!file_exists($filepath)) { + + $icon = new Icon(); + $image = $icon->generateImageResource($filename, 42, 42, false); + + file_put_contents($filepath, $image); + } + + $image = file_get_contents($filepath); header("Content-Type: image/jpeg"); - echo $icon->generateImageResource(md5($_GET['hash']), 42, 42, false); + + echo $image; } diff --git a/src/cache/image/index.html b/src/cache/image/index.html new file mode 100644 index 0000000..e69de29