png2gif-in-ie6-v11

Gesponsorde koppelingen

PHP script bestanden

  1. png2gif-in-ie6-v11

« Lees de omschrijving en reacties

.htaccess

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} MSIE\ [0-6]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*).png$ png2gif.php?url=$1.png


png2gif.php
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php

/**
 * Please do not delete these lines!
 *
 * @author Jonathan
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @version 1.1
 */

/**
 * Configuration
 */

/**
 * Root-path
 * Usefull when this script is not in your root
 */

define('ROOT', './');

/**
 * Cache-folder
 * Please create an empty folder and CGMOD to 0777
 */

define('CACHE', ROOT . 'png2gif/');

/**
 * Script
 */


define('URL', ROOT . $_GET['url']);
$hashUrl = md5(URL);

$createImage = true;

$cachedName = CACHE . $hashUrl . md5(filemtime(URL)) . md5_file(URL);
$cachedType = null;

if (file_exists($cachedName))
{

    $createImage = false;

    if (filesize($cachedName))
    {

        $cachedType = 'gif';
    }

    else
    {
        $cachedType = 'png';
        $cachedName = URL;
    }
}

else
{
    $cachedFiles = scandir(CACHE);

    foreach ($cachedFiles as $cachedFile)
    {

        if (substr($cachedFile, 0, 32) == $hashUrl)
        {

            unlink(CACHE . $cachedFile);
            break;
        }
    }
}


if ($createImage)
{

    $size = getimagesize(URL);
    $width = $size[0];
    $height = $size[1];

    $source = imagecreatefrompng(URL);
    $alpha = false;

    for ($x = 0; $x < $width; $x++)
    {

        for ($y = 0; $y < $height; $y++)
        {

            $color = imagecolorsforindex($source, imagecolorat($source, $x, $y));

            if ($color['alpha'])
            {

                $alpha = true;
                break 2;
            }
        }
    }


    if ($alpha)
    {

        $image = imagecreatetruecolor($width, $height);
        $background = imagecolorallocate($image, 255, 255, 255);
        imagefill($image, 0, 0, $background);
        imagecolortransparent($image, $background);
        imagecopyresampled($image, $source, 0, 0, 0, 0, $width, $height, $width, $height);
        imagegif($image, $cachedName);

        $cachedType = 'gif';
    }

    else
    {
        file_put_contents($cachedName, null);

        $cachedType = 'png';
        $cachedName = URL;
    }
}


header('Content-type: image/' . $cachedType);
readfile($cachedName);
exit;
[
/code]

 
 

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.