PHP

Image to extension

public function image_type_to_extension($imagetype, $include_dot = false) {
    if (empty($imagetype)) {
        return false;
    }
    if ($include_dot) {
        $dot = '.';
    } else {
        $dot = '';
    }
    switch ($imagetype) {
        case IMAGETYPE_GIF:
            return $dot . 'gif';
        case IMAGETYPE_JPEG:
            return $dot . 'jpg';
        case IMAGETYPE_PNG:
            return $dot . 'png';
        case IMAGETYPE_SWF:
            return $dot . 'swf';
        case IMAGETYPE_PSD:
            return $dot . 'psd';
        case IMAGETYPE_WBMP:
            return $dot . 'wbmp';
        case IMAGETYPE_XBM:
            return $dot . 'xbm';
        case IMAGETYPE_TIFF_II:
            return $dot . 'tiff';
        case IMAGETYPE_TIFF_MM:
            return $dot . 'tiff';
        case IMAGETYPE_IFF:
            return $dot . 'aiff';
        case IMAGETYPE_JB2:
            return $dot . 'jb2';
        case IMAGETYPE_JPC:
            return $dot . 'jpc';
        case IMAGETYPE_JP2:
            return $dot . 'jp2';
        case IMAGETYPE_JPX:
            return $dot . 'jpf';
        case IMAGETYPE_SWC:
            return $dot . 'swc';
        case 1:
            return $dot . 'gif';
        case 2:
            return $dot . 'jpg';
        case 3:
            return $dot . 'png';
        case 4:
            return $dot . 'swf';
        case 5:
            return $dot . 'psd';
        case 6:
            return $dot . 'jpg';
        case 7:
            return $dot . 'tiff';
        case 8:
            return $dot . 'tiff';
        case 9:
            return $dot . 'jpc';
        case 10:
            return $dot . 'jp2';
        case 11:
            return $dot . 'jpx';
        case 12:
            return $dot . 'jb2';
        case 13:
            return $dot . 'swc';
        case 14:
            return $dot . 'aiff';
        case 15:
            return $dot . 'wbmp';
        case 16:
            return $dot . 'xbm';
        default:
            return false;
    }
}