English 中文(简体)
最佳的MySQL模式,以提升4个不同的图像尺寸
原标题:best MySQL model to upload 4 different sizes of an image
  • 时间:2012-04-16 04:54:58
  •  标签:
  • php
  • image

我在项目上工作,主要重点是照片。 我想上载4种不同的图像。

由于该项目的性质,图像必须优化,因此以尽可能高的质量(最佳质量/大小比率)重载。 我将利用图片店制作4个图像的最佳质量/尺寸版本。 换言之,我用购买力平价在上载时转播图像。

对所有4个图像而言, <>/strong>和-scription 图像上载一样。 每一图像都有自己的width属性(有助于浏览器在html年生成图像)。

我提出了以下模式:

image (image_id, title, desc, filename_s, filename_s_width, filename_s_height, filename_m, filename_m_width, filename_m_height, filename_l, filename_l_width, filename_l_height, filename_xl, filename_xl_width, filename_xl_height, uploaded)

然后,我认为,上述模式今后不会大大扩展,我对以下模式的思考:

image (image_id, title, desc, uploaded)
imagesize (size_id, size)
image_version (id, image_id, filename, width, height, size_id)

还有一个3个模式,即重载主形象并在数据库中保存记录。 而对于这一主要形象的版本,则将“_small”、“_medium”、“_large'、“_xlarge”等词贴在档案名称上。 但是,我无法得到版本图像的宽度和高度的记录(主图像)(真实需要)。 因此,也许这种模式不是最佳的......或可能是......。

我认为,在我开始该项目之前,我会问我。 我想开一个良好的开端,有坚实的基础。

一条正确的道路? 第二种模式是你使用的模式吗? 有更好的模式,即应当知道什么?

预 收

最佳回答

你的第二个模式是更好的模式。

我对这一模式可能作出的唯一指示是将<代码>> 姓名归为基本名称和颜色,并在<代码>image_version<>/代码>上删除不必要的id:

CREATE TABLE imagesizes (
    id TINYINT UNSIGNED NOT NULL PRIMARY KEY,
    size VARCHAR NOT NULL COMMENT  e.g. small, large, thumbnail, original, etc ,
    suffix VARCHAR NOT NULL COMMENT  e.g. _s, _l, _t, or nothing for no suffix ,
    UNIQUE KEY suffix (suffix),
    UNIQUE KEY size (size)
);

CREATE TABLE images (
    id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    basename VARCHAR NOT NULL COMMENT  the base name of the image. Add suffixes to get a filename ,
    title VARCHAR NOT NULL,
    desc VARCHAR NOT NULL,
    uploaded_on DATETIME NOT NULL,
    UNIQUE KEY basename (basename)
);

CREATE TABLE imagefiles (
    image_id INTEGER UNSIGNED NOT NULL,
    imagesize_id TINYINT UNSIGNED NOT NULL,
    width INTEGER UNSIGNED NOT NULL,
    height INTEGER UNSIGNED NOT NULL,
    PRIMARY KEY (image_id, imagesize_id),
    KEY imagesize_idx (imagesize_id),
    CONSTRAINT image FOREIGN KEY (image_id) REFERENCES images (id) ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT imagesize FOREIGN KEY (imagesize_id) REFERENCES imagesizes (id) ON DELETE NO ACTION ON UPDATE CASCADE
);

之后,你可以找到这样的档案名称:

SELECT CONCAT(image.basename, imagesizes.suffix) AS filename
FROM images INNER JOIN imagefiles ON images.id=imagefiles.id
INNER JOIN imagesizes ON imagefiles.imagesize_id=imagesizes.id;

就普通案件而言,你或许应当把这一点总结为一种观点,相反,我们对此表示怀疑:

CREATE VIEW imagelist AS 
SELECT images.id AS id, images.basename AS basename, images.title AS title, images.desc AS desc, 
images.uploaded_on AS uploaded_on, imagefiles.width AS width, imagefiles.height AS height, imagesizes.id AS size_id, 
imagesizes.size AS size, imagesizes.suffix AS suffix, 
CONCAT(imagefiles.basename, imagesizes.suffix) AS filename;
问题回答

我肯定会看第二点。 它允许在上具有灵活性,即<>/em>大小,但不得限制,而不得限制许多

也请考虑存储one图像,然后以图像Magick等工具将其转成:

http://php.net/manual/en/book.imagick.php

After you upload the images, you can get the image dimensions by using the getimagesize function:

http://php.net/manual/en/Function.getimagesize.php

辩论会是最容易的,并给予你所希望的一切灵活性。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...