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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.