This is similar to what was set before, but I cannot find a duplicate, so ...
I want the smallest image size scaled to a maximum of 200, while maintaining aspect ratio. So:
Obviously, if this can be done using css, this is preferable to javascript.
Yes, you will need JS:
Live demo
function scale(W, H, max) { var min = Math.min(W, H), // Get the smallest size nr = min>max, // NeededResize (Boolean) rat = Math.min(max/W, max/H);// Ratio return { W: nr?W*rat:W, // if NeededResize do W*rat, else just use the image W H: nr?H*rat:H }; }
// Use like: scale(imageWidth, imageHeight, maxSizeToRespect); var resize = scale(this.width, this.height, 200); // Where from now on resize.W // is the returned width scale resize.H // is the returned height scale
Source: https://habr.com/ru/post/1532197/More articles:Library Compatibility between C # .NET and C # Mono - c #FileSystemWatcher - can't do this without API? - vb.netUsing try / catch blocks in unit tests - c #Rails 4 app - where to add jQuery custom plugins and how to enable them - pluginsHow do you create an arrow for navigation assist like this? - htmlhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1532198/rssatom-feed-parsing-in-haskell&usg=ALkJrhhGyF4aeoVQyHQfUU-NOdzoJ2nkdwWhy does the rmvnorm () function return "In sqrt (ev $ values): NaNs is produced", what is this error and how can it be fixed or avoided? - rEmbed readme in the main page (doxygen) - c ++selenium gets page source different with right click in browser - javascriptDoes D have something like Java Scanner? - java.util.scannerAll Articles