【发布时间】:2011-08-30 13:58:28
【问题描述】:
我在调整 blob 图像大小时遇到了一个小问题。 我发现我必须做 BLOB 的高度和宽度,但是因为人们上传的图片不是方形的,我该如何正确调整它们的大小?
基本上我想要最大宽度为 300 像素;
我当前的代码是
$desired_width = 300;
$desired_height = 300;
$sth = mysql_query("SELECT photobase FROM userpictures WHERE id = '".$array[0]."'");
while($r = mysql_fetch_assoc($sth)) {
$blobcontents = $r["photobase"];
$im = imagecreatefromstring($blobcontents);
$new = imagecreatetruecolor($desired_width, $desired_height);
$x = imagesx($im);
$y = imagesy($im);
imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y);
imagedestroy($im);
header('Content-type: <span class="posthilit">image</span>/jpeg');
imagejpeg($new, null, 85);
【问题讨论】: