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
|
<?php
function createVignette($source, $destination, $taille) { list($width, $height) = getimagesize($source); if ($width >= $height) { $width_reduce = $taille; $height_reduce = ($width_reduce*$height)/$width; $image_reduce = imagecreatetruecolor($taille,$taille); $blanc = imagecolorallocate($image_reduce, 255, 255, 255); imagefilledrectangle($image_reduce, 0, 0, $taille, $taille, $blanc); $image = imagecreatefromjpeg($source); $rest = ($taille - $height_reduce) / 2; imagecopyresampled($image_reduce,$image,0,$rest,0,0,$width_reduce,$heigh t_reduce,$width,$height); ImageJPEG($image_reduce,$destination,100); imagedestroy($image_reduce); imagedestroy($image); } else { $height_reduce = $taille; $width_reduce = ($height_reduce*$width)/$height; $image_reduce = imagecreatetruecolor($taille,$taille); $blanc = imagecolorallocate($image_reduce, 255, 255, 255); imagefilledrectangle($image_reduce, 0, 0, $taille, $taille, $blanc); $image = imagecreatefromjpeg($source); $rest = ($taille - $width_reduce) / 2; imagecopyresampled($image_reduce,$image,$rest,0,0,0,$width_reduce,$heigh t_reduce,$width,$height); ImageJPEG($image_reduce,$destination,100); imagedestroy($image_reduce); imagedestroy($image); } }
$source = "grandformat.jpg"; $vignette = "vignette.jpg"; if (!file_exists($vignette)) createVignette($source, $vignette, 150);
?> |