ns_imgtype - Return the type of an image
Returns the type of an image if it can be identified by the particular image header. Currently JPEG, GIF and PNG files are supported. The result is one of "jpeg", "gif" or "png". If the filetype is not recognized the type "unknown" is returned. An error is generated if the file does not exist.
% ns_imgtype screenshot.jpg jpeg
% ns_imgtype test.html 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