-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
32 lines (24 loc) · 849 Bytes
/
Copy pathtest.php
File metadata and controls
32 lines (24 loc) · 849 Bytes
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
<?php
// ---------- REDIMENTIONNER L'IMAGE ----------
// Le fichier
$filename = $_SERVER['DOCUMENT_ROOT']."/assets/images/photos/test.jpg";
// Définition de la largeur et de la hauteur maximale
$width = 2400;
$height = 1600;
// Content type
header('Content-Type: image/jpeg');
// Cacul des nouvelles dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Redimensionnement
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Affichage
imagejpeg($image_p, $_SERVER['DOCUMENT_ROOT']."/assets/images/photos/test_"."resize.jpg", 200);
?>