-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_resizing.php
More file actions
133 lines (91 loc) · 3.28 KB
/
Copy pathimage_resizing.php
File metadata and controls
133 lines (91 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
class imageResizing{
var $image;
var $image_type;
var $res;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG )
{
$this->image = imagecreatefromjpeg($filename);
$this->res = ".jpg";
}
elseif( $this->image_type == IMAGETYPE_GIF )
{
$this->image = imagecreatefromgif($filename);
$this->res = ".gif";
}
elseif( $this->image_type == IMAGETYPE_PNG )
{
$this->image = imagecreatefrompng($filename);
$this->res = ".png";
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=100, $permissions=null){
if( $image_type == IMAGETYPE_JPEG )
imagejpeg($this->image,$filename,$compression);
elseif( $image_type == IMAGETYPE_GIF )
imagegif($this->image,$filename);
elseif( $image_type == IMAGETYPE_PNG )
imagepng($this->image,$filename);
if( $permissions != null)
chmod($filename,$permissions);
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG )
imagejpeg($this->image);
elseif( $image_type == IMAGETYPE_GIF )
imagegif($this->image);
elseif( $image_type == IMAGETYPE_PNG )
imagepng($this->image);
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height,$x=0,$y=0) {
$new_image = imagecreatetruecolor($width, $height);
//imagecopyresampled($new_image, $this->image, $x, $y, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
imagecopy($new_image, $this->image, 0, 0, $x, $y, $width, $height);
/*
echo $x."<br/>";
echo $y."<br/>";
echo $width."<br/>";
echo $height."<br/>";
echo $this->getWidth()."<br/>";
echo $this->getHeight();*/
$this->image = $new_image;
}
function ResizePerfil($width,$height,$x=0,$y=0) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, $x, $y, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
// imagecopy($new_image, $this->image, 0, 0, $x, $y, $width, $height);
/*
echo $x."<br/>";
echo $y."<br/>";
echo $width."<br/>";
echo $height."<br/>";
echo $this->getWidth()."<br/>";
echo $this->getHeight();*/
$this->image = $new_image;
}
}
?>