NaviServer - programmable web server

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

# ns_imgtype(n) 4.99.8 naviserver "NaviServer Built-in Commands"

## Name

ns_imgtype - Return the type of an image

## Table Of Contents

## Synopsis

- ns_imgtype filename

## 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 {[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_imgmime, ns_imgsize, ns_pngsize

## Keywords

images