From: Florent Bruneau Date: Sun, 14 Feb 2010 16:31:45 +0000 (+0100) Subject: Add PlImage, short wrapper to send images. X-Git-Tag: core/1.1.0~83 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=6f58e0613a47d9eeb5004c992e6c59b7cf9ec0ea;p=platal.git Add PlImage, short wrapper to send images. Signed-off-by: Florent Bruneau --- diff --git a/classes/plimage.php b/classes/plimage.php new file mode 100644 index 0000000..955df71 --- /dev/null +++ b/classes/plimage.php @@ -0,0 +1,93 @@ +mime); + if (empty($this->data)) { + readfile($this->file); + } else { + echo $this->data; + } + exit; + } + + public function path() + { + if (empty($this->data)) { + return $file; + } else { + $name = md5($this->data); + $GLOBALS['img' . $name] = $this->data; + return 'var://img' . $name; + } + } + + public function width() + { + return $this->x; + } + + public function height() + { + return $this->y; + } + + public function mimeType() + { + return $this->mime; + } + + public static function fromData($data, $mime, $x = null, $y = null) + { + $image = new PlImage(); + $image->data = $data; + $image->mime = $mime; + $image->x = $x; + $image->y = $y; + return $image; + } + + public static function fromFile($path, $mime, $x = null, $y = null) + { + $image = new PlImage(); + $image->file = $path; + $image->mime = $mime; + $image->x = $x; + $image->y = $y; + return $image; + } +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?>