我使用html2canvas從此代碼生成屏幕抓圖jpg。不過,我不能針對一個particaular div,所以我抓住整個屏幕。來自base64_decode的PHP裁剪圖像
$canvasImg = $_POST['img'];
$data = base64_decode($canvasImg);
$File = "z.jpg";
$Handle = fopen($File, 'w');
fwrite($Handle, $data);
fclose($Handle);
問題:我怎麼能裁剪圖像?
這是我attampt
$canvasImg = $_POST['img'];
$image = base64_decode($canvasImg);
$dest_image = 'z.jpg';
$img = imagecreatetruecolor('200','150');
$org_img = imagecreatefromstring($image);
$ims = getimagesize($image);
imagecopy($img,$org_img, 0, 0, 20, 20, 200, 150);
imagejpeg($img,$dest_image,90);
imagedestroy($img);
但即時得到一個錯誤
Warning: getimagesize(�PNG ) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: Invalid argument
您正在尋找imagecreatefromstring()http://php.net/manual/en/function.imagecreatefromstring.php –
你是不是傳遞一個圖像到imagecreatefrompng(),有一定的誤差與圖像變量 –
重編輯我的問題,實現'imagecreatefromstring()' –