commit be6660d0a1b599883308f41757457c4d2bbd1ea0
parent 8732037ad511c6445b062e5d3f76208ab010cc36
Author: Felicitus <felicitus@felicitus.org>
Date: Tue, 24 Apr 2012 06:26:38 +0200
Return if the attachment is an image, preparation to solve issue #131
Diffstat:
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Part/PartAttachment.php b/src/backend/de/RaumZeitLabor/PartKeepr/Part/PartAttachment.php
@@ -76,7 +76,8 @@ class PartAttachment extends UploadedFile implements Serializable, Deserializabl
"mimetype" => $this->getMimetype(),
"extension" => $this->getExtension(),
"size" => $this->getSize(),
- "description" => $this->getDescription());
+ "description" => $this->getDescription(),
+ "image" => $this->isImage());
}
/**
@@ -98,4 +99,21 @@ class PartAttachment extends UploadedFile implements Serializable, Deserializabl
}
}
}
+
+ /**
+ * Returns if the attachment is an image or not.
+ *
+ * Ths method uses ImageMagick to find out if this is an image. Limitations apply; if ImageMagick doesn't support
+ * the image format, this method would return false, even if it is an image.
+ *
+ * @return True if the attachment is an image, false otherwise
+ */
+ public function isImage () {
+ try {
+ $im = new \Imagick($this->getFilename());
+ return true;
+ } catch (\ImagickException $e) {
+ return false;
+ }
+ }
}
\ No newline at end of file