Skip to content

Instantly share code, notes, and snippets.

@melloc01
Created February 27, 2015 17:34
Show Gist options
  • Save melloc01/c6316fe03956f1984014 to your computer and use it in GitHub Desktop.
Save melloc01/c6316fe03956f1984014 to your computer and use it in GitHub Desktop.
/**
* Setter for text
*
* @param mixed $text Value to set
*
* @return self
*/
public function setText($text)
{
$upload_path = '../public/modules/blog/posts/img/';
$usr_upload_path = '/modules/blog/posts/img/';
$aux = explode('"data:image/png;base64,', $text);
$size = sizeof($aux);
$post = [];
$post = $aux[0];
for ($i=1; $i < $size; $i++) {
$aux_1 = explode('"', $aux[$i]);
//aux_1 é a string base64
$upload_name = md5( mt_rand().mt_rand().mt_rand().'post').'.png';
$file_location = $upload_path.$upload_name;
$usr_file_location = $usr_upload_path.$upload_name;
$base64_code = array_shift($aux_1);
$post.= '"'.$usr_file_location.'"';
if ($aux_1)
foreach ($aux_1 as $key => $text_piece)
$post .= $text_piece;
$this->base64_to_jpeg($base64_code,$file_location);
}
$this->text = $post;
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment