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
|
<?php /* Aceasta functie creaza thumbnail pentru imaginea produsului // Parametrii : - name - numele imaginii input - filename - numele fisierului output - new_w - lungimea dorita noua - new_h - inaltimea dorita noua */
function createThumbnail($name, $filename, $new_w, $new_h) { $system=explode(".",$name); // in functie de extensia apeleaza functia corespunzatoare if (preg_match("/jpg|jpeg/",$system[2])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[2])){$src_img=imagecreatefrompng($name);} if (preg_match("/gif/",$system[2])){$src_img=imagecreatefromgif($name);}
// dimensiunile anterioare $old_x=imagesx($src_img); $old_y=imagesy($src_img); // obtine dimensiunile corecte pentru scalare proportionala if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } // creaza imaginea in memorie $dst_img=@imagecreatetruecolor($thumb_w,$thumb_h) or die('Cannot Initialize new GD image stream'); // copiaza continutul imaginii vechi rescalata in imaginea noua imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // in functie de extensia dorita apeleaza functia de creere corespunzatoare if (preg_match("/png/",$system[2])) imagepng($dst_img,$filename); if (preg_match("/jpg|jpeg/",$system[2])) imagejpeg($dst_img,$filename); if (preg_match("/gif/",$system[2])) imagegif($dst_img,$filename);
// sterge imaginile imagedestroy($dst_img); imagedestroy($src_img); } ?>
|