summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/class/object.class.php32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/class/object.class.php b/app/class/object.class.php
index 14ab891..0dacd87 100644
--- a/app/class/object.class.php
+++ b/app/class/object.class.php
@@ -13,6 +13,7 @@
*/
require_once "class/table.class.php";
+require_once "class/image.php";
/*
* This is a generic database object. This is a supertype of all Scrott
@@ -21,6 +22,16 @@ require_once "class/table.class.php";
class object extends table
{
/*
+ * Constants used for uploading images
+ */
+ public const HEAD_MAXSIZE = 1048576; // 1Mb
+ public const IMAGE_MIME = array(
+ "image/jpeg",
+ "image/jpg",
+ "image/png",
+ );
+
+ /*
* Constructor
*/
public function __construct(?string $guid = NULL)
@@ -149,6 +160,27 @@ class object extends table
database::query($query);
return true;
}
+
+ /*
+ * Set the head image for this object, overwriting any existing
+ * image. $image should be an uploaded file to PHP, still
+ * unhandled.
+ */
+ public function setHeadImg(array $image) : bool
+ {
+ $path = "dynmic/heads/" . $this->guid;
+
+ if (!saveFile($image, $path, self::HEAD_MAXSIZE, self::IMAGE_MIME))
+ return false;
+
+ if (!imageSquareCrop($path))
+ {
+ $this->rmHeadImg();
+ return false;
+ }
+
+ return true;
+ }
}
?>