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
|
$Image = $nomDestination.$extension;
$originale = $repertoireDestination.$Image;
$ratio = 200;
$src=imagecreatefromjpeg($repertoireDestination.$Image);
$size = getimagesize($repertoireDestination.$Image);
if ($size[0] <= $ratio && $size[1] <= $ratio ) {
$x = $size[0];
$y = $size[1];
}
if ( $size[0] == $size[1] && $size[0] > $ratio && $size[1] > $ratio ) {
$x = $size[0];
$y = $size[1];
}
if ($size[0] <= $ratio && $size[1] > $ratio ) {
$x = round( ($size[0] / $size[1] ) * $ratio);
$y = $ratio;
}
if ( $size[0] >= $ratio && $size[1] > $ratio && $size[0] < $size[1] ) {
$x = round( ($size[0] / $size[1] ) * $ratio);
$y = $ratio;
}
if ($size[1] <= $ratio && $size[0] > $ratio ) {
$x = $ratio;
$y = round( ($size[1] / $size[0] ) * $ratio);
}
if ( $size[1] >= $ratio && $size[0] > $ratio && $size[0] > $size[1] ) {
$x = $ratio;
$y = round( ($size[1] / $size[0] ) * $ratio);
}
$im=imagecreatetruecolor($x, $y);
imagecopyresampled($im, $src, 0, 0, 0, 0, $x, $y, $size[0], $size[1]);
$originale = "originale_$Image";
imagejpeg($im, $repertoireDestination.$originale);
$im=imagecreatetruecolor(200, 200);
$position_x = round( (200 - $x) / 2 ); // pour positionner en x image dans la zone
$position_y = round( (200 - $y) / 2 ); // pour positionner en y image dans la zone
$gris = imagecolorallocatealpha($im,204,204,204,0); //($im,255,204,51,0)
imagefilledrectangle($im, 0, 0, 200, 200, $gris);
imagecopyresampled($im, $src, $position_x, $position_y, 0, 0, $x, $y, $size[0], $size[1]);
$noir = imagecolorallocatealpha($im,0,0,0,0);
imagerectangle($im, 0, 0, 199, 199, $noir);
$normale = "normale_$Image";
imagejpeg($im, $repertoireDestination.$normale); |
Partager