Funcionar perfeitamente com o envio de arquivo, manipulando imagens em tempo real.
if($_POST["source"]=="arquivo"){
$uploads_dir = "./tmp";
$tmp_name = $_FILES["arquivo"]["tmp_name"];
$name = basename($_FILES["arquivo"]["name"]);
move_uploaded_file($tmp_name, "$uploads_dir/$name");
$resposta1="
<div id="cropperPanel" class="ui-outputpanel ui-widget">
<table>
<tbody>
<tr>
<td><button id="BtnCortar" name="BtnCortar" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only p-my-3" onclick="DinarteCoelho.ab({s:"BtnCortar",f:"formulario",u:"alerta cropped"});return false;" type="submit"><span class="ui-button-text ui-c">Cortar</span></button>
<script id="BtnCortar_s" type="text/javascript">
DinarteCoelho.cw("CommandButton", "widget_BtnCortar", {
id: "BtnCortar"
});
</script>
</td>
</tr>
<tr>
<td>
<table cellpadding="7">
<tbody>
<tr>
<td>
<div id="imageCropper"><img id="imageCropper_image" alt="" src="".$uploads_dir."/".$name."" height="auto" width="100%" style="max-width: 100%;" /><input id="imageCropper_coords" name="imageCropper_coords" type="hidden" autocomplete="off" aria-hidden="true" /></div>
<script id="imageCropper_s" type="text/javascript">
DinarteCoelho.onElementLoad($(DinarteCoelho.escapeClientId("imageCropper_image")), function() {
DinarteCoelho.cw("ImageCropper", "widget_imageCropper", {
id: "imageCropper",
image: "imageCropper_image",
viewMode: 1,
minSize: [50, 50],
maxSize: [350, 350],
initialCoords: [50, 50, 150, 100]
});
});
</script>
<input type="hidden" name="imagem" value="".$name."">
</td>
<td>
<div id="cropped" class="ui-outputpanel ui-widget"></div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
";
$detail= $name." recebido.";
}
if($_POST["source"]=="BtnCortar"){
$name = rand(1000,99999);
$coords = explode("_", $_POST["imageCropper_coords"]);
$targ_w = $coords[2];
$targ_h = $coords[3];
$jpeg_quality = 90;
$src = "./tmp/".$_POST["imagem"];
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$coords[0],$coords[1],$targ_w,$targ_h,$coords[2],$coords[3]);
$image="../../../resource/demo/images/crop/".$name.".jpg";
imagejpeg($dst_r,$image,$jpeg_quality);
$resposta1="<span id="cropped"><img src="/sistema/resource/demo/images/crop/".$name.".jpg" alt="" /></span>";
$detail= "Corte finalizado.";
}
$resposta="
<span id="alerta" class="ui-growl-pl" data-widget="widget_alerta" data-summary="data-summary" data-detail="data-detail" data-severity="all,error" data-redisplay="true"></span>
<script id="alerta_s" type="text/javascript">
DinarteCoelho.cw("Growl", "widget_alerta", {
id: "alerta",
sticky: false,
life: 6000,
escape: true,
keepAlive: false,
msgs: [{
summary: "Sucesso!",
detail: "".$detail."",
severity: "info",
severityText: "Information"
}]
});
</script>
";
dc.cw("Growl", "widget_alerta", {
id: "alerta"
, sticky: false
, life: 6000
, escape: true
, keepAlive: false
, msgs: []
});
dc.cw("FileUpload", "widget_arquivo", {
id: "arquivo"
, resumeContextPath: "\/sistema\/file\/resume\/"
, mode: "advanced"
, update: "alerta cropperPanel"
, invalidSizeMessage: "O tamanho máximo de arquivo permitido é de 100 KB"
, invalidFileMessage: "Apenas JPG são permitidos"
, maxFileSize: 102400.0
, allowTypes: /(\.|\/)(jpe?g)$/
});