BLOB - PHP 调整图像大小
我在调整 blob 图像大小时遇到一个小问题。 我发现我必须调整 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);
I am having a small issue re-sizing blob images.
What I have found is I have to do height and width of the BLOB but because people upload images that are not square, how do I re-size them correctly?
Basicly I want a max width of 300px;
my current code is
$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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调整图像大小并保持约束比例的简单方法:
A simple method to resize a image keeping the constraint proportions: