extranet/includes/saisie/saisie_logo_save.php
2010-06-23 12:55:04 +00:00

68 lines
1.7 KiB
PHP

<?php
if ( !empty($file) ) {
list($name, $ext) = explode('.', $file);
$name_dst = str_replace('tmp_','',$name);
//Vérifier les dimensions
$max_width = 350;
$max_height = 150;
$size = GetImageSize(PATH_LOGOS.$file); // Read the size
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if( ($width <= $max_width) && ($height <= $max_height) )
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
//Création image
switch($ext){
case 'gif':
$src = imagecreatefromgif(PATH_LOGOS.$src);
break;
case 'png':
$src = imagecreatefrompng(PATH_LOGOS.$src);
break;
case 'jpgeg':
case 'jpg':
$src = imagecreatefromjpeg(PATH_LOGOS.$src);
break;
}
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
switch($ext){
case 'gif':
imagegif($dst,PATH_LOGOS.$name_dst.'.'.$ext);
break;
case 'png':
imagepng($dst,PATH_LOGOS.$name_dst.'.'.$ext);
break;
case 'jpgeg':
case 'jpg':
imagejpeg($dst,PATH_LOGOS.$name_dst.'.'.$ext);
break;
}
//Affecté au siren
$dst = PATH_LOGOS.str_replace('tmp_', '', $file);
if (rename(PATH_LOGOS.$file, $dst)){
$output = 'Image affecté.';
} else {
$output = 'Erreur.';
}
}
$output = '<div style="text-align:center;">';
$output.= $message;
$output.= '<br/>';
$output.= '<a href="#" id="logo_default">Re-Charger le panneau</a>';
$output.= '</div>';
echo $output;