toch-transparante-png-in-ie-7-the-easy-way

Gesponsorde koppelingen

PHP script bestanden

  1. toch-transparante-png-in-ie-7-the-easy-way

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php


// Include this function on your pages
function print_gzipped_page() {
    if( headers_sent() ){
        $encoding = false;
    }
elseif( strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false ){
        $encoding = 'x-gzip';
    }
elseif( strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false ){
        $encoding = 'gzip';
    }
else{
        $encoding = false;
    }


    if( $encoding ){
        $contents = ob_get_contents();
        ob_end_clean();
        header('Content-Encoding: '.$encoding);
        header('Content-type: text/css; charset=utf-8');
        print("\x1f\x8b\x08\x00\x00\x00\x00\x00");
        $size = strlen($contents);
        $contents = gzcompress($contents, 9);
        $contents = substr($contents, 0, $size);
        print($contents);
        exit();
    }
else{
        ob_end_flush();
        exit();
    }
}


// At the beginning of each page call these two functions
ob_start();
ob_implicit_flush(0);

// Get the requested CSS and output it
$file = str_replace('\\','',$_GET['file']);
$file = str_replace('/','',$file);
$files = explode(',',$file);
$count = count($files);
foreach($files as $file){
    $file = trim($file);
    $file .= '.css';
    if(file_exists($file)){
        $contents = file_get_contents($file);
        if($count > 1){
            echo "\n\n/* <<<<<< FILE: ".strtoupper($file)." >>>>>> */\n\n";
        }

        // the nex code fixes the transparant PNG in IE version < 7, It adds the microsoft alpha image loader
        $useragent = $_SERVER['HTTP_USER_AGENT'];
        if (preg_match('|MSIE ([0-6]\.[0-9]{1,2})|',$useragent) && !preg_match('|MSIE ([7-9]\.[0-9]{1,2})|',$useragent)) { // is an old version of IE
            // filter normal png pictures (pictures are cropped)

            $pattern = '/(url\((.*\.png)\).*\n)/';
            $replace = '$1'."\t".'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'$2\', sizingMethod=\'crop\'); background-image:none;'."\n";
            $contents = preg_replace($pattern,$replace,$contents);
            // filter png pictures that need to be scaled (when using background repeat for example)
            $pattern = '/(\/\*SCALE\*\/.*\n.*filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\(.*, sizingMethod=\').*\'/';
            $replace = '$1scale\'';
            $contents = preg_replace($pattern,$replace,$contents);
        }

        echo $contents;
    }
}



// Call this function to output everything as gzipped content.
print_gzipped_page();


?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.