Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

dos2unix, no trailing whitespaces, no tabs, no ending php tags

  • Loading branch information...
commit c052b897ede15ea88d93889c303b6a1cd5be4ea7 1 parent 077ea4e
Sebastian Tramp authored August 30, 2011
248  filters/Crop.filter.php
... ...
@@ -1,125 +1,123 @@
1  
-<?php
2  
-/* How to use
3  
- * 
4  
- * Crop width
5  
- * ?filter=Crop-width-OFFSET-WIDTH
6  
- * Crops WIDTH columns starting with column OFFSET.
7  
- * ?filter=Crop-width-mOFFSET-WIDTH
8  
- * Crops WIDTH columns starting with column (ImageWidth - OFFSET).
9  
- * ?filter=Crop-width-OFFSET-mWIDTH
10  
- * Crops columns starting with OFFSET ending with (ImageWidth - WIDTH).
11  
- * ?filter=Crop-width-mOFFSET-mWIDTH
12  
- * Crops columns starting with (ImageWidth - OFFSET) ending with (ImageWidth - WIDTH).
13  
- * 
14  
- * Crop height
15  
- * ?filter=Crop-height-OFFSET-WIDTH
16  
- * Analog to width.
17  
- * 
18  
- * Crop exact box
19  
- * ?filter=Crop-exact-XOFFSET-YOFFSET-WIDTH-HEIGHT
20  
- * Analog to width.
21  
- */
22  
-
23  
-class Crop extends InstantFilter
24  
-{
25  
-
26  
-	// Security values are in pixel
27  
-	// value -1 means to skip the check
28  
-	var $security = array(
29  
-		"max-width"=>-1,
30  
-		"min-width"=>-1,
31  
-		"max-height"=>-1,
32  
-		"min-height"=>-1,
33  
-		"max-dim"=>-1, // maximum of dimension (x*y) (2560*1920 (=5MPix))
34  
-		"min-dim"=>-1 // minimum of dimension (x*y)
35  
-	);
36  
-
37  
-	function Crop($source, $parameter = null)
38  
-	{
39  
-
40  
-    	$oldWidth = imagesx ($source);
41  
-    	$oldHeight = imagesy ($source);
42  
-    	$startX = 0;
43  
-    	$startY = 0;
44  
-
45  
-    	if ($parameter[1] == 'width')
46  
-    	{
47  
-    		$startX = $this->calcSize($oldWidth, 0, $parameter[2]);
48  
-            
49  
-            $newWidth = $this->calcSize($oldWidth, $startX, $parameter[3]);
50  
-            $newHeight = $oldHeight;
51  
-
52  
-    		// security check of dimensions
53  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
54  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
55  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
56  
-    	}
57  
-    	elseif ($parameter[1] == 'height')
58  
-    	{
59  
-    		$startY = $this->calcSize($oldHeight, 0, $parameter[2]);
60  
-            
61  
-            $newWidth = $oldWidth;
62  
-            $newHeight = $this->calcSize($oldHeight, $startY, $parameter[3]);
63  
-
64  
-    		// security check of dimensions
65  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
66  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
67  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
68  
-    	}
69  
-    	elseif ($parameter[1] == 'exact')
70  
-    	{
71  
-    		$startX = $this->calcSize($oldWidth, 0, $parameter[2]);
72  
-    		$startY = $this->calcSize($oldHeight, 0, $parameter[3]);
73  
-            
74  
-            $newWidth = $this->calcSize($oldWidth, $startX, $parameter[4]);
75  
-            $newHeight = $this->calcSize($oldHeight, $startY, $parameter[5]);
76  
-
77  
-    		// security check of dimensions
78  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
79  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
80  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
81  
-    	}
82  
-    	elseif ($parameter[1] == '')
83  
-    	{
84  
-    		$this->pushError('no attributes');
85  
-    	}
86  
-    	else
87  
-    	{
88  
-    		$this->pushError('wrong attribute '.$parameter[1]);
89  
-    	}
90  
-
91  
-	if (count($this->error) == 0)
92  
-	{
93  
-    		$this->dest = imagecreatetruecolor($newWidth, $newHeight);
94  
-    		if (!imagecopy($this->dest, $source, 0, 0, $startX, $startY, $newWidth, $newHeight))
95  
-    		{	
96  
-    			$this->dest = false;
97  
-    			$this->pushError('cannot apply filter');
98  
-    		}
99  
-    	}
100  
-    	else
101  
-    	{
102  
-    		$this->dest = false;
103  
-    	}
104  
-	}
105  
-	
106  
-	function calcSize($oldSize, $start, $parameter)
107  
-	{
108  
-		if (preg_match("/^m/", $parameter)) {
109  
-			$parameter = substr($parameter, 1);
110  
-			if (strlen($parameter) == 0)
111  
-				return ($oldSize - $start);
112  
-			else
113  
-				return ($oldSize - $parameter - $start);
114  
-		}
115  
-		return $parameter;
116  
-	}
117  
-
118  
-	function checkSecurity($value, $min, $max)
119  
-	{
120  
-		if ($min > 0 && $value < $min) $this->pushError('security issue, dimension fault ('.$value.' < '.$min.')');
121  
-		if ($max > 0 && $value > $max) $this->pushError('security issue, dimension fault ('.$value.' > '.$max.')');
122  
-	}
123  
-}
124  
-
125  
-?>
  1
