https://github.com/renyanwei/.
$types = empty ($types)? Array ('jpg',' gif', 'png',' jpeg'): $types;
$img = str_replace(array('_','-'), array('/','+'), $request->input('image'));
$b64img = substr($img, 0,100);
if(preg_match('/^(data:\s*image\/(\w+);base64,)/', $b64img, $matches)){
$type = $matches[2];
if(!in_array($type, $types)){
return array('type'=>'0','msg'=>'','url'=>'');
}
$img = str_replace($matches[1], '', $img);
$img = base64_decode($img);
$photo = 'upload/links/'.md5(date('YmdHis').rand(1000, 9999)).'.'.$type;
file_put_contents(env('IMAGE_URL').'/'.$photo, $img);
$thumbnail=self::resizeImage('0.5',$photo,'thumbnail');
$min =self::resizeImage('0.2',$photo,'min');
return ['type'=>'1','url'=>'/'.$photo,'thumbnail'=>$thumbnail,'min'=>$min];
}