2015-05-12 96 views
1

你好我retriving圖像的base64編碼版本和我有通過將其裁剪到小尺寸存儲它。現在我不能夠裁切圖像,請幫我 我的代碼如下.. 請幫我在種植基地64圖像轉換圖像64×64像素在PHP BASE64解碼圖像之後

$data = str_replace('data:image/png;base64,', '', $note['file']); 
       $data = str_replace(' ', '+', $data); 
       $decodedFile = base64_decode($data); 
$file = fopen($destination , 'wb'); 


if(!fwrite($file, $decodedFile)){ 
       //return("ERROR: can't save file to $destination"); 
       return '-1'; 
      } 
       fclose($file); 
+0

嘗試使用$ success = file_put_contents($ destination,$ decodedFile); – Saty

+0

影像是否正確上傳,但我必須裁剪64圖像* 64 – Deepesh

+1

因此搜索「調整圖像的PHP」或「裁剪圖像PHP」比寫一個問題更困難? –

回答

2

可以使用GD庫創建二進制代碼的圖像文件:

function binaryToFile($binary_imagen, $width, $height, $new_name, $url_destiny) { 

    try{ 
     //actual size 
     $info = getimagesizefromstring($binary_imagen); 
     $old_width = $info[0]; 
     $old_height = $info[1]; 

     //new resource 
     $resource = imagecreatefromstring($binary_imagen); 

     $resource_copy = imagecreatetruecolor($width, $height); 

     imagealphablending($resource_copy , false); 
     imagesavealpha($resource_copy , true); 

     imagecopyresampled($resource_copy, $resource, 0, 0, 0, 0, 
        $width, $height, 
        $old_width, $old_height); 

     $url = $url_destiny."/".$new_name".png"; 
     $final = imagepng($resource_copy, $url, 9); 

     imagedestroy($resource); 
     imagedestroy($resource_copy); 

     return 1; 

    }catch (Exception $e) { 
     return 0; 
    } 

} 
+0

謝謝他對我的作品...非常非常感謝你 – Deepesh