-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgMods.php
72 lines (50 loc) · 1.85 KB
/
imgMods.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
<?php
function resize_picture ($sourceFile,$targetWidth,$target_file)
{
$source_file_dimensions = getimagesize($sourceFile);
$name = basename($sourceFile);
$target_name = basename($target_file);
$width = $source_file_dimensions[0];
$height = $source_file_dimensions[1];
$img_type = $source_file_dimensions[2];
if($width<$height)
{
$aspect = $width / $targetWidth;
$new_width = $targetWidth;
$new_height= $height / $aspect;
}
else
{
$aspect = $height / $targetWidth;
$new_height = $targetWidth;
$new_width= $width / $aspect;
}
$small = imagecreatetruecolor($new_width, $new_height);
switch($img_type){
case IMAGETYPE_PNG:
$source = imagecreatefrompng($sourceFile);
imagecopyresampled($small, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagepng($small,$target_file);
break;
case IMAGETYPE_GIF:
$source = imagecreatefromgif($sourceFile);
imagecopyresampled($small, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagegif($small,$target_file);
break;
case IMAGETYPE_JPEG:
$source = imagecreatefromjpeg($sourceFile);
imagecopyresampled($small, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($small,$target_file);
break;
}
return true;
}
function delete_picture($picture_name)
{
if(!unlink('pics/768/'.$picture_name)) return false;
if(!unlink('pics/480/'.$picture_name)) return false;
if(!unlink('pics/320/'.$picture_name)) return false;
if(!unlink('pics/160/'.$picture_name)) return false;
return true;
}
?>