我在重新调整二进制大对象图像的大小时遇到了一些小问题。我发现不得不对BLOB的高度和宽度进行调整,但是由于人们上传的图像不是正方形的,我该如何正确地重新调整它们的大小呢?
基本上,我希望最大宽度为300px;
我的当前代码是:
$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);
getimagesize($img_path)
方法就不适用了,因为它需要一个文件路径而不是文件内容。 - Tiny