我应该在每次请求时动态生成每个缩略图,还是将它们存储在图像上传中? [英] Should I generate each thumbnail dynamically every time it is requested, or store them on image upload?

查看:115
本文介绍了我应该在每次请求时动态生成每个缩略图,还是将它们存储在图像上传中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题-我想在我的网站上设置图片上传功能.但是我想同时显示-原始图像和图像的小缩略图.

Problem - I wanted to set up an image-uploading feature in my website. But I wanted to show both- the original image and a small thumbnail of the image.

选择-哪种方法更好-上传图像时在目录中创建单独的图像(缩略图),或者通过以固定比例减小其高度和宽度来显示较小的版本什么时候请求图像?

Choices - Which way is better - to create a separate image (thumbnail) in a directory when the image is uploaded or to show a smaller version by reducing its height and width in the fixed ratio every time the image is requested?

我目前的工作方式-后一种听起来对我来说更好,因为它不会占用太多磁盘空间,但必须一次又一次地调整图像大小.您认为哪个更好?

How I am doing it currently - The later one sounds better to me because it won't be taking much size on the disk but it has to resize the image again and again. Which one do you think is better?

这是Web应用程序的常见问题,没有特定的语言.

This is a general question for web application, no language in specific.

您知道Facebook或Google是如何做到的吗?

Any idea how facebook or google do it?

问题-我的问题是如何生成缩略图并将其显示在网站上-通过创建较小尺寸的原始图像的副本,或在每次请求时动态生成缩略图. /p>

Question - My question is how to generate thumbnails and show them on a website - by creating a copy of the original image with smaller dimension or by generating the thumbnail dynamically every time it is requested.

推荐答案

在上传时创建缩略图几乎总是更好的选择.如果需要考虑存储,则可以将其转换为请求,然后将结果缓存在内存存储中.如果在缓存过期之前再次请求它,则无需进行转换.

Creating the thumbnail on upload is almost always the better option. If storage is a concern you could convert them on the request and then cache the result in a memory store. If its requested again before the cache expires, no conversion will be needed.

存储空间通常很便宜,所以我可能不会考虑这种额外的复杂性.

Storage is often pretty cheap, so I would probably not go for that extra complexity.

这篇关于我应该在每次请求时动态生成每个缩略图,还是将它们存储在图像上传中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