我使用以下代码调整了从用户那里收到的图像的大小:
$imagedata = getimagesize($_FILES['uploadedimage']['tmp_name']);
$newwidth = $imagedata['0']/3;
$newheight = $imagedata['1']/3;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($_FILES['uploadedimage']['tmp_name']);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $imagedata['0'], $imagedata['1']);
// Output and free memory
ob_start();
imagejpeg( $thumb );
echo '<img src="data:image/jpeg;base64,' . base64_encode(ob_get_clean()) . '">';
imagedestroy($thumb);
现在我正在使用这条线
echo '<img src="data:image/jpeg;base64,' . base64_encode(ob_get_clean()) . '">';
显示图像,但相反,我想将其存储在我的数据库中。我无法弄清楚。我在很多论坛上搜索过,都没有找到任何答案。请帮忙。
我通过在写回声的地方添加这行代码来解决这个问题:
$image = addslashes(ob_get_contents());
现在可以使用查询将 $image 正常发送到数据库。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句