summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2019-03-22 00:02:32 -0400
committerMalf Furious <m@lfurio.us>2019-03-22 00:02:32 -0400
commit6e11d642995e2b2644464ef0bb21528e5e0c2456 (patch)
treefaef4fc40be9d49a0445cef6e194dc9e4043ffd4
parent5b67e8791194bf9b6fb6e1d607a0cd1770ff1b93 (diff)
parent098720c46e351ab41295ad451b8d70e7f794ee4d (diff)
downloadscrott-6e11d642995e2b2644464ef0bb21528e5e0c2456.tar.gz
scrott-6e11d642995e2b2644464ef0bb21528e5e0c2456.zip
Merge branch 'bg-thumbnail'
-rw-r--r--app/class/obj.class.php53
-rw-r--r--app/df.php4
-rw-r--r--app/dynmic/thumbs/.gitignore3
-rw-r--r--app/model/objBgPrev.php2
-rw-r--r--app/view/settings.php2
5 files changed, 52 insertions, 12 deletions
diff --git a/app/class/obj.class.php b/app/class/obj.class.php
index 353d617..bd546b2 100644
--- a/app/class/obj.class.php
+++ b/app/class/obj.class.php
@@ -277,26 +277,59 @@ 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))
+ return false;
+
+ /* thumbs image */
+ $thumbs = "dynmic/thumbs/" . $this->guid;
+ if (!copy($bgs, $thumbs))
+ return false;
+
+ if (!imageSquareCrop($thumbs))
+ return false;
+
+ return true;
}
/*
- * 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;
}
}
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);
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
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";
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";
<?php } ?>
<?php function image(\obj $obj, string $type, string $label) : void { ?>
- <div class="col-md-6 text-center">
+ <div class="col-xs-6 text-center">
<?php if ($type == "head") { ?>
<?=\datalsts\objHeadCircle($obj, 100)?>
<?php $d = (!$obj->hasHeadImg() ? "disabled" : ""); ?>