summaryrefslogtreecommitdiffstats
path: root/app/class/obj.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/class/obj.class.php')
-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;
}
}