Jump to content

Cleanest way to do this...


tibberous

Recommended Posts

I have a table, called images. It has a row that stores the height and width of the initial image.

 

When uploaded, the initial image is resized to 6 different dimensions, keeping aspect. So, if my image was 1000 x 2000, and I select the 200 px version, it would be 100x200.

 

Do you think I should make a stored procedure, that takes in a size, and then returns the right dimensions? Do something like:

 

mysql_query("select height(200) as Height, width(200) as Width from images where id='4'"); ?

 

Is their a better way?

Link to comment
https://forums.phpfreaks.com/topic/122024-cleanest-way-to-do-this/
Share on other sites

Not sure what your saying - you mean store it as 123_120_100.jpg, where the name is id, with, height?

 

And here is why I hate stored functions:

CREATE FUNCTION `height`(size int, w int, h int) returns int
begin
if (h >= w) then return size;
else return size * (h / w);
end if;
end ;

 

Be sweet if there was a database that used PHP syntax for stored functions.

i mean store the actual file name plus the 6 dimensions, maybe a table like this:

 

id INT auto-increment primary key

image_name

dim1_width

dim1_height

dim2_width

dim2_height

etc.

 

when the image is uploaded and resized, add a row with the image name and each of the dimensions, width and height 1 through 6... or maybe i misunderstand.

If the dimensions are different for every image then go with the above. If they are fixed sizes applied to all images just use a function to calculate derived dimensions

 

function newHeight ($width, $height, $newwidth)

{

    return intval($newidth * $height / $width);

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.