I'm trying to build a script that browser-resizes images that are larger than the container:
$('img').each(function(i){
var parent_width = parseInt($(this).parent().width()),
image_width = parseInt($(this).width());
if(parent_width !== image_width){
$(this).width(parent_width).wrap(
'<a class="resized-image" href="' + this.src + '">'
+ ' <span class="msg">'
+ ' This image has been resized to ' + parent_width + ' pixels'
+ ' and ' + $(this).height() + ' pixels'
+ '</span>'
+ '</a>'
);
}
});
The resizing works, but how can I get a nice message there telling the user the original image size, percentage to which the image was resized and the original image size in KB?
Like
This image has been resized to 400 x 300 (50%). Original image has 800 x 600 and 75 KB. Click to view the original
So far I could only figure out the width of the resized image (the height() returns 0 for some reason)