diff options
Diffstat (limited to 'articles/miniatures.php')
-rw-r--r-- | articles/miniatures.php | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/articles/miniatures.php b/articles/miniatures.php new file mode 100644 index 0000000..48f3525 --- /dev/null +++ b/articles/miniatures.php | |||
@@ -0,0 +1,85 @@ | |||
1 | <?php | ||
2 | if ($infophoto['extension'] == 'png' OR $infophoto['extension'] == 'PNG') | ||
3 | { | ||
4 | $source = imagecreatefrompng($nom); | ||
5 | $hauteur_source = imagesy($source); | ||
6 | |||
7 | if ($hauteur_source > 250) | ||
8 | { | ||
9 | // dimensions des deux images | ||
10 | $largeur_source = imagesx($source); | ||
11 | $forme = $hauteur_source / $largeur_source; // si image plus haute que large: >1, si plus large: <1 | ||
12 | $hauteur_destination = 250; // hauteur arbitraire | ||
13 | $largeur_destination = 250 / $forme; // largeur proportionnée | ||
14 | |||
15 | // créer la miniature | ||
16 | $destination = imagecreatetruecolor($largeur_destination, 250); | ||
17 | imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source); | ||
18 | |||
19 | // enregistrer la nouvelle image | ||
20 | imagepng($destination, $mini_nom); | ||
21 | } | ||
22 | else | ||
23 | { | ||
24 | // enregistrer l'image de départ avec le nom d'une miniature | ||
25 | imagepng($source, $mini_nom); | ||
26 | } | ||
27 | } | ||
28 | elseif ($infophoto['extension'] == 'jpg' OR $infophoto['extension'] == 'jpeg') | ||
29 | { | ||
30 | $source = imagecreatefromjpeg($nom); | ||
31 | $hauteur_source = imagesy($source); | ||
32 | ; | ||
33 | if ($hauteur_source > 250) | ||
34 | { | ||
35 | // dimensions des deux images | ||
36 | $largeur_source = imagesx($source); | ||
37 | $forme = $hauteur_source / $largeur_source; // si image plus haute que large: >1, si plus large: <1 | ||
38 | $hauteur_destination = 250; // hauteur arbitraire | ||
39 | $largeur_destination = 250 / $forme; // largeur proportionnée | ||
40 | |||
41 | // créer la miniature | ||
42 | $destination = imagecreatetruecolor($largeur_destination, 250); | ||
43 | imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source); | ||
44 | |||
45 | // enregistrer la nouvelle image | ||
46 | imagejpeg($destination, $mini_nom); | ||
47 | } | ||
48 | else | ||
49 | { | ||
50 | // enregistrer l'image de départ avec le nom d'une miniature | ||
51 | imagejpeg($source, $mini_nom); | ||
52 | } | ||
53 | } | ||
54 | elseif ($infophoto['extension'] == 'gif') | ||
55 | { | ||
56 | $source = imagecreatefromgif($nom); | ||
57 | $hauteur_source = imagesy($source); | ||
58 | |||
59 | if ($hauteur_source > 250) | ||
60 | { | ||
61 | // dimensions des deux images | ||
62 | $largeur_source = imagesx($source); | ||
63 | $forme = $hauteur_source / $largeur_source; // si image plus haute que large: >1, si plus large: <1 | ||
64 | $hauteur_destination = 250; // hauteur arbitraire | ||
65 | $largeur_destination = 250 / $forme; // largeur proportionnée | ||
66 | |||
67 | // créer la miniature | ||
68 | $destination = imagecreatetruecolor($largeur_destination, 250); | ||
69 | imagecopyresampled($destination, $source, 0, 0, 0, 0, $largeur_destination, $hauteur_destination, $largeur_source, $hauteur_source); | ||
70 | |||
71 | // enregistrer la nouvelle image | ||
72 | imagegif($destination, $mini_nom); | ||
73 | } | ||
74 | else | ||
75 | { | ||
76 | // enregistrer l'image de départ avec le nom d'une miniature | ||
77 | imagegif($source, $mini_nom); | ||
78 | } | ||
79 | } | ||
80 | else // echec à l'enregistrement, la fonction renvoie FALSE | ||
81 | { | ||
82 | header('Location: ../administration.php'); | ||
83 | exit (); | ||
84 | } | ||
85 | ?> | ||