<?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,$height_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,$height_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);
?>