嗨,我如何使用下面的脚本将我的 base64 图像调整为 w:60px h:60px,我是新手,所以感谢您的帮助,谢谢!
我的更新代码:
$ImageToLoad = $_POST['imgdata'];
if($ImageToLoad){
$ImageToLoad = str_replace('data:image/png;base64,', '', $ImageToLoad);
$ImageToLoad = str_replace('data:image/jpeg;base64,', '', $ImageToLoad);
$ImageToLoad = str_replace(' ', '+', $ImageToLoad);
$fileData = base64_decode($ImageToLoad);
$filename = '../../assets/img/users/'.uniqid().".jpg";
$im = imagecreatefromstring($fileData);
$source_width = imagesx($im);
$source_height = imagesy($im);
$ratio = $source_height / $source_width;
$new_width = 340; // assign new width to new resized image
$new_height = 340;
$thumb = imagecreatetruecolor($new_width, $new_height);
imagefilledrectangle($thumb, 0, 0, $new_width, $new_height);
imagecopyresampled($thumb, $im, 0, 0, 0, 0, $new_width, $new_height, $source_width, $source_height);
imagepng($thumb, $filename, 9);
imagedestroy($im);
file_put_contents($destino_path, $fileData);
}