forked from feridkazimli/Simple-Image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.simpleImage.php
96 lines (94 loc) · 2.1 KB
/
class.simpleImage.php
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
<?php
/**
* Class simpleImage
* @author Kazımlı Fərid
* @blog http://www.feridkazimov.blogspot.com
* @mail [email protected]
* @date 29.01.2016
*/
class simpleImage {
protected $image = null; // image
protected static $thumbnail_image = 500; // The width size of a thumbnail.
/*
*
* @str
*
*/
public function getImage($str){
$this->image = $str;
}
/*
*
* #imageType
*
*/
private function imageType(){
$imageType = strrchr($this->image,".");
if($imageType == ".JPG" || $imageType == ".jpg"){
return true;
}else {
return false;
}
}
/*
*
* #img
* #width
* #height
*
*/
private function imageSize(){
$img = imagecreatefromjpeg("{$this->image}");
$width = imagesx($img);
$height = imagesy($img);
return array(
"img" => $img,
"width" => $width,
"height" => $height
);
}
/*
*
* #orginalImageSize
* #new_width
* #new_height
*
*/
private function newImageSize(){
$orginalImageSize = self::imageSize();
$new_width = self::$thumbnail_image;
$new_height = floor($orginalImageSize["height"]*(self::$thumbnail_image/$orginalImageSize["width"]));
return array(
"new_width" => $new_width,
"new_height" => $new_height
);
}
private function createImage(){
$orginalImageSize = self::imageSize();
$newImageSize = self::newImageSize();
$thump = imagecreatetruecolor($newImageSize["new_width"],$newImageSize["new_height"]);
imagecopyresized($thump,$orginalImageSize["img"],0,0,0,0,$newImageSize["new_width"],$newImageSize["new_height"],$orginalImageSize["width"],$orginalImageSize["height"]);
return $thump;
}
/*
*
* @name folder name
*
*/
public function smallImageToSaveFolder($name){
if(!is_dir($name)){
mkdir($name);
echo "Folder was created: <b style='color:red'>".$name."</b><br/>";
}
if(!self::imageType()){
echo "Error";
}else{
$time = date("d-m-Y-H-i-s");
$imageName = $time."-".$this -> image;
$folder = $name."/";
imagejpeg(self::createImage(),"{$folder}{$imageName}");
echo "Small image has been created: <b style='color:red'>".$imageName."</b>";
}
}
}
?>