Hey Tom,
Enqueue this to the footer of comments.php (or ideally just hook it) and think about adding a theme option for file size.
<script>
document.forms[0].addEventListener('submit', function( evt ) {
var file = document.getElementById('comment_image').files[0];
if(file && file.size < 153600) { // 150k (this size is in bytes)
//Submit form
} else {
//Prevent default and display error
alert('File size is too large, please reduce and try again');
evt.preventDefault();
}
}, false);
</script>
That does the trick.
Also, in plugin.php, consider modifying the display code:
<a href="' . $comment_image['url'] . '" rel="PrettyPhoto"><img src="' . $comment_image['url'] . '" alt="" /></a>
The rel won’t do a thing if PrettyPhoto isn’t installed but if it is, it’ll trigger the plugin. You can ignore that or make it an option but the link to full size is nice.
Finally, the following CSS:
p.comment-image img {max-width: 45%;}
span.warning {color:indianred;}
In addition to a warning:
$html .= __( '<br><span class="warning">File must be smaller than 150k or submit will fail</span>', 'comment-images' );
Makes a it a much more functional tool.
Cheers.