An event, although you did not ask for any JS solution. This is my solution for your problem.
Change image width and height
Assuming the shape is parent to img
$(document).ready(function(){ $("img").load(function(){ $(this).parent().width( $(this).width()); }); });
Anoop source share