After some tweaking and looking through the provided answers, here's some working code that will adjust for differences in height, width, and aspect ratios. With use of some data attributes, this is a good start to feed from, and if you are using a different form of communicating the data, just replace variables as needed. First, the HTML:
<input type="range" min="0" max="100" value="100" step="1" id="slider" style="width: 500px;" />
<div id="per">100%</div>
<div>
<img src="http://placehold.it/1920x1280" alt="My image" id="my-img" />
</div>
Simple enough, and when testing, change the src attribute of the img tag to see how the code handles different sizes. Now the fun part:
var id = function(i){return(document.getElementById(i));},
slider = id('slider'),
per = id('per'),
img = id('my-img'),
d_w = 0,
d_h = 0,
min = 350,
reSize = function(percent) {
var h = slider.getAttribute('data-h') == 'true',
s_h = (parseFloat(slider.getAttribute('data-step-h')) * percent) + min,
s_w = (parseFloat(slider.getAttribute('data-step-w')) * percent) + min,
o_h = (d_h / d_w) * s_w,
o_w = (d_w / d_h) * s_h;
img.style.height = ((h) ? s_h : o_h).toString() + 'px';
img.style.width = ((h) ? o_w : s_w).toString() + 'px';
};
img.addEventListener('load', function() {
d_w = this.width;
d_h = this.height;
slider.setAttribute('data-h', (d_w > d_h));
slider.setAttribute('data-step-h', (d_h - min) / 100);
slider.setAttribute('data-step-w', (d_w - min) / 100);
slider.addEventListener('input', function() {
var perc = parseFloat(this.value);
per.innerHTML = perc.toString() + '%';
reSize(perc);
}, false);
}, false);
Few quick pointers, make sure to wrap this in an onload or better yet, DomContentLoaded method like:
document.addEventListener('DOMContentLoaded', function()( /* Code */ }, false);
And keep in mind the range type of input isn't supported in older IE, some maybe some hidden inputs instead? Also, instead of input in the slider event, it has to be change in IE 10 so keep that in mind for cross browser-ness.
Breakdown of the code, yeah? Alright, first we declare some variables, where id is just to grab by ID, grab the elements, have some more 'global' like variables (d_w, d_h, and min) where d_w is default width and d_h is, yep, default height. The reSize() function grabs the data assigned to the image and uses it for calculations and determining which side is longer, followed by s_h and s_w which uses the step to adjust the pixels, some aspect ratio equations, and finally hit the width and height of the element with CSS.
slider.addEventListener does a few simple things, like update the percent and run the reSize() function when it moves. Again, make sure to check for IE 10 and replace input with change if you want this to work on that... 'browser'.
Finally, the img event grabs the default width and height, assigns them to said variables (d_w and d_h), checks which side is longer, and with the help of Paulo, calculates the step for each percent based on the offset of the actual size vs the minimum. I tested this on Chrome, FF, and IE 10+ and it's working fine. It'll work on IE 9>, but you'll have to use attachEvent and no range element. Hope this helps.
EDIT
I put the slider event within the img load event to prevent premature firing of the code. I could tweak this more and even make it a stand-alone 'class' (well, kinda, JS classes are weird) if you like, let me know and I'd take a swing at it.
628px