Jump to content

Setting max height AND/OR max width of image inside <img> tag?


seany123

Recommended Posts

is it possible to set the MAX height and/or width an image can be inside the <img> tags?

 

eg.

 

<img src="image.php" max-height="40px" max-width="70px">

 

the idea being that the image stays the normal height+width UNLESS it reaches over the said amounts then it scales down to fit inside the amounts.

set only width or height, don't set both... it will be seen in proportion

 

well by setting the height or width its defining the size of the image, i dont want to do that, i want to define the max height or width the image is allowed to be.

well by setting the height or width its defining the size of the image, i dont want to do that, i want to define the max height or width the image is allowed to be.

 

You're saying it like you may not have control over the size of the image. If you provide php before any image is displayed, you can always set the max height/width

 

When I do image resize scripts, I always check that the height is less than 600 pixels(to fit in most browsers) and to specify the image width/height, I do the following:

 

// code that gets the current image's width/height and puts into $image_width/$image_height
if($image_height > 600)
{
  $r = $image_h / 600; // $r is temporary variable that represents the ratio between the image height and 600
  $image_width = $image_width / $r; // that ratio is applied to the width
  $image_height = $image_height / $r; // and then apply the ratio to the height
}

// so now $image_width/$image_height are set so that the dimensions are proportional to the original, and so that the height is no greater than 600

 

modify this code accordingly to fit your needs

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.