/*------------------------------*/
|
/*
|
Titre : Effet miroir sur des images
|
|
Date édition : 15 Fev 2019
|
Date mise a jour : 11 Aout 2019
|
|
Rapport de la maj:
|
- modification de la description
|
*/
|
/*------------------------------*/
|
|
function pic_flip($src , $dest , $format , $flip="H"){
|
/* Paramètres : $src : fichier source
|
* $dest : fichier de destination
|
* $format : format de l'image résultat
|
* ("GIF", "JPG", "PNG", "WBMP")
|
* $flip : type de flip H => horizontal
|
* V => vertical
|
* VH ou HV => horizontal puis vertical
|
*/
|
|
$flip = strtoupper($flip);
|
if (file_exists($src))
|
$size = getimagesize($src);
|
else
|
return FALSE;
|
|
switch($size[2])
|
{
|
case 1 :
|
if (imagetypes() & IMG_GIF)
|
$pic = imagecreatefromgif($src);
|
break;
|
case 2 :
|
if (imagetypes() & IMG_JPG)
|
$pic = imagecreatefromjpeg($src);
|
break;
|
case 3 :
|
if (imagetypes() & IMG_PNG)
|
$pic = imagecreatefrompng($src);
|
break;
|
default :
|
if (preg_match("/\.wbmp$/i", $src) && (imagetypes() & IMG_WBMP))
|
$pic = imagecreatefromwbmp($src);
|
}
|
if (!$pic)
|
return FALSE;
|
|
$width = imagesx($pic);
|
$height = imagesy($pic);
|
$p = imagecreate($width, $height);
|
|
if ($flip == 'V')
|
{
|
for($i=0;$i<$height;$i++)
|
{
|
imagecopy($p, $pic, 0, $height-1-$i, 0, $i, $width, 1);
|
}
|
imagedestroy($pic);
|
$pic = $p;
|
}
|
if ($flip == 'H')
|
{
|
for($i=0;$i<$width;$i++)
|
{
|
imagecopy($p, $pic, $width-1-$i, 0, $i, 0, 1, $height);
|
}
|
imagedestroy($pic);
|
$pic = $p;
|
}
|
if ($flip == 'HV' || $flip == 'VH')
|
{
|
for($i=0;$i<$height;$i++)
|
{
|
imagecopy($p, $pic, 0, $height-1-$i, 0, $i, $width, 1);
|
}
|
for($i=0;$i<$width;$i++)
|
{
|
imagecopy($pic, $p, $width-1-$i, 0, $i, 0, 1, $height);
|
}
|
}
|
|
$format = strtoupper($format);
|
if ($format == "GIF")
|
{
|
if (imagetypes() & IMG_GIF)
|
imagegif($pic, $dest);
|
else
|
return FALSE;
|
}
|
else if ($format == "JPG")
|
{
|
if (imagetypes() & IMG_JPG)
|
imagejpeg($pic, $dest);
|
else
|
return FALSE;
|
}
|
else if ($format == "PNG")
|
{
|
if (imagetypes() & IMG_PNG)
|
imagepng($pic, $dest);
|
else
|
return FALSE;
|
}
|
else if ($format == "WBMP")
|
{
|
if (imagetypes() & IMG_WBMP)
|
imagewbmp($pic, $dest);
|
else
|
return FALSE;
|
}
|
else return FALSE;
|
return TRUE;
|
}
|
|
| ?> |