+<?php
  2
+/* How to use
  3
+ *
  4
+ * Crop width
  5
+ * ?filter=Crop-width-OFFSET-WIDTH
  6
+ * Crops WIDTH columns starting with column OFFSET.
  7
+ * ?filter=Crop-width-mOFFSET-WIDTH
  8
+ * Crops WIDTH columns starting with column (ImageWidth - OFFSET).
  9
+ * ?filter=Crop-width-OFFSET-mWIDTH
  10
+ * Crops columns starting with OFFSET ending with (ImageWidth - WIDTH).
  11
+ * ?filter=Crop-width-mOFFSET-mWIDTH
  12
+ * Crops columns starting with (ImageWidth - OFFSET) ending with (ImageWidth - WIDTH).
  13
+ *
  14
+ * Crop height
  15
+ * ?filter=Crop-height-OFFSET-WIDTH
  16
+ * Analog to width.
  17
+ *
  18
+ * Crop exact box
  19
+ * ?filter=Crop-exact-XOFFSET-YOFFSET-WIDTH-HEIGHT
  20
+ * Analog to width.
  21
+ */
  22
+
  23
+class Crop extends InstantFilter
  24
+{
  25
+
  26
+    // Security values are in pixel
  27
+    // value -1 means to skip the check
  28
+    var $security = array(
  29
+        "max-width"=>-1,
  30
+        "min-width"=>-1,
  31
+        "max-height"=>-1,
  32
+        "min-height"=>-1,
  33
+        "max-dim"=>-1, // maximum of dimension (x*y) (2560*1920 (=5MPix))
  34
+        "min-dim"=>-1 // minimum of dimension (x*y)
  35
+    );
  36
+
  37
+    function Crop($source, $parameter = null)
  38
+    {
  39
+
  40
+        $oldWidth = imagesx ($source);
  41
+        $oldHeight = imagesy ($source);
  42
+        $startX = 0;
  43
+        $startY = 0;
  44
+
  45
+        if ($parameter[1] == 'width')
  46
+        {
  47
+            $startX = $this->calcSize($oldWidth, 0, $parameter[2]);
  48
+
  49
+            $newWidth = $this->calcSize($oldWidth, $startX, $parameter[3]);
  50
+            $newHeight = $oldHeight;
  51
+
  52
+            // security check of dimensions
  53
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  54
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  55
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  56
+        }
  57
+        elseif ($parameter[1] == 'height')
  58
+        {
  59
+            $startY = $this->calcSize($oldHeight, 0, $parameter[2]);
  60
+
  61
+            $newWidth = $oldWidth;
  62
+            $newHeight = $this->calcSize($oldHeight, $startY, $parameter[3]);
  63
+
  64
+            // security check of dimensions
  65
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  66
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  67
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  68
+        }
  69
+        elseif ($parameter[1] == 'exact')
  70
+        {
  71
+            $startX = $this->calcSize($oldWidth, 0, $parameter[2]);
  72
+            $startY = $this->calcSize($oldHeight, 0, $parameter[3]);
  73
+
  74
+            $newWidth = $this->calcSize($oldWidth, $startX, $parameter[4]);
  75
+            $newHeight = $this->calcSize($oldHeight, $startY, $parameter[5]);
  76
+
  77
+            // security check of dimensions
  78
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  79
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  80
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  81
+        }
  82
+        elseif ($parameter[1] == '')
  83
+        {
  84
+            $this->pushError('no attributes');
  85
+        }
  86
+        else
  87
+        {
  88
+            $this->pushError('wrong attribute '.$parameter[1]);
  89
+        }
  90
+
  91
+        if (count($this->error) == 0)
  92
+        {
  93
+            $this->dest = imagecreatetruecolor($newWidth, $newHeight);
  94
+            if (!imagecopy($this->dest, $source, 0, 0, $startX, $startY, $newWidth, $newHeight))
  95
+            {
  96
+                $this->dest = false;
  97
+                $this->pushError('cannot apply filter');
  98
+            }
  99
+        }
  100
+        else
  101
+        {
  102
+            $this->dest = false;
  103
+        }
  104
+    }
  105
+
  106
+    function calcSize($oldSize, $start, $parameter)
  107
+    {
  108
+        if (preg_match("/^m/", $parameter)) {
  109
+            $parameter = substr($parameter, 1);
  110
+            if (strlen($parameter) == 0)
  111
+                return ($oldSize - $start);
  112
+            else
  113
+                return ($oldSize - $parameter - $start);
  114
+        }
  115
+        return $parameter;
  116
+    }
  117
+
  118
+    function checkSecurity($value, $min, $max)
  119
+    {
  120
+        if ($min > 0 && $value < $min) $this->pushError('security issue, dimension fault ('.$value.' < '.$min.')');
  121
+        if ($max > 0 && $value > $max) $this->pushError('security issue, dimension fault ('.$value.' > '.$max.')');
  122
+    }
  123
+}
155  filters/Palette.filter.php
... ...
@@ -1,78 +1,77 @@
1  
-<?php
2  
-
3  
-class Palette
4  
-{
5  
-
6  
-	var $oldWidth = 0;
7  
-	var $oldHeight = 0;
8  
-	var $source;
9  
-
10  
-	function Palette($source,$parameter)
11  
-	{
12  
-    	$this->oldWidth = imagesx ($source);
13  
-    	$this->oldHeight = imagesy ($source);
14  
-		$this->source = $source;
15  
-
16  
-		if ($parameter[1] == 'gray')
17  
-		{
18  
-			if ($parameter[2] > 1 && $parameter[2] < 257)
19  
-			{
20  
-				$this->PaletteGray($parameter[2]);
21  
-			}
22  
-			else
23  
-			{
24  
-				$this->PaletteGray(64);
25  
-			}
26  
-		}
27  
-		elseif ($parameter[1] == '')
28  
-		{
29  
-			$this->error[] = 'empty attribute';
30  
-		}
31  
-		else
32  
-		{
33  
-			$this->error[] = 'do not know attribute "'.$parameter[1].'"';
34  
-		}
35  
-
36  
-		if ($this->error)
37  
-		{
38  
-	    		$this->dest = false;
39  
-	    	}
40  
-	}
41  
-
42  
-	function PaletteGray($colors)
43  
-	{
44  
-		$colors = round(256 / ($colors-1));
45  
-		
46  
-		$this->dest = imagecreate($this->oldWidth,$this->oldHeight);
47  
-		
48  
-	   for ($y = 0; $y <$this->oldHeight; $y++)
49  
-           for ($x = 0; $x <$this->oldWidth; $x++) {
50  
-               $rgb = imagecolorat($this->source, $x, $y);
51  
-               $red  = ($rgb >> 16) & 0xFF;
52  
-               $green = ($rgb >> 8)  & 0xFF;
53  
-               $blue  = $rgb & 0xFF;
54  
-
55  
-               $gray = round((.299*$red + .587*$green + .114*$blue) / $colors) * $colors;
56  
-		if ($gray > 255) $gray = 255;
57  
-              
58  
-               // shift gray level to the left
59  
-               $grayR = $gray << 16;  // R: red
60  
-               $grayG = $gray << 8;    // G: green
61  
-               $grayB = $gray;        // B: blue
62  
-              
63  
-               // OR operation to compute gray value
64  
-               $grayColor = $grayR | $grayG | $grayB;
65  
-
66  
-               // set the pixel color
67  
-               imagesetpixel ($this->source, $x, $y, $grayColor);
68  
-               imagecolorallocate ($this->source, $grayR, $grayG, $grayB);
69  
-           }
70  
-
71  
-
72  
-   		if (!imagecopyresampled($this->dest, $this->source, 0, 0, 0, 0, $this->oldWidth, $this->oldHeight, $this->oldWidth, $this->oldHeight))
73  
-   			$this->dest = false;
74  
-	}
75  
-
76  
-}
77  
-
78  
-?>
  1
