JSFiddle - React, Tailwind, and code Playground

HTML

<img src="http://javascript.ru/forum/images/ca_serenity/misc/logo.gif" class="ph_cat" alt="" />

JavaScript

var e = document.getElementsByTagName("img");
var width = 200, height = 300;
var w, h, hi, wi;
    
for (var i = 0; i < e.length; i++)
    if (e[i].className == "ph_cat")
        {
            w = e[i].width;
            h = e[i].height;
            
            hi = h * width / w;
            
            if (hi <= height)
                {
                    e[i].style.width = width +'px';
                    e[i].style.paddingTop = (height - hi)/2 + "px";
                    e[i].style.paddingBottom = (height - hi)/2 + "px";
                }
            else
                {
                    wi = w * height / h;
                    if (wi <= width)
                        {
                            e[i].style.height = height +'px';
                            e[i].style.paddingLeft = (width - wi)/2 + "px";
                            e[i].style.paddingRight = (width - wi)/2 + "px";
                        }
                }
        }