Documentation is available at class.imgresize.php
1 <?php
2 /*
3 METAjour version 1.6 - Content Management System
4 Copyright (C) 2003 IPW Systems A/S
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 $Id: class.imgresize.php,v 1.2 2004/10/11 00:10:30 jan Exp $
21
22 */
23 class imgresize {
24 var $img;
25
26 function imgresize($imgfile, $format) {
27 $this->img['ok'] = true;
28 //detect image format
29 # $this->img["format"]=ereg_replace(".*\.(.*)$","\\1",$imgfile);
30 # $this->img["format"]=strtoupper($this->img["format"]);
31 if ($format == "image/pjpeg" || $format == "image/jpeg" ) {
32 //JPEG
33 $this->img["format"]="JPEG";
34 $this->img["src"] = ImageCreateFromJPEG ($imgfile);
35 } elseif ($format == "image/png" ) {
36 //PNG
37 $this->img["format"]="PNG";
38 $this->img["src"] = ImageCreateFromPNG ($imgfile);
39 # GIF IS UNFORTUNATELY NOT SUPPORTED BY ALL VERSIONS OF GD BECAUS OF PATENT ISSUES
40 # } elseif ($format == "image/gif" ) {
41 # //GIF
42 # $this->img["format"]="GIF";
43 # $this->img["src"] = ImageCreateFromGIF ($imgfile);
44 } elseif ($format == "image/wbmp" ) {
45 //WBMP
46 $this->img["format"]="WBMP";
47 $this->img["src"] = ImageCreateFromWBMP ($imgfile);
48 } else {
49 //DEFAULT
50 $this->img['ok'] = false;
51 }
52 if ($this->img['ok']) {
53 @$this->img["width"] = imagesx($this->img["src"]);
54 @$this->img["height"] = imagesy($this->img["src"]);
55 //default quality jpeg
56 $this->img["quality"]=75;
57 }
58 }
59
60 function size_height($size=100)
61 {
62 //height
63 $this->img["height_thumb"]=$size;
64 @$this->img["width_thumb"] = ($this->img["height_thumb"]/$this->img["height"])*$this->img["width"];
65 }
66
67 function size_width($size=100)
68 {
69 //width
70 $this->img["width_thumb"]=$size;
71 @$this->img["height_thumb"] = ($this->img["width_thumb"]/$this->img["width"])*$this->img["height"];
72 }
73
74 function size_auto($size=100)
75 {
76 //size
77 if ($this->img["width"]>=$this->img["height"]) {
78 $this->img["width_thumb"]=$size;
79 @$this->img["height_thumb"] = ($this->img["width_thumb"]/$this->img["width"])*$this->img["height"];
80 } else {
81 $this->img["height_thumb"]=$size;
82 @$this->img["width_thumb"] = ($this->img["height_thumb"]/$this->img["height"])*$this->img["width"];
83 }
84 }
85
86 function jpeg_quality($quality=75)
87 {
88 //jpeg quality
89 $this->img["quality"]=$quality;
90 }
91
92 function show()
93 {
94 //show thumb
95 @Header("Content-Type: image/".$this->img["format"]);
96
97 /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
98 if (function_exists('imagecreatetruecolor')) {
99 $this->img["des"] = ImageCreateTrueColor($this->img["width_thumb"],$this->img["height_thumb"]);
100 } else {
101 $this->img["des"] = ImageCreate($this->img["width_thumb"],$this->img["height_thumb"]);
102 }
103 @imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["width_thumb"], $this->img["height_thumb"], $this->img["width"], $this->img["height"]);
104
105 if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
106 //JPEG
107 imageJPEG($this->img["des"],"",$this->img["quality"]);
108 } elseif ($this->img["format"]=="PNG") {
109 //PNG
110 imagePNG($this->img["des"]);
111 } elseif ($this->img["format"]=="GIF") {
112 //GIF
113 imageGIF($this->img["des"]);
114 } elseif ($this->img["format"]=="WBMP") {
115 //WBMP
116 imageWBMP($this->img["des"]);
117 }
118 }
119
120 function save($save="")
121 {
122 //save thumb
123 if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]);
124 /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/
125 if (function_exists('imagecreatetruecolor')) {
126 $this->img["des"] = ImageCreateTrueColor($this->img["width_thumb"],$this->img["height_thumb"]);
127 } else {
128 $this->img["des"] = ImageCreate($this->img["width_thumb"],$this->img["height_thumb"]);
129 }
130 @imagecopyresized ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["width_thumb"], $this->img["height_thumb"], $this->img["width"], $this->img["height"]);
131
132 if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {
133 //JPEG
134 imageJPEG($this->img["des"],"$save",$this->img["quality"]);
135 } elseif ($this->img["format"]=="PNG") {
136 //PNG
137 imagePNG($this->img["des"],"$save");
138 } elseif ($this->img["format"]=="GIF") {
139 //GIF
140 imageGIF($this->img["des"],"$save");
141 } elseif ($this->img["format"]=="WBMP") {
142 //WBMP
143 imageWBMP($this->img["des"],"$save");
144 }
145 }
146 }
147 ?>
Documentation generated on Thu, 9 Jun 2005 06:51:40 +0200 by phpDocumentor 1.2.3