+<?php
  2
+
  3
+class Palette
  4
+{
  5
+
  6
+    var $oldWidth = 0;
  7
+    var $oldHeight = 0;
  8
+    var $source;
  9
+
  10
+    function Palette($source,$parameter)
  11
+    {
  12
+        $this->oldWidth = imagesx ($source);
  13
+        $this->oldHeight = imagesy ($source);
  14
+        $this->source = $source;
  15
+
  16
+        if ($parameter[1] == 'gray')
  17
+        {
  18
+            if ($parameter[2] > 1 && $parameter[2] < 257)
  19
+            {
  20
+                $this->PaletteGray($parameter[2]);
  21
+            }
  22
+            else
  23
+            {
  24
+                $this->PaletteGray(64);
  25
+            }
  26
+        }
  27
+        elseif ($parameter[1] == '')
  28
+        {
  29
+            $this->error[] = 'empty attribute';
  30
+        }
  31
+        else
  32
+        {
  33
+            $this->error[] = 'do not know attribute "'.$parameter[1].'"';
  34
+        }
  35
+
  36
+        if ($this->error)
  37
+        {
  38
+            $this->dest = false;
  39
+        }
  40
+    }
  41
+
  42
+    function PaletteGray($colors)
  43
+    {
  44
+        $colors = round(256 / ($colors-1));
  45
+
  46
+        $this->dest = imagecreate($this->oldWidth,$this->oldHeight);
  47
+
  48
+        for ($y = 0; $y <$this->oldHeight; $y++)
  49
+            for ($x = 0; $x <$this->oldWidth; $x++) {
  50
+                $rgb = imagecolorat($this->source, $x, $y);
  51
+                $red  = ($rgb >> 16) & 0xFF;
  52
+                $green = ($rgb >> 8)  & 0xFF;
  53
+                $blue  = $rgb & 0xFF;
  54
+
  55
+                $gray = round((.299*$red + .587*$green + .114*$blue) / $colors) * $colors;
  56
+                if ($gray > 255) $gray = 255;
  57
+
  58
+                // shift gray level to the left
  59
+                $grayR = $gray << 16;  // R: red
  60
+                $grayG = $gray << 8;    // G: green
  61
+                $grayB = $gray;        // B: blue
  62
+
  63
+                // OR operation to compute gray value
  64
+                $grayColor = $grayR | $grayG | $grayB;
  65
+
  66
+                // set the pixel color
  67
+                imagesetpixel ($this->source, $x, $y, $grayColor);
  68
+                imagecolorallocate ($this->source, $grayR, $grayG, $grayB);
  69
+            }
  70
+
  71
+
  72
+        if (!imagecopyresampled($this->dest, $this->source, 0, 0, 0, 0, $this->oldWidth, $this->oldHeight, $this->oldWidth, $this->oldHeight))
  73
+            $this->dest = false;
  74
+    }
  75
+
  76
+}
  77
