4
Hello! I am creating a user profile and to crop the image I am using JCROP. He cuts normally for me, but wanted to know how I do to save this result in the image and the bank accept this cut that was made.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Arquivo</title>
<link rel="stylesheet" href="css/jquery.Jcrop.css" type="text/css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js"></script>
<script language="Javascript">
$(function(){
$('#ImagemCrop').Jcrop({
aspectRatio: 1,
onSelect: UpdateCrop,
setSelect: [0, 0, 200, 200],
});
});
function UpdateCrop(c)
{
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
$("#altura").html("Altura:" + c.h);
$("#largura").html("Largura:" + c.w);
};
</script>
</head>
<body>
<div id="altura">Altura:</div>
<div id="largura">Largura:</div>
<form action="recorte.php" 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="imagem" name="imagem" value="img/1.jpg" />
<input type="submit" value="Recortar Imagem" />
</form>
<img src="img/1.jpg" id="ImagemCrop" />
</body>
</html>
<?php
if (isset($_POST['imagem']) &&
isset($_POST['x']) &&
isset($_POST['y']) &&
isset($_POST['w']) &&
isset($_POST['h']))
{
$targ_w = $_POST['w'];
$targ_h = $_POST['h'];
$jpeg_quality = 90;
$src = $_POST['imagem'];
$img_r = imagecreatefromjpeg($src);
$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']);
header('Content-type: image/jpeg');
imagejpeg($dst_r,null,$jpeg_quality);
} else {
echo 'error';
}
See this article from Code line about jCrop explaining the PHP code to save the image in the database.
– Ciano Barbarossa