summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2019-03-21 22:09:01 -0400
committerMalf Furious <m@lfurio.us>2019-03-21 22:09:01 -0400
commite8fed693e9568e2e71d6a9de61309cd9b895b602 (patch)
treeb98265a7f86f4a32933cbf56e2b173df2194a5df /app
parent7d90a9ac3bd5d0605ab398d2b564a83cc946a56f (diff)
downloadscrott-e8fed693e9568e2e71d6a9de61309cd9b895b602.tar.gz
scrott-e8fed693e9568e2e71d6a9de61309cd9b895b602.zip
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 <m@lfurio.us>
Diffstat (limited to 'app')
-rw-r--r--app/class/obj.class.php57
1 files 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;
}
}