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
| <?php
function get_dim_photo($width, $height, $width_max, $height_max)
{
$dim = array();
// si l'image déborde des dimensions maximales choisis, on réalise le traitement
if(($width > $width_max) || ($height > $height_max))
{
$ratio = min(array($width_max / $width, $height_max / $height));
$dim[] = ceil($width * $ratio);
$dim[] = ceil($height * $ratio);
}
else
{
$dim[] = $width;
$dim[] = $height;
}
return $dim;
}
/*$sql = "SELECT nom_photo, largeur_photo, hauteur_photo, blob_photo
FROM photo
WHERE id_photo = ".$_GET[id_photo].";";*/
$nom_photo = "mon_image.jpg";
$img_blob = file_get_contents($nom_photo);
$largeur_photo = 520;
$hauteur_photo = 347;
$extension = str_replace('.','',strstr($nom_photo, '.'));
$dim = get_dim_photo($largeur_photo, $hauteur_photo, 500, 300);
$desired_width = $dim[0];
$desired_height = $dim[1];
// création de l'image
$im = imagecreatefromstring($img_blob);
$new = imagecreatetruecolor($desired_width, $desired_height);
$x = imagesx($im);
$y = imagesy($im);
imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y);
imagedestroy($im);
header ('Content-type: image/'.$extension);
header('Content-Disposition: inline; filename='.$nom_photo);
imagejpeg($new, null, 85);
imageDestroy($new);
?> |
Partager