The image size is somewhat independent from the file size because bit depth resolution is the major factor in file size. But for scaling, and keeping aspect ratio (so it doesn't look funny) you would find the proportional equivalent for height with the fixed target width. Images stored in a table is a big performance hit compared to storing them on the webstorage, but we can discuss alternatives to this.
for an example, lets say you want to have a fixed width of 500, but the picture is 1280x900.
cross multiply the ratio 1280/900 with 500/x to result in (450000)=1280x and now solve X=(450000)/1280 or x=351.5625 for the new height.
so we can translate this to php like:
//detect picture size
list($width, $height, $type, $attr) = getimagesize("image_file_name.gif");
Since we already know out target width, lets get our target height by using a simplified version of our cross-multiplication:
$newHeight=($height*500)/$width;
Now all we have to do now is to use a resizer method since now we have target height too.
this is a good article on this subject: https://dzone.com/articles/resize-image-class-php
I don't have time right now for a detailed post.