$().ready(function() { $('[type="file"]').change(function() { var fileInput = $(this); if (fileInput.length && fileInput[0].files && fileInput[0].files.length) { var url = window.URL || window.webkitURL; var image = new Image(); image.onload = function() { alert('Valid Image'); }; image.onerror = function() { alert('Invalid image'); }; image.src = url.createObjectURL(fileInput[0].files[0]); } }); });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter