-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_handler.php
68 lines (62 loc) · 1.94 KB
/
image_handler.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
<?
function image_handler($velicine, $folder, $pref, $suf, $tmp, $name) {
$podrzano = array("jpg","jpeg","gif","png");
$ext = getImgExtension(strtolower($name));
// echo "Ext: $ext";exit;
// Copy the original file
copy($tmp, "{$folder}/original/{$pref}-original.{$ext}");
if(!in_array($ext,$podrzano)) {
echo "<br>Format nije podrzan!";
exit;
}
switch ($ext) {
case "jpg":
$source = imagecreatefromjpeg($tmp);
break;
case "gif":
$source = imagecreatefromgif($tmp);
break;
case "png":
$source = imagecreatefrompng($tmp);
break;
}
$d = getimagesize($tmp);
$o = $d[1]/$d[0];
foreach($velicine as $v) {
$putanja = "{$folder}/{$pref}{$v}";
// $putanja = "{$folder}/{$pref}-{$v}px";
if(is_file("{$putanja}.jpg")) unlink("{$putanja}.jpg");
if(is_file("{$putanja}.gif")) unlink("{$putanja}.gif");
if(is_file("{$putanja}.png")) unlink("{$putanja}.png");
$dest = ($o>1)?imagecreatetruecolor($v/$o, $v):imagecreatetruecolor($v, $v*$o);
if($o>1) imagecopyresampled($dest, $source, 0, 0, 0, 0, $v/$o, $v, imagesx($source), imagesy($source));
else imagecopyresampled($dest, $source, 0, 0, 0, 0, $v, $v*$o, imagesx($source), imagesy($source));
switch ($ext) {
case "jpg":
if(!imagejpeg($dest,"{$putanja}.jpg",85)) echo "Greska...";
break;
case "gif":
if(!imagegif($dest,"{$putanja}.gif")) echo "Greska...";
break;
case "png":
if(!imagepng($dest,"{$putanja}.png")) echo "Greska...";
break;
}
imagedestroy($dest);
}
// dnevnik("upload image: $folder/$pref$suf.$ext; Size: $d");
}
function getImgExtension($name) {
$e = explode(".",$name);
$ext = strtolower($e[sizeof($e)-1]);
return($ext);
}
function DajEkstenzijuSlikeAkoPostoji($folder, $fajl, $ajdi)
{
$odgovor = "";
if(is_file("{$folder}/{$fajl}-80px-{$ajdi}.jpg")) $odgovor = "jpg";
if(is_file("{$folder}/{$fajl}-80px-{$ajdi}.gif")) $odgovor = "gif";
if(is_file("{$folder}/{$fajl}-80px-{$ajdi}.png")) $odgovor = "png";
return $odgovor;
}
?>