NaviServer - programmable web server


[ Main Table Of Contents | Table Of Contents | Keyword Index ]

ns_imgtype(n) 4.99.5 naviserver "NaviServer Built-in Commands"

Name

ns_imgtype - Return the type of an image

Table Of Contents

Synopsis

Description

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.

COMMANDS

ns_imgtype filename

EXAMPLES

% ns_imgtype screenshot.jpg
jpeg
% ns_imgtype test.html
unknown
% foreach f [glob -nocomplain -types f /tmp/images/*] {
    if {[lsearch [list jpeg png gif] [ns_imgtype $f]]} {
        puts -nonewline "supported image:  "
    } else {
        puts -nonewline "unsupported file: "
    }
    foreach {width height} [ns_imgsize $f] { break }
    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

See Also

nsd

Keywords

ns_gifsize, ns_imgmime, ns_imgsize, ns_pngsize