存储和检索多个头像图像大小 [英] Store and Retrieve Multiple Avatar Image Sizes

查看:59
本文介绍了存储和检索多个头像图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个论坛类型的网站,用户将在该网站上使用化身。主页上将显示一个小版本,而单个页面将显示该头像的大版本。

I am building a forum type site whereby the users will have an avatar. The main page will have a small version whereas the single page will have a large version of the avatar.

因此,出于带宽考虑,我将使用不同的尺寸:

So for sake of bandwidth, I will have different sizes:

example.png
example_thumb.png

不同大小的首选存储和检索方法是什么?

What is the preferred storage and retrieval method for the different sizes?

到目前为止,我想出的是:

Here's what I have come up with so far:

User Table    UserId  |  AvatarName  |  AvatarExt
              1       |  example     |  .png

这样,只要知道,我就可以使用相同的查询获得基本版本和拇指版本要么有一个'_thumb'版本

This way I can get the base and thumb version with the same query as long as I know that there is a '_thumb' version

或者我应该创建一个元表,例如:

Or should I create a meta table like so:

UserMeta      UserId  |  Avatar             |  AvatarType
              1       |  example.png        |  original
              1       |  example_thumb.png  |  thumbnail

我希望得到一些建议

推荐答案

您在正确的轨道上。

用户:

id
username
...

头像

id
user_id
avatar_type(original, thumbnail)
file_name

然后您可以执行以下操作:

Then you can do:

select * from avatars where user_id = $user_id and avatar_type='thumbnail'

例如,您可以允许用户以后使用多个头像而不修改您的表。

This allows you to, say, allow users later on to have multiple avatars without modifying your tables.

这篇关于存储和检索多个头像图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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