在php中解码base64图像后转换图像64X64 px
嗨,我正在检索base64编码版本的图像,我必须将其裁剪成小尺寸来存储它。现在我无法裁剪图像,请帮助我 我的代码如下。。 请帮我裁剪Base64图像在php中解码base64图像后转换图像64X64 px,php,json,Php,Json,嗨,我正在检索base64编码版本的图像,我必须将其裁剪成小尺寸来存储它。现在我无法裁剪图像,请帮助我 我的代码如下。。 请帮我裁剪Base64图像 $data = str_replace('data:image/png;base64,', '', $note['file']); $data = str_replace(' ', '+', $data); $decodedFile = base64_decode($data)
$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);
您可以使用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;
}
}
不确定你需要什么,但如果你想达到这样的目标,那么这可能会对你有所帮助
尝试使用$success=file\u put\u contents($destination,$decodedFile);图像上传正确,但我必须以64*64裁剪图像,所以搜索“调整图像大小php”或“裁剪图像php”比写问题更困难?