I am currently working on a script to automatically resize images that are too large for 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 functionality is working as expected. However, I want to display a message to the user showing the original size of the image, percentage of resizing, and the file size in KB.
For example:
This image has been resized to 400 x 300 (50%). Original image size: 800 x 600 and 75 KB. Click to view the original
Currently, I am only able to retrieve the width of the resized image (the height() method returns 0 for some reason).