You can use a image_send_to_editor filter hook to achieve what you want.
<?php
add_filter( 'image_send_to_editor', 'imagehtmlchange', 10, 8);
function imagehtmlchange($html, $id, $caption, $title, $align, $url, $size, $alt) {
// your banny wrote - put your code here
return $html;
}
?>