103 lines
2.4 KiB
PHP
103 lines
2.4 KiB
PHP
<?php
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
|
{
|
|
$jpeg_quality = 90;
|
|
$png_quality = 90;
|
|
|
|
list($name, $ext) = explode('.', $_POST['image']);
|
|
|
|
$src = $name.'.'.$ext;
|
|
$dst = str_replace('tmp_', '', $src);
|
|
|
|
//Création image
|
|
switch($ext){
|
|
case 'gif':
|
|
$img_r = imagecreatefromgif(PATH_LOGOS.$src);
|
|
break;
|
|
case 'png':
|
|
$img_r = imagecreatefrompng(PATH_LOGOS.$src);
|
|
break;
|
|
case 'jpgeg':
|
|
case 'jpg':
|
|
$img_r = imagecreatefromjpeg(PATH_LOGOS.$src);
|
|
break;
|
|
}
|
|
//Resample
|
|
$dst_r = ImageCreateTrueColor( $_POST['w'], $_POST['h'] );
|
|
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
|
|
$_POST['w'],$_POST['h'],$_POST['w'],$_POST['h']);
|
|
//Enregistrement comme le format de départ
|
|
if ( file_exists(PATH_LOGOS.$dst) ) {
|
|
unlink(PATH_LOGOS.$dst);
|
|
}
|
|
switch($ext){
|
|
case 'gif':
|
|
imagegif($dst_r,PATH_LOGOS.$dst);
|
|
break;
|
|
case 'png':
|
|
imagepng($dst_r,PATH_LOGOS.$dst, $png_quality);
|
|
break;
|
|
case 'jpgeg':
|
|
case 'jpg':
|
|
imagejpeg($dst_r,PATH_LOGOS.$dst, $jpeg_quality);
|
|
break;
|
|
}
|
|
$output = '<div style="text-align:center;">';
|
|
$output.= '<img src="logos/'.$dst.'&uid='.time().'"/>';
|
|
$output.= '<br/>';
|
|
$output.= '<a href="#" id="logo_delete" alt="'.$dst.'">'.
|
|
'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>
|