6 |
kaklik |
1 |
<?php
|
|
|
2 |
/*************************
|
|
|
3 |
Coppermine Photo Gallery
|
|
|
4 |
************************
|
|
|
5 |
Copyright (c) 2003-2005 Coppermine Dev Team
|
|
|
6 |
v1.1 originaly written by Gregory DEMAR
|
|
|
7 |
|
|
|
8 |
This program is free software; you can redistribute it and/or modify
|
|
|
9 |
it under the terms of the GNU General Public License as published by
|
|
|
10 |
the Free Software Foundation; either version 2 of the License, or
|
|
|
11 |
(at your option) any later version.
|
|
|
12 |
********************************************
|
|
|
13 |
Coppermine version: 1.3.3
|
|
|
14 |
$Source: /cvsroot/coppermine/stable/include/imageObjectGD.class.php,v $
|
|
|
15 |
$Revision: 1.5 $
|
|
|
16 |
$Author: gaugau $
|
|
|
17 |
$Date: 2005/04/19 03:17:11 $
|
|
|
18 |
**********************************************/
|
|
|
19 |
|
|
|
20 |
class imageObject{
|
|
|
21 |
|
|
|
22 |
// image resource
|
|
|
23 |
var $imgRes;
|
|
|
24 |
// px
|
|
|
25 |
var $height=0;
|
|
|
26 |
var $width=0;
|
|
|
27 |
// for img height/width tags
|
|
|
28 |
var $string;
|
|
|
29 |
// output report or error message
|
|
|
30 |
var $message;
|
|
|
31 |
// file + dir
|
|
|
32 |
var $directory;
|
|
|
33 |
var $filename;
|
|
|
34 |
// output quality, 0 - 100
|
|
|
35 |
var $quality;
|
|
|
36 |
// truecolor available, boolean
|
|
|
37 |
var $truecolor;
|
|
|
38 |
|
|
|
39 |
//constructor
|
|
|
40 |
function imageObject($directory,$filename,$previous=null)
|
|
|
41 |
{
|
|
|
42 |
$this->directory = $directory;
|
|
|
43 |
$this->filename = $filename;
|
|
|
44 |
$this->previous = $previous;
|
|
|
45 |
$this->imgRes = $previous->imgRes;
|
|
|
46 |
if (file_exists($directory.$filename)){
|
|
|
47 |
$this->filesize = round(filesize($directory.$filename)/1000);
|
|
|
48 |
if($this->filesize>0){
|
|
|
49 |
$size = @GetImageSize($directory.$filename);
|
|
|
50 |
if ($size && !$this->imgRes) {
|
|
|
51 |
$this->imgRes = $this->getimgRes($directory.$filename,$size[2]);
|
|
|
52 |
}
|
|
|
53 |
if (function_exists("imagecreatetruecolor")){
|
|
|
54 |
$this->truecolor = true;
|
|
|
55 |
}
|
|
|
56 |
$this->width = $size[0];
|
|
|
57 |
$this->height = $size[1];
|
|
|
58 |
$this->string = $size[3];
|
|
|
59 |
}
|
|
|
60 |
}// if
|
|
|
61 |
}// constructor
|
|
|
62 |
|
|
|
63 |
// private methods
|
|
|
64 |
function getimgRes($name,&$type)
|
|
|
65 |
{
|
|
|
66 |
switch ($type){
|
|
|
67 |
case 1:
|
|
|
68 |
$im = imagecreatefromgif($name);
|
|
|
69 |
break;
|
|
|
70 |
case 2:
|
|
|
71 |
$im = imagecreatefromjpeg($name);
|
|
|
72 |
break;
|
|
|
73 |
case 3:
|
|
|
74 |
$im = imagecreatefrompng($name);
|
|
|
75 |
break;
|
|
|
76 |
}
|
|
|
77 |
return $im;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
function createUnique(&$imgnew)
|
|
|
82 |
{
|
|
|
83 |
srand((double)microtime()*100000);
|
|
|
84 |
$unique_str = "temp_".md5(rand(0,999999)).".jpg";
|
|
|
85 |
@imagejpeg($imgnew,$this->directory.$unique_str,$this->quality);
|
|
|
86 |
@imagedestroy($this->imgRes);
|
|
|
87 |
//Don't clutter with old images
|
|
|
88 |
@unlink($this->directory.$this->filename);
|
|
|
89 |
//Create a new ImageObject
|
|
|
90 |
return new imageObject($this->directory,$unique_str,$imgnew);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
function createImage($new_w,$new_h)
|
|
|
94 |
{
|
|
|
95 |
if (function_exists("imagecreatetruecolor")){
|
|
|
96 |
$retval = @imagecreatetruecolor($new_w,$new_h);
|
|
|
97 |
}
|
|
|
98 |
if (!$retval) $retval = imagecreate($new_w,$new_h);
|
|
|
99 |
return $retval;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
function cropImage(&$clipval)
|
|
|
103 |
{
|
|
|
104 |
$cliparray = split(",",$clipval);
|
|
|
105 |
$clip_top = $cliparray[0];
|
|
|
106 |
$clip_right = $cliparray[1];
|
|
|
107 |
$clip_bottom = $cliparray[2];
|
|
|
108 |
$clip_left = $cliparray[3];
|
|
|
109 |
|
|
|
110 |
$new_w = $clip_right - $clip_left;
|
|
|
111 |
$new_h = $clip_bottom - $clip_top;
|
|
|
112 |
|
|
|
113 |
$dst_img = $this->createImage($new_w,$new_h);
|
|
|
114 |
|
|
|
115 |
$result = @imagecopyresampled($dst_img, $this->imgRes, 0,0,$clip_left, $clip_top,$new_w, $new_h, $new_w, $new_h);
|
|
|
116 |
if (!$result) $result = @imagecopyresized($dst_img, $this->imgRes, 0,0,$clip_left, $clip_top,$new_w, $new_h, $new_w, $new_h);
|
|
|
117 |
|
|
|
118 |
return $this->createUnique($dst_img);
|
|
|
119 |
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
function rotateImage(&$angle){
|
|
|
123 |
|
|
|
124 |
if ($angle == 180){
|
|
|
125 |
$dst_img = @imagerotate($this->imgRes, $angle, 0);
|
|
|
126 |
}else{
|
|
|
127 |
$width = imagesx($this->imgRes);
|
|
|
128 |
$height = imagesy($this->imgRes);
|
|
|
129 |
if ($width > $height){
|
|
|
130 |
$size = $width;
|
|
|
131 |
}else{
|
|
|
132 |
$size = $height;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
$dst_img = $this->createImage($size, $size);
|
|
|
136 |
imagecopy($dst_img, $this->imgRes, 0, 0, 0, 0, $width, $height);
|
|
|
137 |
$dst_img = @imagerotate($dst_img, $angle, 0);
|
|
|
138 |
$this->imgRes = $dst_img;
|
|
|
139 |
$dst_img = $this->createImage($height, $width);
|
|
|
140 |
|
|
|
141 |
if ((($angle == 90) && ($width > $height)) || (($angle == 270) && ($width < $height))){
|
|
|
142 |
imagecopy($dst_img, $this->imgRes, 0, 0, 0, 0, $size, $size);
|
|
|
143 |
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
if ((($angle == 270) && ($width > $height)) || (($angle == 90) && ($width < $height))){
|
|
|
147 |
imagecopy($dst_img, $this->imgRes, 0, 0, $size - $height, $size - $width, $size, $size);
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
return $this->createUnique($dst_img);
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
function resizeImage($new_w=0,$new_h=0){
|
|
|
157 |
|
|
|
158 |
$dst_img = $this->createImage($new_w,$new_h);
|
|
|
159 |
|
|
|
160 |
$result = @imagecopyresampled($dst_img, $this->imgRes, 0, 0, 0, 0, $new_w, $new_h, $this->width,$this->height);
|
|
|
161 |
if (!$result) $result = @imagecopyresized($dst_img, $this->imgRes, 0, 0, 0, 0, $new_w, $new_h, $this->width,$this->height);
|
|
|
162 |
return $this->createUnique($dst_img);
|
|
|
163 |
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
function saveImage(){
|
|
|
168 |
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
}
|
|
|
172 |
?>
|