EDIT: This method is useful if you want to retrieve the computed size of an image after it is rendered on a page, but before you transform its size with scale. If you just want the original size of the image, use the methods above.
Try writing the scale of the image to a data attribute when you scale it. Then you can easily divide the new dimensions by that scale attribute to retrieve the original size. It might look something like this:
// Set the scale data attribute of the image
var scale = 2;
img.dataset.scale = scale;
...
// Later, retrieve the scale and calculate the original size of the image
var s = img.dataset.scale;
var dimensions = [img.width(), img.height()];
var originalDimensions = dimensions.map(function(d) {return d / parseFloat(s)});
Alternatively, you can just retrieve the scale of the image directly using jQuery and regex.
var r = /matrix\(([\d.]+),/;
try {
var currentTransform = $swiper.css('transform');
var currentScale = currentTransform.match(r)[1];
}
// Handle cases where the transform attribute is unset
catch (TypeError) {
currentScale = 1;
}
This makes more intuitive sense to me than creating an entirely new image and relying on the browser's caching for it to load quickly.