summaryrefslogtreecommitdiffstats
path: root/app/class/object.class.php
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-04-19 02:32:38 -0400
committerMalf Furious <m@lfurio.us>2017-04-19 02:32:38 -0400
commita6a828521c61ebed3ec7038b2a53c002312a8bd0 (patch)
tree2cb31c3e1f62b0623644cc4f7d36e1e2b6db97cb /app/class/object.class.php
parent065c8bbb637954c47259e312ef87667e8d281497 (diff)
downloadscrott-a6a828521c61ebed3ec7038b2a53c002312a8bd0.tar.gz
scrott-a6a828521c61ebed3ec7038b2a53c002312a8bd0.zip
Add object function setHeadImg()
Diffstat (limited to 'app/class/object.class.php')
-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;
+ }
}
?>