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_wid
th]
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.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Fellow title is reserved for select members who demonstrate sustained contributions, industry leadership, and outstanding performance. We will announce the experts being inducted into the Experts Exchange Fellowship during the annual Expert Awards, but unlike other awards, Fellow is a lifelong status. This title may not be given every year if there are no obvious candidates.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.