I'm using a BB code function to allow members to post images and such in comments and topics. My problem is if an image is too big to fit the table, it expands everything past the width. Are there any workarounds for this? Either in the table or the td? A predefined width and height for the image won't work because I'll never know how big each image is. Is there a way to make a max width/height for the image or something along those lines?
Here's a bit of code you can run to force a maximum width if the images are being stored on your server:
$maxWidth = 450;
$info = getimagesize("../path/to/image.jpg");
if( $info[0] > $maxWidth )
{
print '<img src="../path/to/image.jpg" width="' . $maxWidth . '" />';
}
else
{
print '<img src="../path/to/image.jpg" />';
}
The height will scale to the width, so nothing gets too stretched out.
src
to the image and then determine the width and height of the image through Javascript's built-in methods. You could then dynamically alter the width/height of the <img>
element to be no larger than your pre-determined width/height.Set the TD a max height or width and set the img to 100% width/height