Full source code website bán hàng thương mại điện tử gần giống shopee
462.621 lượt xem;
1 <?php
2 class SimpleImage {
3
4 var $image;
5 var $image_type;
6
7 function load($filename) {
8
9 $image_info = getimagesize($filename);
10 $this->image_type = $image_info[2];
11 if( $this->image_type == IMAGETYPE_JPEG ) {
12
13 $this->image = imagecreatefromjpeg($filename);
14 } elseif( $this->image_type == IMAGETYPE_GIF ) {
15
16 $this->image = imagecreatefromgif($filename);
17 } elseif( $this->image_type == IMAGETYPE_PNG ) {
18
19 $this->image = imagecreatefrompng($filename);
20 }
21 }
22 function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
23
24 if( $image_type == IMAGETYPE_JPEG ) {
25 imagejpeg($this->image,$filename,$compression);
26 } elseif( $image_type == IMAGETYPE_GIF ) {
27
28 imagegif($this->image,$filename);
29 } elseif( $image_type == IMAGETYPE_PNG ) {
30
31 imagepng($this->image,$filename);
32 }
33 if( $permissions != null) {
34
35 chmod($filename,$permissions);
36 }
37 }
38 function output($image_type=IMAGETYPE_JPEG) {
39
40 if( $image_type == IMAGETYPE_JPEG ) {
41 imagejpeg($this->image);
42 } elseif( $image_type == IMAGETYPE_GIF ) {
43
44 imagegif($this->image);
45 } elseif( $image_type == IMAGETYPE_PNG ) {
46
47 imagepng($this->image);
48 }
49 }
50 function getWidth() {
51
52 return imagesx($this->image);
53 }
54 function getHeight() {
55
56 return imagesy($this->image);
57 }
58 function resizeToHeight($height) {
59
60 $ratio = $height / $this->getHeight();
61 $width = $this->getWidth() * $ratio;
62 $this->resize($width,$height);
63 }
64
65 function resizeToWidth($width) {
66 $ratio = $width / $this->getWidth();
67 $height = $this->getheight() * $ratio;
68 $this->resize($width,$height);
69 }
70
71 function scale($scale) {
72 $width = $this->getWidth() * $scale/100;
73 $height = $this->getheight() * $scale/100;
74 $this->resize($width,$height);
75 }
76
77 function resize($width,$height) {
78 $new_image = imagecreatetruecolor($width, $height);
79 imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
80 $this->image = $new_image;
81 }
82
83 }
84 ?>
2 class SimpleImage {
3
4 var $image;
5 var $image_type;
6
7 function load($filename) {
8
9 $image_info = getimagesize($filename);
10 $this->image_type = $image_info[2];
11 if( $this->image_type == IMAGETYPE_JPEG ) {
12
13 $this->image = imagecreatefromjpeg($filename);
14 } elseif( $this->image_type == IMAGETYPE_GIF ) {
15
16 $this->image = imagecreatefromgif($filename);
17 } elseif( $this->image_type == IMAGETYPE_PNG ) {
18
19 $this->image = imagecreatefrompng($filename);
20 }
21 }
22 function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
23
24 if( $image_type == IMAGETYPE_JPEG ) {
25 imagejpeg($this->image,$filename,$compression);
26 } elseif( $image_type == IMAGETYPE_GIF ) {
27
28 imagegif($this->image,$filename);
29 } elseif( $image_type == IMAGETYPE_PNG ) {
30
31 imagepng($this->image,$filename);
32 }
33 if( $permissions != null) {
34
35 chmod($filename,$permissions);
36 }
37 }
38 function output($image_type=IMAGETYPE_JPEG) {
39
40 if( $image_type == IMAGETYPE_JPEG ) {
41 imagejpeg($this->image);
42 } elseif( $image_type == IMAGETYPE_GIF ) {
43
44 imagegif($this->image);
45 } elseif( $image_type == IMAGETYPE_PNG ) {
46
47 imagepng($this->image);
48 }
49 }
50 function getWidth() {
51
52 return imagesx($this->image);
53 }
54 function getHeight() {
55
56 return imagesy($this->image);
57 }
58 function resizeToHeight($height) {
59
60 $ratio = $height / $this->getHeight();
61 $width = $this->getWidth() * $ratio;
62 $this->resize($width,$height);
63 }
64
65 function resizeToWidth($width) {
66 $ratio = $width / $this->getWidth();
67 $height = $this->getheight() * $ratio;
68 $this->resize($width,$height);
69 }
70
71 function scale($scale) {
72 $width = $this->getWidth() * $scale/100;
73 $height = $this->getheight() * $scale/100;
74 $this->resize($width,$height);
75 }
76
77 function resize($width,$height) {
78 $new_image = imagecreatetruecolor($width, $height);
79 imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
80 $this->image = $new_image;
81 }
82
83 }
84 ?>