+
330  filters/Resize.filter.php
... ...
@@ -1,61 +1,61 @@
1  
-<?php
2  
-
3  
-class Resize extends InstantFilter
4  
-{
5  
-
6  
-	// Security values are in pixel
7  
-	// value -1 means to skip the check
8  
-	var $security = array(
9  
-		"max-width"=>-1,
10  
-		"min-width"=>-1,
11  
-		"max-height"=>-1,
12  
-		"min-height"=>-1,
13  
-		"max-dim"=>-1, // maximum of dimension (x*y)
14  
-		"min-dim"=>-1 // minimum of dimension (x*y)
15  
-	);
16  
-
17  
-	function Resize($source, $parameter = null)
18  
-	{
19  
-
20  
-    	$oldWidth = imagesx ($source);
21  
-    	$oldHeight = imagesy ($source);
22  
-    	$startX = 0;
23  
-    	$startY = 0;
24  
-
25  
-    	if ($parameter[1] == 'square')
26  
-    	{
27  
-    		if ($oldWidth != $oldHeight)
28  
-    		{
29  
-    			if ($oldWidth > $oldHeight)
30  
-    			{
31  
-    				$temp = $oldWidth - $oldHeight;
32  
-    				$startX = $startX + intval($temp/2);
33  
-    				$oldWidth = $oldWidth - $temp;
34  
-    			}
35  
-    			else
36  
-    			{
37  
-    				$temp = $oldHeight - $oldWidth;
38  
-    				$startY = $startY + intval($temp/2);
39  
-    				$oldHeight = $oldHeight - $temp;
40  
-    			}
41  
-    		}
42  
-
43  
-            $newWidth = $parameter[2];
44  
-            $newHeight = $parameter[2];
45  
-
46  
-    		// security check of dimensions
47  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
48  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
49  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
50  
-    	}
51  
-    	elseif ($parameter[1] == 'cutout')
52  
-    	{
53  
-            $newWidth = $parameter[2];
  1
+<?php
  2
+
  3
+class Resize extends InstantFilter
  4
+{
  5
+
  6
+    // Security values are in pixel
  7
+    // value -1 means to skip the check
  8
+    var $security = array(
  9
+        "max-width"=>-1,
  10
+        "min-width"=>-1,
  11
+        "max-height"=>-1,
  12
+        "min-height"=>-1,
  13
+        "max-dim"=>-1, // maximum of dimension (x*y)
  14
+        "min-dim"=>-1 // minimum of dimension (x*y)
  15
+    );
  16
+
  17
+    function Resize($source, $parameter = null)
  18
+    {
  19
+
  20
+        $oldWidth = imagesx ($source);
  21
+        $oldHeight = imagesy ($source);
  22
+        $startX = 0;
  23
+        $startY = 0;
  24
+
  25
+        if ($parameter[1] == 'square')
  26
+        {
  27
+            if ($oldWidth != $oldHeight)
  28
+            {
  29
+                if ($oldWidth > $oldHeight)
  30
+                {
  31
+                    $temp = $oldWidth - $oldHeight;
  32
+                    $startX = $startX + intval($temp/2);
  33
+                    $oldWidth = $oldWidth - $temp;
  34
+                }
  35
+                else
  36
+                {
  37
+                    $temp = $oldHeight - $oldWidth;
  38
+                    $startY = $startY + intval($temp/2);
  39
+                    $oldHeight = $oldHeight - $temp;
  40
+                }
  41
+            }
  42
+
  43
+            $newWidth = $parameter[2];
  44
+            $newHeight = $parameter[2];
  45
+
  46
+            // security check of dimensions
  47
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  48
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  49
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  50
+        }
  51
+        elseif ($parameter[1] == 'cutout')
  52
+        {
  53
+            $newWidth = $parameter[2];
54 54
             $newHeight = $parameter[3];
55  
-            
  55
+
56 56
             $oldRatio = $oldWidth/$oldHeight;
57 57
             $newRatio = $newWidth/$newHeight;
58  
-            
  58
+
59 59
             if ($oldRatio != $newRatio)
60 60
             {
61 61
                 if ($oldRatio > $newRatio)
@@ -70,114 +70,112 @@ function Resize($source, $parameter = null)
70 70
                     $startY = intval($temp/2);
71 71
                     $oldHeight = intval($oldHeight - $temp);
72 72
                 }
73  
-            }
74  
-    	    
75  
-    		// security check of dimensions
76  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
77  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
78  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
79  
-    	}
80  
-    	elseif ($parameter[1] == 'exact')
81  
-    	{
82  
-            $newWidth = $parameter[2];
83  
-            $newHeight = $parameter[3];
84  
-
85  
-    		// security check of dimensions
86  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
87  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
88  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
89  
-    	}
90  
-    	elseif ($parameter[1] == 'min')
91  
-    	{
92  
-            if ($oldWidth < $oldHeight)
93  
-            {
94  
-            	$newWidth = $parameter[2];
95  
-            	$newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
96  
-            }
97  
-            else
98  
-            {
99  
-            	$newHeight = $parameter[2];
100  
-            	$newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
101  
-            }
102  
-    		// security check of dimensions
103  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
104  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
105  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
106  
-    	}
107  
-    	elseif ($parameter[1] == 'max')
108  
-    	{
109  
-            if ($oldWidth > $oldHeight)
110  
-            {
111  
-            	$newWidth = $parameter[2];
112  
-            	$newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
113  
-            }
114  
-            else
115  
-            {
116  
-            	$newHeight = $parameter[2];
117  
-            	$newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
118  
-            }
119  
-    		// security check of dimensions
120  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
121  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
122  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
123  
-    	}
124  
-    	elseif ($parameter[1] == 'width')
125  
-    	{
126  
-           	$newWidth = $parameter[2];
127  
-           	$newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
128  
-    		// security check of dimensions
129  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
130  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
131  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
132  
-    	}
133  
-    	elseif ($parameter[1] == 'height')
134  
-    	{
135  
-          	$newHeight = $parameter[2];
136  
-           	$newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
137  
-    		// security check of dimensions
138  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
139  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
140  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
141  
-    	}
142  
-    	elseif ($parameter[1] == 'dim')
143  
-    	{
144  
-          	$f = sqrt(($oldHeight*$oldWidth)/$parameter[2]);
145  
-          	$newHeight = intval($oldHeight/$f);
146  
-           	$newWidth = intval($oldWidth/$f);;
147  
-    		// security check of dimensions
148  
-    		$this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
149  
-    		$this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
150  
-    		$this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
151  
-    	}
152  
-    	elseif ($parameter[1] == '')
153  
-    	{
154  
-    		$this->pushError('no attributes');
155  
-    	}
156  
-    	else
157  
-    	{
158  
-    		$this->pushError('wrong attribute '.$parameter[1]);
159  
-    	}
160  
-
161  
-		if (count($this->error) == 0)
162  
-		{
163  
-    		$this->dest = imagecreatetruecolor($newWidth, $newHeight);
164  
-    		if (!imagecopyresampled($this->dest, $source, 0, 0, $startX, $startY, $newWidth, $newHeight, $oldWidth, $oldHeight))
165  
-    		{	
166  
-    			$this->dest = false;
167  
-    			$this->pushError('cannot apply filter');
168  
-    		}
169  
-    	}
170  
-    	else
171  
-    	{
172  
-    		$this->dest = false;
173  
-    	}
174  
-	}
175  
-	
176  
-	function checkSecurity($value, $min, $max)
177  
-	{
178  
-		if ($min > 0 && $value < $min) $this->pushError('security issue, dimension fault ('.$value.' < '.$min.')');
179  
-		if ($max > 0 && $value > $max) $this->pushError('security issue, dimension fault ('.$value.' > '.$max.')');
180  
-	}
181  
-}
182  
-
183  
-?>
  73
+            }
  74
+
  75
+            // security check of dimensions
  76
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  77
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  78
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  79
+        }
  80
