3 if(! class_exists("Photo")) {
10 public function __construct($data) {
11 $this->image = @imagecreatefromstring($data);
12 if($this->image !== FALSE) {
13 $this->width = imagesx($this->image);
14 $this->height = imagesy($this->image);
18 public function __destruct() {
20 imagedestroy($this->image);
23 public function getWidth() {
27 public function getHeight() {
31 public function getImage() {
35 public function scaleImage($max) {
37 $width = $this->width;
38 $height = $this->height;
40 $dest_width = $dest_height = 0;
42 if((! $width)|| (! $height))
45 if($width > $max && $height > $max) {
46 if($width > $height) {
48 $dest_height = intval(( $height * $max ) / $width);
51 $dest_width = intval(( $width * $max ) / $height);
58 $dest_height = intval(( $height * $max ) / $width);
61 if( $height > $max ) {
62 $dest_width = intval(( $width * $max ) / $height);
67 $dest_height = $height;
73 $dest = imagecreatetruecolor( $dest_width, $dest_height );
74 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
76 imagedestroy($this->image);
78 $this->width = imagesx($this->image);
79 $this->height = imagesy($this->image);
85 public function scaleImageUp($min) {
87 $width = $this->width;
88 $height = $this->height;
90 $dest_width = $dest_height = 0;
92 if((! $width)|| (! $height))
95 if($width < $min && $height < $min) {
96 if($width > $height) {
98 $dest_height = intval(( $height * $min ) / $width);
101 $dest_width = intval(( $width * $min ) / $height);
106 if( $width < $min ) {
108 $dest_height = intval(( $height * $min ) / $width);
111 if( $height < $min ) {
112 $dest_width = intval(( $width * $min ) / $height);
116 $dest_width = $width;
117 $dest_height = $height;
123 $dest = imagecreatetruecolor( $dest_width, $dest_height );
124 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
126 imagedestroy($this->image);
127 $this->image = $dest;
128 $this->width = imagesx($this->image);
129 $this->height = imagesy($this->image);
135 public function scaleImageSquare($dim) {
137 $dest = imagecreatetruecolor( $dim, $dim );
138 imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height);
140 imagedestroy($this->image);
141 $this->image = $dest;
142 $this->width = imagesx($this->image);
143 $this->height = imagesy($this->image);
147 public function cropImage($max,$x,$y,$w,$h) {
148 $dest = imagecreatetruecolor( $max, $max );
149 imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h);
151 imagedestroy($this->image);
152 $this->image = $dest;
153 $this->width = imagesx($this->image);
154 $this->height = imagesy($this->image);
157 public function saveImage($path) {
158 imagejpeg($this->image,$path,100);
161 public function imageString() {
163 imagejpeg($this->image,NULL,100);
164 $s = ob_get_contents();