-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.resizer.php
More file actions
executable file
·120 lines (100 loc) · 3.52 KB
/
class.resizer.php
File metadata and controls
executable file
·120 lines (100 loc) · 3.52 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
<?php
class resizeThis{
var $sourceImage; /* initialize source image */
var $ext; /* Get image extension */
function do_upload() /* firstly lets upload the image */
{
if($_FILES['category_image']['size']>0)
{
$dir='../images/category_images';
$filename1=$_FILES['category_image']['name'];
$srcfile=$_FILES['category_image']['tmp_name'];
$targetfile=$dir.'/'.$filename1;
if(move_uploaded_file($srcfile, $targetfile))
{
return $filename1;
}
else
{
return $filename1; /* this returns the uploaded image name */
}
}
}
function load($source){
$source = '../images/category_images/'.$source; /* get the source directory */
//echo $source; die();
//$source = $this->do_upload();
$this->ext = strtolower(pathinfo($source, PATHINFO_EXTENSION));
if($this->ext == "jpg"){
$this->sourceImage = imagecreatefromjpeg($source);
}elseif($this->ext == "gif"){
$this->sourceImage = imagecreatefromgif($source);
}elseif($this->ext == "png"){
$this->sourceImage = imagecreatefrompng($source);
}
}
function getWidth(){
return @imagesx($this->sourceImage);
}
function getHeight(){
return @imagesy($this->sourceImage);
}
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){
$newImage = imagecreatetruecolor($width, $height);
imagecopyresampled($newImage, $this->sourceImage, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->simagejpegourceImage = $newImage;
}
function crop($width,$height,$x_pos=0,$y_pos=0){
$newImage = imagecreatetruecolor($width, $height);
if(@$this->getWidth()/$this->getHeight() != @$width/$height){
$width_temp=$width;
$height_temp=$height;
if($this->getWidth()/$this->getHeight()>$width/$height){
$width = $this->getWidth()*$height/$this->getHeight();
$x_pos = -($width-$width_temp)/2;
$y_pos = 0;
}else{
@$height = $this->getHeight()*$width/$this->getWidth();
$y_pos = -($height-$height_temp)/2;
$x_pos = 0;
}
}
@imagecopyresampled($newImage, $this->sourceImage, $x_pos, $y_pos, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->sourceImage = $newImage;
}
function save($source, $comp=80){
$ext = strtolower(pathinfo($source, PATHINFO_EXTENSION));
if($ext == "jpg"){
imagejpeg($this->sourceImage, $source, $comp);
}elseif($ext == "gif"){
imagegif($this->sourceImage, $source,5);
}elseif($ext == "png"){
imagepng($this->sourceImage, $source,9);
}
}
function output($ext="jpg"){
if($ext == "jpg"){
imagejpeg($this->sourceImage);
}elseif($ext == "gif"){
imagegif($this->sourceImage);
}elseif($ext == "png"){
imagepng($this->sourceImage);
}
}
}
?>