62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
// création des miniatures pour la galerie de ZwiiCMS par @Gilux 2019
|
|
if (!isset($_GET['img']))
|
|
{
|
|
exit(0);
|
|
}
|
|
$ratio = (isset($_GET['ratio'])) ? (int) $_GET['ratio'] : 135;
|
|
$img = '../../../'.$_GET['img'];
|
|
$dossiercache = '../../../site/file/cache';
|
|
if(!is_dir($dossiercache))
|
|
{
|
|
@mkdir($dossiercache,0755);
|
|
}
|
|
$par = substr(strrchr($img, '/'), 1);
|
|
$url_par = str_replace('/'.$par,'',$img);
|
|
$cache = substr(strrchr($url_par, '/'), 1);
|
|
if(!is_dir($dossiercache.'/'.$cache))
|
|
{
|
|
@mkdir($dossiercache.'/'.$cache);
|
|
}
|
|
$extension = strrchr($par,'.');
|
|
$vignette = str_replace($extension,'',$par);
|
|
$miniature = $dossiercache.'/'.$cache.'/'.$vignette.'.jpg';
|
|
|
|
if(!file_exists($miniature))
|
|
{
|
|
$imginfo = getimagesize($img);
|
|
$largeur = $imginfo[0];
|
|
$hauteur = $imginfo[1];
|
|
$type = $imginfo[2];
|
|
if($type == 1)
|
|
{
|
|
$src = imagecreatefromgif($img);
|
|
}
|
|
elseif($type == 2)
|
|
{
|
|
$src = imagecreatefromjpeg($img);
|
|
}
|
|
elseif($type == 3)
|
|
{
|
|
$src = imagecreatefrompng($img);
|
|
}
|
|
imageinterlace($src, true);
|
|
if ($largeur > $hauteur)
|
|
{
|
|
$im = imagecreatetruecolor(round(($ratio/$hauteur)*$largeur), $ratio);
|
|
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratio/$hauteur)*$largeur), $ratio, $largeur, $hauteur);
|
|
}
|
|
else
|
|
{
|
|
$im = imagecreatetruecolor($ratio, round(($ratio/$largeur)*$hauteur));
|
|
imagecopyresampled($im, $src, 0, 0, 0, 0, $ratio, round($hauteur*($ratio/$largeur)), $largeur, $hauteur);
|
|
}
|
|
imagejpeg($im, $miniature, 80);
|
|
imagedestroy($im);
|
|
}
|
|
header('Content-Type: image/jpeg');
|
|
$data = file_get_contents($miniature);
|
|
echo $data;
|
|
clearstatcache();
|
|
?>
|