From d39c95a8ac28e66bdf53245ab1165813ebf57544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaussoin=20Timoth=C3=A9e?= Date: Mon, 20 Jan 2014 16:29:18 +0100 Subject: [PATCH] - Clean some stuff for the new Picture class --- app/models/contact/Contact.php | 2 +- app/widgets/Avatar/Avatar.php | 2 +- system/Picture.php | 32 ++++++++++++++++++++++---------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/models/contact/Contact.php b/app/models/contact/Contact.php index 49eb682cf..bb61c285f 100644 --- a/app/models/contact/Contact.php +++ b/app/models/contact/Contact.php @@ -172,7 +172,7 @@ class Contact extends ModlModel { public function createThumbnails() { $p = new \Picture; - $p->fromBase64($this->photobin); + //$p->fromBase($this->photobin); $p->set($this->jid); if(isset($this->email)) diff --git a/app/widgets/Avatar/Avatar.php b/app/widgets/Avatar/Avatar.php index 1b0f46c83..2be93d208 100644 --- a/app/widgets/Avatar/Avatar.php +++ b/app/widgets/Avatar/Avatar.php @@ -54,7 +54,7 @@ class Avatar extends WidgetBase $p = new Picture; $p->get($this->user->getLogin()); - $avatarform->assign('photobin', $p->toBase64()); + $avatarform->assign('photobin', $p->toBase()); $avatarform->assign('me', $me); $avatarform->assign( diff --git a/system/Picture.php b/system/Picture.php index 8a53af3af..743b64f8b 100644 --- a/system/Picture.php +++ b/system/Picture.php @@ -4,7 +4,7 @@ class Picture { private $_path = CACHE_PATH; private $_uri = CACHE_URI; private $_key; - private $_bin; + private $_bin = false; /** * @desc Load a bin picture from a path @@ -18,15 +18,19 @@ class Picture { /** * @desc Load a bin picture from a base64 */ - public function fromBase64($base) { - $this->_bin = base64_decode($base); + public function fromBase($base) { + //if(isset($base)) + // $this->_bin = (string)base64_decode((string)$base); } /** * @desc Convert to a base64 */ - public function toBase64() { - return base64_encode($this->_bin); + public function toBase() { + if($this->_bin) + return base64_encode($this->_bin); + else + return false; } /** @@ -70,16 +74,24 @@ class Picture { * @desc Save a picture (original size) * @param $key The key of the picture */ - public function set($key) { + public function set($key, $base = false) { $this->_key = $key; $path = $this->_path.md5($this->_key).'.jpg'; if(file_exists($path)) unlink($path); - - $source = imagecreatefromstring($this->_bin); - imagejpeg($source, $path, 95); - imagedestroy($source); + + + if($base != false) + $data = base64_decode($base); + else + $data = $this->_bin; + + if($data) { + $source = imagecreatefromstring($data); + imagejpeg($source, $path, 95); + imagedestroy($source); + } } /**