+        elseif ($parameter[1] == 'exact')
  81
+        {
  82
+            $newWidth = $parameter[2];
  83
+            $newHeight = $parameter[3];
  84
+
  85
+            // security check of dimensions
  86
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  87
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  88
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  89
+        }
  90
+        elseif ($parameter[1] == 'min')
  91
+        {
  92
+            if ($oldWidth < $oldHeight)
  93
+            {
  94
+                $newWidth = $parameter[2];
  95
+                $newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
  96
+            }
  97
+            else
  98
+            {
  99
+                $newHeight = $parameter[2];
  100
+                $newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
  101
+            }
  102
+            // security check of dimensions
  103
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  104
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  105
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  106
+        }
  107
+        elseif ($parameter[1] == 'max')
  108
+        {
  109
+            if ($oldWidth > $oldHeight)
  110
+            {
  111
+                $newWidth = $parameter[2];
  112
+                $newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
  113
+            }
  114
+            else
  115
+            {
  116
+                $newHeight = $parameter[2];
  117
+                $newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
  118
+            }
  119
+            // security check of dimensions
  120
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  121
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  122
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  123
+        }
  124
+        elseif ($parameter[1] == 'width')
  125
+        {
  126
+            $newWidth = $parameter[2];
  127
+            $newHeight = intval(($oldHeight/$oldWidth)*$newWidth);
  128
+            // security check of dimensions
  129
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  130
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  131
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  132
+        }
  133
+        elseif ($parameter[1] == 'height')
  134
+        {
  135
+            $newHeight = $parameter[2];
  136
+            $newWidth = intval(($oldWidth/$oldHeight)*$newHeight);
  137
+            // security check of dimensions
  138
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  139
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  140
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  141
+        }
  142
+        elseif ($parameter[1] == 'dim')
  143
+        {
  144
+            $f = sqrt(($oldHeight*$oldWidth)/$parameter[2]);
  145
+            $newHeight = intval($oldHeight/$f);
  146
+            $newWidth = intval($oldWidth/$f);;
  147
+            // security check of dimensions
  148
+            $this->checkSecurity($newWidth,$this->security['min-width'],$this->security['max-width']);
  149
+            $this->checkSecurity($newHeight,$this->security['min-height'],$this->security['max-height']);
  150
+            $this->checkSecurity($newWidth*$newHeight,$this->security['min-dim'],$this->security['max-dim']);
  151
+        }
  152
+        elseif ($parameter[1] == '')
  153
+        {
  154
+            $this->pushError('no attributes');
  155
+        }
  156
+        else
  157
