在PHP中调整base64_string图像的大小

问题描述 投票:0回答:1

嗨,我如何使用下面的脚本将我的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);

}
php image-resizing tobase64string
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.