ns_imgmime - Return the MIME type of an image
Returns the MIME type of an image based on the image type (and not just the file extension). Currently JPEG, GIF and PNG files are supported, so the result can be one of "image/jpeg", "image/gif" or "image/png". If the filetype is not recognized the type "image/unknown" is returned. An error is generated if the file does not exist.
% ns_imgmime screenshot.jpg image/jpeg
% ns_imgmime test.html image/unknown
% foreach f [glob -nocomplain -types f /tmp/images/*] { if {[ns_imgtype $f]] ne "unknown"} { puts -nonewline "supported image: " } else { puts -nonewline "unsupported file: " } lassign [ns_imgsize $f] width height set mimetype [ns_imgmime $f] set f [file tail $f] puts [format "%30s width: %5i height: %5i MIME: %15s" \ $f $width $height $mimetype] } unsupported file: support.pdf width: 0 height: 0 MIME: image/unknown supported image: MARADONNA.jpg width: 294 height: 420 MIME: image/jpeg