troubleshooting Question

Image size based on width/height

Avatar of APD Toronto
APD TorontoFlag for Canada asked on
6 Comments1 Solution85 ViewsLast Modified:
Hi Experts,

How can I resize an image dynamically based on their original width or height, without distorting them?

Let me elaborate...

The images are logos that are uploaded by users, so their dimensions are unknown. Some squares, some vertical rectangles, others horizontal. In other words there are 3 possible shapes.

I'm only in the planning phase for this, but i'll have a container (div) for these images, with a fixed size, let's say 190 x 60px.

So based on the 3 shapes and on the known 190 x 60 container, I'd want to end up with the following if the shape is

  • Square
  • , then the display size would be
  • 60 x 60

  • Horizontal
  • , then the display size would be
  • 190 x calc

  • Vertical
  • , then the display size would be
  • calc x 60

In each scenario, the img would remain its original size if it is less than 190x60 I think

Now, I know calc would be proportional. For example, for vertical, calc (or width) would be 60/[orig_height]x[orig_width]

So, my first question is how to obtain the original dimensions of a given image file?

Secondly, what is the easiest way to do this, considering that I'm using PHP/jQuery/SCSS? I'm leaning towards doing it all on the  PHP side.

Thank you.
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros