<?php
|
/*---------------------------------------------------------------*/
|
/*
|
Titre : Homothétie d'une image
|
|
URL : https://phpsources.net/code_s.php?id=970
|
Date édition : 15 Fév 2019
|
*/
|
/*---------------------------------------------------------------*/
|
|
function ResizePicture($srcFilename , $destFilename , $maxWidth , $maxHeight ,
|
$format){
|
/// format supportes : (IMG_GIF, IMG_JPEG, IMG_PNG)
|
if(($format == IMG_GIF) && (imagetypes() & IMG_GIF))
|
$frmName = "GIF";
|
elseif(($format == IMG_PNG) && (imagetypes() & IMG_PNG))
|
$frmName = "PNG";
|
elseif(($format == IMG_JPG) && (imagetypes() & IMG_JPG))
|
$frmName = "JPEG";
|
else
|
return FALSE;
|
$imageCreateFromXXX = "ImageCreateFrom$frmName";
|
$imageXXX = "Image$frmName";
|
$infos = getimagesize($srcFilename);
|
$ratio_w = $infos[0] / $maxWidth;
|
$ratio_h = $infos[1] / $maxHeight;
|
$ratio = ($ratio_w > $ratio_h)?$ratio_w:$ratio_h;
|
$newWidth = $infos[0] / $ratio;
|
$newHeight = $infos[1] / $ratio;
|
$outBuffer = imagecreatetruecolor($newWidth, $newHeight);
|
$inBuffer = $imageCreateFromXXX($srcFilename);
|
imagecopyresized($outBuffer, $inBuffer, 0, 0, 0, 0, $newWidth, $newHeight,
|
$infos[0], $infos[1]);
|
$imageXXX($outBuffer, $destFilename);
|
return $destFilename;
|
}
|
|
?>
|
|
|