extranet/includes/saisie/saisie_logo_crop.php
2010-06-23 09:22:57 +00:00

102 lines
2.3 KiB
PHP

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$targ_w = $targ_h = 150;
$jpeg_quality = 90;
$png_quality = 90;
list($name, $ext) = explode('.', $_POST['image']);
$src = PATH_LOGOS.$name.'.'.$ext;
$dst = str_replace('tmp_', '', $src);
//Création image
switch($ext){
case 'gif':
$img_r = imagecreatefromgif($src);
break;
case 'png':
$img_r = imagecreatefrompng($src);
break;
case 'jpgeg':
case 'jpg':
$img_r = imagecreatefromjpeg($src);
break;
}
//Resample
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['h']);
//Enregistrement comme le format de départ
switch($ext){
case 'gif':
imagegif($dst_r,$dst);
break;
case 'png':
imagepng($dst_r,$dst, $png_quality);
break;
case 'jpgeg':
case 'jpg':
imagejpeg($dst_r,$dst, $jpeg_quality);
break;
}
$logo = $name.'.'.$ext;
$output = '<div style="text-align:center;">';
$output.= '<img src="logos/'.$logo.'"/>';
$output.= '<br/>';
$output.= '<a href="#" id="logo_delete" alt="'.$logo.'">'.
'Supprimer le logo existant</a>';
$output.= '</div>';
echo $output;
exit;
}
?>
<script src="js/jquery.Jcrop.js"></script>
<link rel="stylesheet" href="css/jquery.Jcrop.css" type="text/css" />
<script language="Javascript">
$(function(){
$('#cropbox').Jcrop({
onSelect: updateCoords,
maxSize: [ 350, 150 ]
});
});
function updateCoords(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
function checkCoords()
{
if (parseInt($('#w').val())) return true;
alert('Please select a crop region then press submit.');
return false;
};
var options = {
target: '#formLogo',
beforeSubmit: checkCoords,
success: function(data, status, xhr, $form)
{
$('#formLogo').html(data);
$('#dialogcrop').dialog('close');
}
};
$('#crop').ajaxForm(options);
</script>
<img src="logos/<?=$image?>" id="cropbox" />
<br/>
<form id="crop" name="crop" action="/?page=saisieajax&q=logo/crop" method="post">
<input type="hidden" id="x" name="x" />
<input type="hidden" id="y" name="y" />
<input type="hidden" id="w" name="w" />
<input type="hidden" id="h" name="h" />
<input type="hidden" id="image" name="image" value="<?=$image?>" />
<input type="submit" name="submit" value="Découper" />
</form>