Browse Source

Added entry for classes/imgsize.php

pecesama 17 years ago
parent
commit
1304ab1eee
2 changed files with 99 additions and 96 deletions
  1. 94 94
      classes/imgsize.php
  2. 5 2
      entry.php

+ 94 - 94
classes/imgsize.php View File

@@ -1,94 +1,94 @@
1
-<?php
2
- if(!defined('entry') || !entry) die('Not a valid page');
3
-header ("Content-type: image/jpeg");
4
-header('Cache-Control: max-age=172800, must-revalidate');
5
-header('Expires: ' . date('r', time()+120));
6
-/*
7
-JPEG / PNG Image Resizer
8
-Parameters (passed via URL):
9
-
10
-img = path / url of jpeg or png image file
11
-
12
-percent = if this is defined, image is resized by it's
13
-          value in percent (i.e. 50 to divide by 50 percent)
14
-
15
-w = image width
16
-
17
-h = image height
18
-
19
-constrain = if this is parameter is passed and w and h are set
20
-            to a size value then the size of the resulting image
21
-            is constrained by whichever dimension is smaller
22
-
23
-Requires the PHP GD Extension
24
-
25
-Outputs the resulting image in JPEG Format
26
-
27
-By: Michael John G. Lopez - www.sydel.net
28
-Filename : imgsize.php
29
-*/
30
-
31
-$img = $_GET['img'];
32
-$percent = $_GET['percent'];
33
-$constrain = $_GET['constrain'];
34
-$w = $_GET['w'];
35
-$h = $_GET['h'];
36
-
37
-// get image size of img
38
-$x = @getimagesize($img);
39
-// image width
40
-$sw = $x[0];
41
-// image height
42
-$sh = $x[1];
43
-
44
-if ($percent > 0) {
45
-	// calculate resized height and width if percent is defined
46
-	$percent = $percent * 0.01;
47
-	$w = $sw * $percent;
48
-	$h = $sh * $percent;
49
-} else {
50
-	if (isset ($w) AND !isset ($h)) {
51
-		// autocompute height if only width is set
52
-		$h = (100 / ($sw / $w)) * .01;
53
-		$h = @round ($sh * $h);
54
-	} elseif (isset ($h) AND !isset ($w)) {
55
-		// autocompute width if only height is set
56
-		$w = (100 / ($sh / $h)) * .01;
57
-		$w = @round ($sw * $w);
58
-	} elseif (isset ($h) AND isset ($w) AND isset ($constrain)) {
59
-		// get the smaller resulting image dimension if both height
60
-		// and width are set and $constrain is also set
61
-		$hx = (100 / ($sw / $w)) * .01;
62
-		$hx = @round ($sh * $hx);
63
-
64
-		$wx = (100 / ($sh / $h)) * .01;
65
-		$wx = @round ($sw * $wx);
66
-
67
-		if ($hx < $h) {
68
-			$h = (100 / ($sw / $w)) * .01;
69
-			$h = @round ($sh * $h);
70
-		} else {
71
-			$w = (100 / ($sh / $h)) * .01;
72
-			$w = @round ($sw * $w);
73
-		}
74
-	}
75
-}
76
-
77
-$im = @ImageCreateFromJPEG ($img) or // Read JPEG Image
78
-$im = @ImageCreateFromPNG ($img) or // or PNG Image
79
-$im = @ImageCreateFromGIF ($img) or // or GIF Image
80
-$im = false; // If image is not JPEG, PNG, or GIF
81
-
82
-if (!$im) {
83
-	// We get errors from PHP's ImageCreate functions...
84
-	// So let's echo back the contents of the actual image.
85
-	readfile ($img);
86
-} else {
87
-	// Create the resized image destination
88
-	$thumb = @ImageCreateTrueColor ($w, $h);
89
-	// Copy from image source, resize it, and paste to image destination
90
-	@ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh);
91
-	// Output resized image
92
-	@ImageJPEG ($thumb);
93
-}
94
-?>
1
+<?php
2
+ if(!defined('entry')) define('entry',true);
3
+header ("Content-type: image/jpeg");
4
+header('Cache-Control: max-age=172800, must-revalidate');
5
+header('Expires: ' . date('r', time()+120));
6
+/*
7
+JPEG / PNG Image Resizer
8
+Parameters (passed via URL):
9
+
10
+img = path / url of jpeg or png image file
11
+
12
+percent = if this is defined, image is resized by it's
13
+          value in percent (i.e. 50 to divide by 50 percent)
14
+
15
+w = image width
16
+
17
+h = image height
18
+
19
+constrain = if this is parameter is passed and w and h are set
20
+            to a size value then the size of the resulting image
21
+            is constrained by whichever dimension is smaller
22
+
23
+Requires the PHP GD Extension
24
+
25
+Outputs the resulting image in JPEG Format
26
+
27
+By: Michael John G. Lopez - www.sydel.net
28
+Filename : imgsize.php
29
+*/
30
+
31
+$img = $_GET['img'];
32
+$percent = $_GET['percent'];
33
+$constrain = $_GET['constrain'];
34
+$w = $_GET['w'];
35
+$h = $_GET['h'];
36
+
37
+// get image size of img
38
+$x = @getimagesize($img);
39
+// image width
40
+$sw = $x[0];
41
+// image height
42
+$sh = $x[1];
43
+
44
+if ($percent > 0) {
45
+	// calculate resized height and width if percent is defined
46
+	$percent = $percent * 0.01;
47
+	$w = $sw * $percent;
48
+	$h = $sh * $percent;
49
+} else {
50
+	if (isset ($w) AND !isset ($h)) {
51
+		// autocompute height if only width is set
52
+		$h = (100 / ($sw / $w)) * .01;
53
+		$h = @round ($sh * $h);
54
+	} elseif (isset ($h) AND !isset ($w)) {
55
+		// autocompute width if only height is set
56
+		$w = (100 / ($sh / $h)) * .01;
57
+		$w = @round ($sw * $w);
58
+	} elseif (isset ($h) AND isset ($w) AND isset ($constrain)) {
59
+		// get the smaller resulting image dimension if both height
60
+		// and width are set and $constrain is also set
61
+		$hx = (100 / ($sw / $w)) * .01;
62
+		$hx = @round ($sh * $hx);
63
+
64
+		$wx = (100 / ($sh / $h)) * .01;
65
+		$wx = @round ($sw * $wx);
66
+
67
+		if ($hx < $h) {
68
+			$h = (100 / ($sw / $w)) * .01;
69
+			$h = @round ($sh * $h);
70
+		} else {
71
+			$w = (100 / ($sh / $h)) * .01;
72
+			$w = @round ($sw * $w);
73
+		}
74
+	}
75
+}
76
+
77
+$im = @ImageCreateFromJPEG ($img) or // Read JPEG Image
78
+$im = @ImageCreateFromPNG ($img) or // or PNG Image
79
+$im = @ImageCreateFromGIF ($img) or // or GIF Image
80
+$im = false; // If image is not JPEG, PNG, or GIF
81
+
82
+if (!$im) {
83
+	// We get errors from PHP's ImageCreate functions...
84
+	// So let's echo back the contents of the actual image.
85
+	readfile ($img);
86
+} else {
87
+	// Create the resized image destination
88
+	$thumb = @ImageCreateTrueColor ($w, $h);
89
+	// Copy from image source, resize it, and paste to image destination
90
+	@ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh);
91
+	// Output resized image
92
+	@ImageJPEG ($thumb);
93
+}
94
+?>

+ 5 - 2
entry.php View File

@@ -2,8 +2,10 @@
2 2
  if(!defined('entry') || !entry) die('Not a valid page');
3 3
 /*
4 4
  * Created on Sep 15, 2007
5
+ * Modified on Sep 22, 2007
5 6
  *
6
- * Known Entry Points 
7
+ * Known Entry Points
8
+ * api.php
7 9
  * install.php
8 10
  * index.php
9 11
  * login.php
@@ -17,7 +19,8 @@
17 19
  * admin/admin.php
18 20
  * admin/comments.php
19 21
  * admin/users.php
20
- *admin/form.autosave.php
22
+ * admin/form.autosave.php
23
+ * classes/imgsize.php 
21 24
  */
22 25
 
23 26