PHP 显示缩小并调整大小的图像
有没有一种方法可以在服务器上显示缩小并调整大小的图像而不保存缩小的图像?就像如果图像是 500x500 250KB,我希望它在用户浏览器中显示 50x50 45kb。
如果没有办法,我如何临时创建一个文件夹并在粘贴一段时间后删除?
Is there a way with to display an image on a server reduced and resized without saving an reduced one? Like if an image was 500x500 250KB, I want it to display 50x50 45kb in a user's browser.
If there isn't a way, how can I temporarily create one to go to a folder and delete later after sometime has pasted?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
但是您应该以某种方式缓存结果以降低服务器上的负载。
But you should cache the result somehow to lower the load on the server.
我强烈建议您在上传时存储较小的版本并保留原始版本,而不是尝试缩小大图像的大小。使用 S3 等云托管,您可以以低廉的成本完成此任务。
最合乎逻辑的过程是执行一次昂贵的操作(缩放照片)而不是多次。
在回答您的其他问题时,您可以使用 GD 或 imagemagick 来缩小图像。有数百个关于如何执行此操作的教程。如果你想走这条路,我会谷歌一个教程并尝试一下。
I would strongly suggest that rather than trying to resize down a large image that you at upload time store a smaller version and keep the original version. Using cloud hosting like S3 you can do this cheaply.
The most logical process is to perform the expensive operation (scaling the photo) once rather than multiple times.
In answer to your other question you can use GD or imagemagick to scale down an image. There are hundreds of tutorials on how to do this. If you want to go down this route I would Google a tutorial and have a go.
听起来您想要做的就是设置 HTML 图像标记的
height
和width
属性。也可以使用百分比。
CSS 允许更多的控制,并且可以应用于所有图像(或某个类的所有图像)。有了它,您可以指定
max-height
和max-width
这不会影响较小的图像。下面将适用于具有类resizedimages
的所有图像如果您对保存调整大小的图像不感兴趣,那么这听起来完全是客户端问题。 PHP 与它无关(除了可能渲染必要的 HTML)
注意:如果用户右键单击并保存在图像上,它仍然是完整的 250kB。这些纯粹是显示问题。如果这方面对您很重要,那么除了保存缩小副本之外,我不知道有什么方法。
这些可能不是最好的资源,只是谷歌排名靠前的一些资源。
http://www.w3schools.com/tags/tag_img.asp
http://www.fastechws.com/tricks/web/image -最大宽度高度.php
It sounds like all you want to do is set the
height
andwidth
attributes of the HTML image tag.percentages can be used also.
CSS allows for a little more control, and can be applied to all images (or all images of a certain class). With it you can specifcy
max-height
andmax-width
which will not effect smaller images. Below will apply to all images with classresizedimages
If you are not interested in saving a resized image, then this sounds like entirely a client side issue. PHP has nothing to do with it (except perhaps rendering the necessary HTML)
NOTE: If the user goes to right click and save on the image it will still be the full 250kB. These are purely display issues. If this aspect is important to you then I don't know any way other than saving a reduced copy.
These probably arent the best resources, just a few that came up near the top of google.
http://www.w3schools.com/tags/tag_img.asp
http://www.fastechws.com/tricks/web/image-max-width-height.php