鍍金池/ 問答/PHP  UI  網(wǎng)絡(luò)安全  HTML/ 裁切出來的圖片是 data:image/xxx;base64 格式,php後端怎

裁切出來的圖片是 data:image/xxx;base64 格式,php後端怎麼接應(yīng)?

https://github.com/Foliotek/C...

我找到這個裁切圖片的套件
但是裁切出來的圖片網(wǎng)址變成

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMwAAADMCAYAAAA/IkzyAAAgAElEQV......">

這種格式,我php要怎麼接收?
js還需要怎麼處理才能送到php?
我現(xiàn)在只知道這個 base64會在這出現(xiàn)

clipboard.png

回答
編輯回答
厭惡我

$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];

    }
2017年4月12日 12:59
編輯回答