+        {
  158
+            $this->pushError('wrong attribute '.$parameter[1]);
  159
+        }
  160
+
  161
+        if (count($this->error) == 0)
  162
+        {
  163
+            $this->dest = imagecreatetruecolor($newWidth, $newHeight);
  164
+            if (!imagecopyresampled($this->dest, $source, 0, 0, $startX, $startY, $newWidth, $newHeight, $oldWidth, $oldHeight))
  165
+            {
  166
+                $this->dest = false;
  167
+                $this->pushError('cannot apply filter');
  168
+            }
  169
+        }
  170
+        else
  171
+        {
  172
+            $this->dest = false;
  173
+        }
  174
+    }
  175
+
  176
+    function checkSecurity($value, $min, $max)
  177
+    {
  178
+        if ($min > 0 && $value < $min) $this->pushError('security issue, dimension fault ('.$value.' < '.$min.')');
  179
+        if ($max > 0 && $value > $max) $this->pushError('security issue, dimension fault ('.$value.' > '.$max.')');
  180
+    }
  181
+}
1  instantpicture.conf.php
@@ -35,4 +35,3 @@
35 35
 
36 36
 # User Preferences --- End
37 37
 
38  
-?>
805  instantpicture.inc.php
@@ -2,420 +2,419 @@
2 2
 
3 3
 function instantErrorHandler ($errno, $errstr, $errfile, $errline)
4 4
 {
5  
-	global $errormsg;
6  
-	if ($errno != E_NOTICE)
7  
-		$errormsg[] = 'PHP '.PHP_VERSION.': '.$errstr.' in '.$errfile.' on line '.$errline. ' ['.$errno.']';
  5
+    global $errormsg;
  6
+    if ($errno != E_NOTICE)
  7
+        $errormsg[] = 'PHP '.PHP_VERSION.': '.$errstr.' in '.$errfile.' on line '.$errline. ' ['.$errno.']';
8 8
 }
9 9
 
10 10
 function cacheName($file,$filters,$cachetype,$cachefilterorder)
11 11
 {
12  
-	$filename = basename($file);
13  
-	$foldername = str_replace($_SERVER['DOCUMENT_ROOT'].'/','',dirname($file));
14  
-	if ($cachefilterorder === false) sort($filters, SORT_STRING);
15  
-	$filters = implode('/',$filters);
16  
-	
17  
-	if ($cachetype == 'hash')
18  
-	{
19  
-		return md5($foldername.'/'.$filename.'/'.$filters);
20  
-	}
21  
-	elseif ($cachetype == 'long')
22  
-	{
23  
-		return str_replace(array('/','.'),array('_','_'),$foldername.'/'.$filename.'/'.$filters);
24  
-	}
25  
-	elseif ($cachetype == 'mixed')
26  
-	{
27  
-		return str_replace(array('/','.'),array('_','_'),$filename.'_'.md5($foldername.'/'.$filters));
28  
-	}
29  
-	else
30  
-	{
31  
-		return false;
32  
-	}
  12
+    $filename = basename($file);
  13
+    $foldername = str_replace($_SERVER['DOCUMENT_ROOT'].'/','',dirname($file));
  14
+    if ($cachefilterorder === false) sort($filters, SORT_STRING);
  15
+    $filters = implode('/',$filters);
  16
+
  17
+    if ($cachetype == 'hash')
  18
+    {
  19
+        return md5($foldername.'/'.$filename.'/'.$filters);
  20
+    }
  21
+    elseif ($cachetype == 'long')
  22
+    {
  23
+        return str_replace(array('/','.'),array('_','_'),$foldername.'/'.$filename.'/'.$filters);
  24
+    }
  25
+    elseif ($cachetype == 'mixed')
  26
+    {
  27
+        return str_replace(array('/','.'),array('_','_'),$filename.'_'.md5($foldername.'/'.$filters));
  28
+    }
  29
+    else
  30
+    {
  31
+        return false;
  32
+    }
33 33
 }
34 34
 
35 35
 class InstantPicture
