Jump to content

If/Then relating to image height


jonw118

Recommended Posts

Hello...

 

I'm not sure how to (if it can be done) restrict an image height ONLY if it is over a certain amount of pixels.

 

Specifically, right now the script resizes images by width only. But sometimes, if an image that is long vertically is uploaded it throws the format off, so in that case, I do want it resize by width AND height, but only in that case.

 

I hope that makes sense.

 

Basically if right now an image is inserted that is 1500px x 1500px I only want it to scale the image width (ie, scaled to 150px wide), keeping the height in proporotion automatically (150px height for this example). But if an image is 1500 x 4000, for example, I'd like it to scale to something like (150px X 150px)... and yes I know it will distort the image, but it will be better than how it breaks the format currently.

 

Is this possible?

 

The specific code I am working with is:

 

<img style='float: center; margin-right: 5px;' width='150px' src='$img' />

 

Thanks for any suggestions!!!

Link to comment
Share on other sites

Yes, it is possible. But, why not specify a max width and a max height. So, for example, if the max size is 150 x 150 the following images would be resized as follows:

 

1000 x 1000 = 150 x 150

1000 x 3000 = 50 x 150

3000 x 1000 = 150 x 50

 

You could even "fill in" the unused proportions with black or white. Distorting the image is a bad route IMHO.

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.