NaviServer - programmable web server
4.99  5.0

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

ns_imgmime(n) 5.0.0a naviserver "NaviServer Built-in Commands"

Name

ns_imgmime - Return the MIME type of an image

Table Of Contents

Synopsis

Description

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.

COMMANDS

ns_imgmime filename

EXAMPLES

 % 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

See Also

ns_gifsize, ns_guesstype, ns_imgsize, ns_imgtype, ns_pngsize

Keywords

global built-in, images