How to check a uploaded file whether it is an image or other file?

I’m assuming that you’re running this in a servlet context. If it’s affordable to check the content type based on just the file extension, then use ServletContext#getMimeType() to get the mime type (content type). Just check if it starts with image/. String fileName = uploadedFile.getFileName(); String mimeType = getServletContext().getMimeType(fileName); if (mimeType.startsWith(“image/”)) { // It’s an … Read more

Image scaling in IE 11, 10, and 9 is terrible

Why are they not smoothly scaling down the image? Well because Internet Explorer simply does not support a smooth form of interpolation any more. It was indeed supported in earlier versions of Internet Explorer (version 7) by using ms-interpolation-mode. Newer versions of IE do not support this. It is a very frustrating IE issue and … Read more

High quality JPEG compression with c#

The .Net encoder built-in to the library (at least the default Windows library provided by Microsoft) is pretty bad: http://b9dev.blogspot.com/2013/06/nets-built-in-jpeg-encoder-convenient.html Partial Update I’m now using an approach outlined here, that uses ImageMagick for the resize then jpegoptim for the final compression, with far better results. I realize that’s a partial answer but I’ll expand on … Read more