You check the content-type
response header. The appropriate value is listed in the Chrome network debugger. Alternatively, you can look it up on one of the many lists on the internet.
Assuming you are using jQuery
$.ajax({
url: "[image url]",
success: function(response, status, xhr){
var contentType = xhr.getResponseHeader("content-type") || "";
if (contentType === "image/jpeg") {
// do something with jpg
}
if (contentType === "image/png") {
// do something with png
}
}
});
If you are using plain javascript use XMLHttpRequest.getResponseHeader()
in stead.