用php调整图像大小?
我在网上和这里进行了研究,但我一直没有找到可以帮助我的答案: 我有下面的代码,它根据用户的位置显示文件夹中的图像,但是图像太大,我需要调整它的大小。 我尝试或阅读的所有脚本都与上传的文件有关。谁能把我推向正确的方向?
谢谢。
<?php
print"
<table <td width=\"138\" height=\"73\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td align=\"center\" valign=\"middle\"><a href=\"map.php\"><img src=\"" .
esc('img/' . $db_name . '_maps/sm' . $user['location'] . '.png') .
"\" alt=\"Map of systems around {$user['location']}\" /></a></td>
</tr>
</table>
"
?>
我的问题源于以下事实:我需要将图像拉取为:
<img src=\"" .esc('img/' . $db_name . '_maps/sm' . $user['location'] . '.png') . "\" alt=\"Map of systems around {$user['location']}\" /></a>
ive done my research on the net and here as well and i keep on coming up with no answer that can help me:
i have the below code which displays an image from a folder based on a user's location however the image is too big and i need to resize it.
all the scripts that i have tried or read relate to files being uploaded. can anyone push me in the right direction?
thank you.
<?php
print"
<table <td width=\"138\" height=\"73\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td align=\"center\" valign=\"middle\"><a href=\"map.php\"><img src=\"" .
esc('img/' . $db_name . '_maps/sm' . $user['location'] . '.png') .
"\" alt=\"Map of systems around {$user['location']}\" /></a></td>
</tr>
</table>
"
?>
My problem arises from the fact that i need to pull the images as:
<img src=\"" .esc('img/' . $db_name . '_maps/sm' . $user['location'] . '.png') . "\" alt=\"Map of systems around {$user['location']}\" /></a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不久前写了一个关于此的教程。也许它能有所帮助。它从上传开始,但大部分是关于调整大小。只需通过以不同的方式获取图像类型和文件名来交换 $_FILES 数组的使用即可。这是您应该需要的代码:
如果您想将图像存储为文件而不是将其转储到浏览器,请删除末尾的 head 和 echo 部分,然后换出 NULL 参数使用实际文件名调用
imagejpeg
。希望有帮助:)这是正在使用的代码: http://samples.geekality.net/image-resize /
Wrote a tutorial about this a while ago. Perhaps it can help. It starts with uploading, but most of it is about resizing. Just swap out the usage of the $_FILES array by geting the image type and file name a different way. Here's the code you should need:
If you want to store the image as a file rather than dumping it to the browser, remove the head and echo part at the end and then swap out the
NULL
parameter in theimagejpeg
call with an actual filename. Hope that helps :)Here's the code in use: http://samples.geekality.net/image-resize/
你看一下 gd : http://www.php.net/manual /en/function.imagecopyresized.php
你可以试试这个:
You make take a look at gd : http://www.php.net/manual/en/function.imagecopyresized.php
You can try this:
有一个简单易用的开源库,名为 PHP Image Magician,它具有一些不错的功能和文档。
它使用 100% GD。
基础用法示例:
There a simple to use, open source library called PHP Image Magician that has some nice features and documentation.
It uses 100% GD.
Example of basis usage:
如果您需要更多功能convert可能会有所帮助。
If you need more features convert might be a help.