Caute, mam problem s nasledujucim kodom, pozeram do toho uz druhy den a neviem si rady, mozno je chyba trivialna kedze som v Jquery- ajax zaciatocnik. Mam nasledujuci kod, ktory by mal vytiahnut udaje z formulara a postnut ich:
Kód:
$(document).ready(function () { //create the thumbnail
$('#save_image').click(function() {
var x = $('#x').val();
var y = $('#y').val();
var w = $('#w').val();
var h = $('#h').val();
var source= $('#source').val();
var o_width = $('#o_width').val();
var o_height = $('#o_height').val();
var width = $('#width').val();
var height = $('#height').val();
var ratio1 = $('#ratio1').val();
if(x=="" || y=="" || w=="" || h==""){
alert("You must make a selection first");
return false;
}else{
$.ajax({
type: 'POST',
url: 'crop.php',
data: 'save_thumb=Save Thumbnail&x='+x+'&y='+y+'&w='+w+'&h='+h+'&source='+source+'&o_width='+o_width+'&o_height='+o_height+'&ratio1='+ratio1+'&width='+width+'&height='+height,
cache: false,
sucess: function(){
alert("OK"); // TENTO ALERT SA VOBEC NEVYPISE
}
});
return false;
}
});
});
potom mam subor crop.php ktory by ich mal spracovat, a vlastne ulozit cropnuty obrazok. Predtym som to mal riesene klasickym formularom, ale chcel som to vyriesit takto kedze je to lepsie. Avsak nefunguje mi to a neviem preco. Tu je subor crop.php
Kód:
<?php
error_reporting (E_ALL ^ E_NOTICE);
if ($_POST["save_thumb"]=="Save Thumbnail") {
{
$tmp_w = 1260;
$tmp_h = 900;
$ar_width = $_POST['o_width']/ $_POST['width']; //pomer ktorim treba nasobit
$ar_height = $_POST['o_height']/ $_POST['height'];
//overi ako je obrazok orezany, ci na vysku alebo na sirku
if ( $_POST['ratio1'] == 0)
{
$targ_w = $tmp_w;
$targ_h = $tmp_h;
$height = 500;
$width = 650;
$img_width = 602;
$m_width = $width + 50;
$m_height = $height + 170;
$header = 40;
}
else
{
$targ_w = $tmp_h;
$targ_h = $tmp_w;
$height = 504;
$width = 360;
$img_width = 430;
$m_width = $width + 50;
$m_height = $height + 170;
$header = 40;
}
$jpeg_quality = 100;
$src = $_POST['source'];
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x']*$ar_width,$_POST['y']*$ar_height,$targ_w,$targ_h,$_POST['w']*$ar_width,$_POST['h']*$ar_height);
/*imagejpeg($dst_r,null,$jpeg_quality);*/
$act_time = time();
$file_name = $act_time.".jpg";
$i = 0;
while( (file_exists("tmp_img/".$file_name)) )
{
$file_name = $act_time."_".$i.".jpg";
$i++;
}
imagejpeg($dst_r, 'tmp_img/'.$file_name, $jpeg_quality);
unlink($src);
// Remove from memory - don't forget this part
imagedestroy($dst_r);
//exit;
}
?>
Neviete nahodov niekto kde robim chybu ? Dakujem.