From 7d90a9ac3bd5d0605ab398d2b564a83cc946a56f Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Wed, 20 Mar 2019 20:05:52 -0400 Subject: Tweak setting modal image columns The target display size of these columns is changed to 'xs' so they don't wrap when viewed on smaller displays. Signed-off-by: Malf Furious --- app/view/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/view/settings.php b/app/view/settings.php index 21b75ba..a5dc9d8 100644 --- a/app/view/settings.php +++ b/app/view/settings.php @@ -78,7 +78,7 @@ require_once "class/user.class.php"; -
+
hasHeadImg() ? "disabled" : ""); ?> -- cgit v1.2.3 From e8fed693e9568e2e71d6a9de61309cd9b895b602 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 21 Mar 2019 22:09:01 -0400 Subject: Update bg image functions to implement an image thumbnail When setting the bg image for an object, create a copy of it (square-cropped) in dynmic/thumbs/ for display in the settings modal. This patch provides an additional function for retriving the thumbnail's URL as well. This thumbnail is desirable for the sake of the UI. If we cannot make a guarantee as to the aspect ratio of the preview images shown on the user tab of the settings modal, these widgets may appear wrong or go off the screen a bit on smaller devices. Signed-off-by: Malf Furious --- app/class/obj.class.php | 57 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/app/class/obj.class.php b/app/class/obj.class.php index 353d617..9d3ac9a 100644 --- a/app/class/obj.class.php +++ b/app/class/obj.class.php @@ -277,26 +277,63 @@ class obj extends table } /* - * Set the background image for this object, overwriting any - * existing image. $image should be the name of the file - * formctrl field. + * Get the URL to the background image thumbnail resource for + * this object. If no image is set, NULL is returned. + */ + public function getThumbImg() : ?string + { + if (!is_file("dynmic/thumbs/" . $this->guid)) + return NULL; + + return ar() . "/df.php?d=thumbs&f=" . $this->guid; + } + + /* + * Set the background image and its thumbnail for this object, + * overwriting any existing images. $image should be the name + * of the file formctrl field. */ public function setBgImg(string $image) : bool { - $path = "dynmic/bgs/" . $this->guid; - return saveIfFile($image, $path, self::BG_MAXSIZE, self::IMAGE_MIME); + /* bgs image */ + $bgs = "dynmic/bgs/" . $this->guid; + if (!saveIfFile($image, $bgs, self::BG_MAXSIZE, self::IMAGE_MIME)) + goto fail; + + /* thumbs image */ + $thumbs = "dynmic/thumbs/" . $this->guid; + if (!copy($bgs, $thumbs)) + goto fail; + + if (!imageSquareCrop($thumbs)) + goto fail; + + return true; + +fail: + $this->rmBgImg(); + return false; } /* - * Remove the background image for this object. This deletes - * the image on disk. + * Remove the background image and thumbnail for this object. + * This deletes the images on disk. */ public function rmBgImg() : bool { - if (!is_file("dynmic/bgs/" . $this->guid)) - return true; + $ret = true; + + /* bgs */ + $bgs = "dynmic/bgs/" . $this->guid; + if (is_file($bgs) && !unlink($bgs)) + $ret = false; - return unlink("dynmic/bgs/" . $this->guid); + /* thumbs */ + $thumbs = "dynmic/thumbs/" . $this->guid; + if (is_file($thumbs) && !unlink($thumbs)) + $ret = false; + + return $ret; } } -- cgit v1.2.3 From 080611eb878166b93b9ac334a17826fca44ffdf9 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 21 Mar 2019 22:48:20 -0400 Subject: Update df.php to serve thumbnails df.php will now serve bg image thumbnails when d=thumbs. Normal access requirements stand. Signed-off-by: Malf Furious --- app/df.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/df.php b/app/df.php index 97cd055..80aec5a 100644 --- a/app/df.php +++ b/app/df.php @@ -96,6 +96,10 @@ function main(string $dir, string $guid) : void serveResource("dynmic/bgs/" . $guid); break; + case "thumbs": + serveResource("dynmic/thumbs/" . $guid); + break; + case "attach": $mesg = new mesg($guid); serveResource("dynmic/attach/" . $guid, $mesg->attachment); -- cgit v1.2.3 From 9f890de0a50e68c7c912d1346478380f7cb109ac Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 21 Mar 2019 22:52:23 -0400 Subject: Show thumbnail for object bg preview ... instead of the fullsized image. This guarantees a square aspect ratio, which is nice for the user interface. Signed-off-by: Malf Furious --- app/model/objBgPrev.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/model/objBgPrev.php b/app/model/objBgPrev.php index f8d024a..418ad57 100644 --- a/app/model/objBgPrev.php +++ b/app/model/objBgPrev.php @@ -20,7 +20,7 @@ require_once "class/obj.class.php"; * int $height */ -$src = $obj->getBgImg(); +$src = $obj->getThumbImg(); if ($src == NULL) $src = ar() . "/static/img/null.jpg"; -- cgit v1.2.3 From 0ef6ebdc441d0e840ea5002100c1d98339d2d840 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 21 Mar 2019 23:22:24 -0400 Subject: Track thumbs dynmic directory Signed-off-by: Malf Furious --- app/dynmic/thumbs/.gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 app/dynmic/thumbs/.gitignore diff --git a/app/dynmic/thumbs/.gitignore b/app/dynmic/thumbs/.gitignore new file mode 100644 index 0000000..e38384e --- /dev/null +++ b/app/dynmic/thumbs/.gitignore @@ -0,0 +1,3 @@ +# Track empty directory +* +!.gitignore -- cgit v1.2.3 From 098720c46e351ab41295ad451b8d70e7f794ee4d Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Thu, 21 Mar 2019 23:50:40 -0400 Subject: Don't remove bg image if it fails to set This behavior was causing issues in the UI. We normally "try" to set a new asset by default, in case one was provided by the user, and just soft-fail if one wasn't. This "soft-failing" is now resulting in the images being removed if the user just goes in to change his alias (for example). Signed-off-by: Malf Furious --- app/class/obj.class.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/class/obj.class.php b/app/class/obj.class.php index 9d3ac9a..bd546b2 100644 --- a/app/class/obj.class.php +++ b/app/class/obj.class.php @@ -298,21 +298,17 @@ class obj extends table /* bgs image */ $bgs = "dynmic/bgs/" . $this->guid; if (!saveIfFile($image, $bgs, self::BG_MAXSIZE, self::IMAGE_MIME)) - goto fail; + return false; /* thumbs image */ $thumbs = "dynmic/thumbs/" . $this->guid; if (!copy($bgs, $thumbs)) - goto fail; + return false; if (!imageSquareCrop($thumbs)) - goto fail; + return false; return true; - -fail: - $this->rmBgImg(); - return false; } /* -- cgit v1.2.3