Browse Source

- Clean some stuff for the new Picture class

pull/16/head
Jaussoin Timothée 12 years ago
parent
commit
d39c95a8ac
  1. 2
      app/models/contact/Contact.php
  2. 2
      app/widgets/Avatar/Avatar.php
  3. 32
      system/Picture.php

2
app/models/contact/Contact.php

@ -172,7 +172,7 @@ class Contact extends ModlModel {
public function createThumbnails() { public function createThumbnails() {
$p = new \Picture; $p = new \Picture;
$p->fromBase64($this->photobin);
//$p->fromBase($this->photobin);
$p->set($this->jid); $p->set($this->jid);
if(isset($this->email)) if(isset($this->email))

2
app/widgets/Avatar/Avatar.php

@ -54,7 +54,7 @@ class Avatar extends WidgetBase
$p = new Picture; $p = new Picture;
$p->get($this->user->getLogin()); $p->get($this->user->getLogin());
$avatarform->assign('photobin', $p->toBase64());
$avatarform->assign('photobin', $p->toBase());
$avatarform->assign('me', $me); $avatarform->assign('me', $me);
$avatarform->assign( $avatarform->assign(

32
system/Picture.php

@ -4,7 +4,7 @@ class Picture {
private $_path = CACHE_PATH; private $_path = CACHE_PATH;
private $_uri = CACHE_URI; private $_uri = CACHE_URI;
private $_key; private $_key;
private $_bin;
private $_bin = false;
/** /**
* @desc Load a bin picture from a path * @desc Load a bin picture from a path
@ -18,15 +18,19 @@ class Picture {
/** /**
* @desc Load a bin picture from a base64 * @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 * @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) * @desc Save a picture (original size)
* @param $key The key of the picture * @param $key The key of the picture
*/ */
public function set($key) {
public function set($key, $base = false) {
$this->_key = $key; $this->_key = $key;
$path = $this->_path.md5($this->_key).'.jpg'; $path = $this->_path.md5($this->_key).'.jpg';
if(file_exists($path)) if(file_exists($path))
unlink($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);
}
} }
/** /**

Loading…
Cancel
Save