36 36
 {
37  
-	var $imgSrc = '';
38  
-	var $imgType = null;
39  
-	var $fileToFlush = null;
40  
-
41  
-	var $quality = 80;
42  
-	
43  
-	var $error = array();
44  
-	var $debug = 0; // default: debugging off
45  
-	var $debugtype = 'jpg';
46  
-		
47  
-	
48  
-	function InstantPicture($config=array(),$imagefile=null,$filters=array())
49  
-	{
50  
-		
51  
-		if ($config['quality']) $this->quality = $config['quality'];
52  
-		if ($config['debug']) $this->debug = $config['debug'];
53  
-		if ($config['debugtype']) $this->debugtype = $config['debugtype'];
54  
-		return $this->apply($imagefile,$filters);
55  
-	}
56  
-	
57  
-	function setImageType($type)
58  
-	{
59  
-		$this->imgType = $type;
60  
-	}
61  
-	
62  
-	function getImageTypeByFile($file)
63  
-	{
64  
-		// check if file exists
65  
-		if (is_file($file))
66  
-		{
67  
-			// file exists
68  
-			
69  
-			// get image type
70  
-			$info = getimagesize($file);
71  
-			$type = null; // set to null per default for unsupported types
72  
-			if ($info[2] == 1) $type = 'gif';
73  
-			if ($info[2] == 2) $type = 'jpg';
74  
-			if ($info[2] == 3) $type = 'png';
75  
-			
76  
-			// getimagesize cannot read type
77  
-			// fallback to getting type by file extension
78  
-			if ($type===null) $type = strtolower(substr($file,-3));
79  
-			
80  
-			return $type;
81  
-		}
82  
-		else
83  
-		{
84  
-			$this->error[] = 'InstantImage: file does not exist ('.$file.')';
85  
-			return false;
86  
-		}
87  
-	}
88  
-	
89  
-	function imageOpenFromFile($file)
90  
-	{
91  
-		// get Image type
92  
-		if ($this->imgType === null)
93  
-		{
94  
-			$imgType = $this->getImageTypeByFile($file);
95  
-		}
96  
-		else
97  
-		{
98  
-			$imgType = $this->imgType;
99  
-		}
100  
-		// 1. Check Image Type
101  
-		if ($imgType === 'gif' || $imgType === 'jpg' || $imgType === 'png')
102  
-		{
103  
-			// supported image type
104  
-			
105  
-			// save type
106  
-			if ($this->imgType == null) $this->imgType = $imgType;
107  
-			
108  
-			// 2. Check if file exists
109  
-			if (is_file($file))
110  
-			{
111  
-				// valid file
112  
-				
113  
-				// 3. Check server (PHP) support for image type
114  
-				$support = false;
115  
-				if ($this->imgType == 'gif' && (ImageTypes() & IMG_GIF)) $support = true;
116  
-				if ($this->imgType == 'jpg' && (ImageTypes() & IMG_JPG)) $support = true;
117  
-				if ($this->imgType == 'png' && (ImageTypes() & IMG_PNG)) $support = true;
118  
-
119  
-				if ($support === true)
120  
-				{
121  
-					// PHP supports image type
122  
-					
123  
-					// 4. Open image as source
124  
-					$src = '';
125  
-					if ($this->imgType === 'gif') $src = imagecreatefromgif($file);
126  
-					if ($this->imgType === 'jpg') $src = imagecreatefromjpeg($file);
127  
-					if ($this->imgType === 'png') $src = imagecreatefrompng($file);
128  
-					// check for errors
129  
-					if ($src != '')
130  
-					{
131  
-						// no error
132  
-						$this->imgSrc = $src;
133  
-						return true;
134  
-					}
135  
-					else
136  
-					{
137  
-						// error, cannot open image
138  
-						
139  
-						$this->error[] = 'InstantImage: cannot open image as source';
140  
-						return false;
141  
-					}
142  
-				}
143  
-				else
144  
-				{
145  
-					// PHP don't support image type (maybe wrong GD lib)
146  
-					$this->error[] = 'InstantImage: your server (PHP '.phpversion().') does not support '.$this->imgType;
147  
-					return false;
148  
-				}
149  
-				
150  
-			}
151  
-			else
152  
-			{
153  
-				// does not exist or is not a file
154  
-				$this->error[] = 'InstantImage: file does not exist ('.$file.')';
155  
-				return false;
156  
-			}
157  
-		}
158  
-		else
159  
-		{
160  
-			// wrong (unsupported) image type
161  
-			
162  
-			if ($imgType !== false) $this->error[] = 'InstantImage: unsupported image type';
163  
-			return false;
164  
-		}
165  
-		
166  
-	}
167  
-	
168  
-	function imageSaveToFile($file,$quality=0)
169  
-	{
170  
-		// get preferences for jpeg quality
171  
-		if ($quality == 0) $quality = $this->quality;
172  
-		
173  
-		if (count($this->error) == 0)
174  
-		{
175  
-			// no errors, try to save image
176  
-			if ($this->imgType == 'gif') $saved = imagegif($this->imgSrc,$file);
177  
-			if ($this->imgType == 'jpg') $saved = imagejpeg($this->imgSrc,$file,$quality);
178  
-			if ($this->imgType == 'png') $saved = imagepng($this->imgSrc,$file);
179  
-			
180  
-			if (!$saved)
181  
-			{
182  
-				// image was not written
183  
-				$this->error[] = 'InstantImage: cannot write image to file';
184  
-				return false;
185  
-			}
186  
-			else
187  
-			{
188  
-				$this->fileToFlush = $file;
189  
-				return true;
190  
-			}
191  
-		}
192  
-		else
193  
-		{
194  
-			// errors, doesn't make sense to save the wrong image
195  
-			$this->error[] = 'InstantImage: do not save the image because of errors';
196  
-			return false;
197  
-		}
198  
-	}
199  
-	
200  
-	function applyFilter($filter)
201  
-	{
202  
-		// only by zero pre errors
203  
-		if (count($this->error) == 0)
204  
-		{
205  
-			// split up filter name and filter configuration
206  
-	        $filterInfos = explode('-',$filter);
207  
-	        eval("\$temp = new ".$filterInfos[0]." (\$this->imgSrc,\$filterInfos);");
208  
-	        if ($temp->dest !== false)
209  
-	        {
210  
-	        	// filter was applied
211  
-	        	// $filterUsed[] = $filterItem['value'];
212  
-	        	$this->imgSrc = $temp->dest;
213  
-	        	return true;
214  
-	        }
215  
-	        else
216  
-	        {
217  
-	        	// filter was not applied, save filter errors
218  
-	        	foreach($temp->error as $error)
219  
-	        	{
220  
-	        		$this->error[] = $filterInfos[0].': '.$error;
221  
-	        	}
222  
-	        	return false;
223  
-	        }
224  
-		}
225  
-	}
226  
-	
227  
-	function applyFilters($filters)
228  
-	{
229  
-		foreach ($filters as $filter)
230  
-		{
231  
-			$r = $this->applyFilter($filter);
232  
-		}
233  
-		return $r;
234  
-	}
235  
-	
236  
-	function apply($imagefile,$filters)
237  
-	{
238  
-		if ($imagefile !== null)
239  
-		{
240  
-			if ($this->imageOpenFromFile($imagefile))
241  
-			{
242  
-				return $this->applyFilters($filters);
243  
-			}
244  
-			else
245  
-			{
246  
-				return false;
247  
-			}
248  
-		}
249  
-	}
250  
-	
251  
-	function flush($file=null,$quality=0)
252  
-	{
253  
-		if ($quality==0) $quality = $this->quality;
254  
-		
255  
-		$source = '';
256  
-		
257  
-		if (count($this->error)>0)
258  
-		{
259  
-			$this->flushError();
260  
-		}
261  
-		else
262  
-		{
263  
-			// flush(void)
264  
-			if ($file === null) $file = $this->fileToFlush;
265  
-			// fallback to image resource when no file is specified
266  
-			if ($file === null) $source = $this->imgSrc;
267  
-			
268  
-			if ($file != null)
269  
-			{
270  
-				// check for file
271  
-				if (is_file($file))
272  
-				{
273  
-					$type = $this->getImageTypeByFile($file);
274  
-					$this->sendHeader($type);
275  
-					return readfile($file);
276  
-				}
277  
-				else
278  
-				{
279  
-					$this->error[] = 'InstantImage: no image to flush, cannot find file '.$file;
280  
-					$this->flushError();
281  
-					return false;
282  
-				}
283  
-			}
284  
-			elseif ($source != '')
285  
-			{
286  
-				// check for image type
287  
-				if ($this->imgType != null)
288  
-				{
289  
-					if ($this->imgType == 'gif')
290  
-					{
291  
-						$this->sendHeader($this->imgType);
292  
-						return imagegif($this->imgSrc);	
293  
-					}
294  
-					elseif ($this->imgType == 'jpg')
295  
-					{
296  
-						$this->sendHeader($this->imgType);
297  
-						return imagejpeg($this->imgSrc,null,$quality);
298  
-					}
299  
-					elseif ($this->imgType == 'png')
300  
-					{
301  
-						$this->sendHeader($this->imgType);
302  
-						return imagepng($this->imgSrc);
303  
-					}
304  
-					else
305  
-					{
306  
-						$this->error[] = 'InstantImage: cannot flush image source, unsupported image type';
307  
-						$this->flushError();
308  
-						return false;
309  
-					}
310  
-				}
311  
-				else
312  
-				{
313  
-					$this->error[] = 'InstantImage: cannot flush image, do not know image type';
314  
-					$this->flushError();
315  
-					return false;
316  
-				}
317  
-			}
318  
-			else
319  
-			{
320  
-				// no file or source specified
321  
-				$this->error[] = 'InstantImage: no image to flush';
322  
-				$this->flushError();
323  
-				return false;
324  
-			}
325  
-		}
326  
-	}
327  
-	
328  
-	function sendHeader($type)
329  
-	{
330  
-		if ($type == 'gif') header("Content-type: image/gif");
331  
-		if ($type == 'jpg') header("Content-type: image/jpeg");
332  
-		if ($type == 'png') header("Content-type: image/png");
333  
-		if ($type == '404') header("HTTP/1.0 404 Not Found");
334  
-		return true;
335  
-	}
336  
-	
337  
-	function flushError($type=null)
338  
-	{
339  
-		if ($type===null) $type = $this->debugtype;
340  
-
341  
-		// only show error when debugging is on
342  
-		if ($this->debug == 0)
343  
-		{
344  
-			// no debugging, send 404 (not found) instead
345  
-			$this->sendHeader('404');
346  
-		}
347  
-		else
348  
-		{
349  
-			// show errors in image
350  
-			// using some code by dev at numist dot net
351  
-			// see original: http://de3.php.net/imagefontheight#49340
352  
-			
353  
-			// init
354  
-			$errors = array_merge(array_unique($this->error)); // get all errors
355  
-			$font = 2; // define font
356  
-			// width and height for one font char
357  
-			$text_width = imagefontwidth($font);
358  
-			$text_height = imagefontheight($font);
359  
-   			// image height depends on number of errors
360  
-			$height = count($errors) * $text_height;
361  
-			// image width depends on error with most chars
362  
-			$errorstrlen = 0;
363  
-			foreach ($errors as $error)
364  
-			{
365  
-				if (strlen($error) > $errorstrlen)
366  
-				{
367  
-					$errorstrlen = strlen($error);
368  
-				}
369  
-			}
370  
-			$width = $errorstrlen * $text_width;
371  
-
372  
-   			// create image with dimensions to fit text
373  
-   			// plus two extra rows/columns for border
374  
-			$errorImg = imagecreatetruecolor($width+(2*$text_width),$height+(2*$text_height));
375  
-
376  
-			if($errorImg)
377  
-			{
378  
-				// image creation success
379  
-
380  
-				// color
381  
-				$text_c