tibberous Posted August 30, 2008 Share Posted August 30, 2008 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? Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 30, 2008 Author Share Posted August 30, 2008 Guess I have to send in the height and width too - is their a way to have a stored procedure access members of the row it's affecting? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 30, 2008 Share Posted August 30, 2008 if you're resizing to 6 different dimensions, why not store the 6 different widths and heights with the file name and reference them all by the record id? Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 30, 2008 Author Share Posted August 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 30, 2008 Share Posted August 30, 2008 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. Quote Link to comment Share on other sites More sharing options...
tibberous Posted August 30, 2008 Author Share Posted August 30, 2008 Yeah, I could have done that. I think technically you are not supposed to store values that are derivatives of other values, unless you are caching them for performance -- that would have saved a lot of time though Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted August 30, 2008 Share Posted August 30, 2008 if you are resizing the images, the dimensions are set. they aren't derivatives. the alternative would be to 'derive' the values on every run instead of just once. doesn't sound like a time saver to me. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 30, 2008 Share Posted August 30, 2008 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); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.