保存/显示图像的最佳方式是什么? (不是 blob 与 txt)
我正在现场制作一个画廊。并且不知道最好的解决方案是什么。需要建议。
我认为有两种处理图像的方法。
用户上传图像。我只将其保存在服务器上一次,仅保存其原始大小。然后,当需要在屏幕上显示该图像时,我会将其大小调整为必要的大小,例如作为头像。因此,我只存储一张原始尺寸的图像,并在显示之前将其调整为任何合适的尺寸。
用户上传图像。我将其以原始大小保存在服务器上,并制作并保存多个副本(缩略图大小),例如头像大小、erc.txt。这样,如果显示图像,则每次显示时都不会调整其大小,而只是获取适当大小的副本。
我认为第二种方式更好。因为不需要每次都花费服务器的力量来调整图像的大小。但是,如果我决定更改网站的设计并且网站上图像的某些尺寸也将调整大小,该怎么办?我会遇到服务器上有大量不适合新设计的图像的情况。
他们在不同的论坛上解释如何制作画廊,每次他们都说还制作并保存了缩略图大小的副本。但如果及时改变设计,似乎就没有意义了。请指教。语言——PHP。
I’m making a gallery on site. And don’t know what the best solution for it. Need advice.
For my opinion there are two ways of operating with images.
User uploads image. I save it on server only once, only with its original size. And then, when there’s a need of displaying that image on screen I resize it to the necessary size, for example as avatar. So I store only ONE original-sized image and resize it to ANY proper size RIGHT BEFORE displaying.
User uploads image. I save it on server with original size and also make and save several copies (thumbnails-sized), for example, avatar-sized, erc. So that if the image is displayed it’s not resized every time it is displayed, just proper-sized copy taken.
I think that the second way is better. Because there’s no need to spend server strength on resizing images every time. But what if I’ll decide to change design of my site and some dimensions of images on it will be resized too? I’ll get the situation of having lots of images on server that doesn’t fit new design.
All around different forums they explain how to make galleries and every time they say that thumbnail-sized copies are also made and saved. But it looks like it doesn’t make sense if design is changed in time. Please, advise. Language – PHP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
其他人提出的一种解决方案是两者的混合。因此,用户上传照片,您将其以其原始形式保存在服务器上。然后,当需要头像时,您检查磁盘上是否保存了头像(可能是 user12345_50x50.jpg - 其中 50x50 是宽度 x 高度)。如果确实存在,则显示该图像。如果没有,则使用服务器调整大小/裁剪任何内容,然后将该图像保存到磁盘并将其提供给用户。这将允许您请求任何大小的文件并根据需要提供服务 - 利用缓存已请求的文件[请注意,这是服务器端缓存,因此将适用于全部用户]。
您可以两全其美。您不需要预先处理所有图像操作,只需根据需要即可。第一次处理图像时,该用户将不得不等待,但任何其他请求都将获得处理后的文件。
在 PHP 中使用此解决方案的一种实现是 phpthumb: http://phpthumb.sourceforge.net/
One solution that others have come up with is a mix between the two. So, the user uploads the photo and you save it in its original form on your server. Then, when an avatar is needed, you check to see if you have the avatar saved on disk (maybe user12345_50x50.jpg - where 50x50 is widthxheight). If it does exist, show that image. If not, then use the server to resize/crop whatever, then save that image to disk and serve that to the user. This will allow you to request any size file and serve it as-needed -- taking advantage of caching those that have already been requested [Note that this is a server-side cache, so would apply for all users].
You sort of get the best of both worlds. You don't need to handle all of the image manipulation up front, just as needed. The first time the image is processed, that user will have to wait, but any other request will get the processed file.
One implementation that uses this solution in PHP is phpthumb: http://phpthumb.sourceforge.net/