I have a javascript scrict PHP function that allows me to crop images.
My problem is that the resulting image is always a black image the same size as the crop field , it does not contain the cropped part of the original image.
A buddy of mine said that the is problem is that is don’t load the stream image, but i’m not sure what he meant nor did he preset any solutions to resolve my problem. Does anyone know how to do it ?
This what i have so far :
if(isset($_POST['decupata'])){
$new_width=$_POST['w'];//width of the crop field
$new_height=$_POST['h'];//height of the crop field
$x=$_POST['x1']; // x of crop field
$y=$_POST['y1'];// y of crop field
$num=$_POST['nume'];//name of the original picture
$old_width=imagesx("../upload/original/".$num);
$old_height=imagesy("../upload/original/".$num);
$min_rand=rand(0,1000);
$max_rand=rand(100000000000,10000000000000000);
$new_num=rand($min_rand,$max_rand);
$new_image = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg("../upload/original/".$num);
imagecopyresampled($new_image, $image, 0, 0, $x, $y, $new_width, $new_height, $old_width, $old_height);
imagejpeg($new_image,"../upload/".$new_num.$num,100);
header('Location:lista_imagini.php');
}
<form action="<?php $_PHP_SELF ?>" method="post" enctype="multipart/form-data" id="coords">
<input type="text" size="4" id="x1" name="x1" />
<input type="text" size="4" id="y1" name="y1" />
<input type="text" size="4" id="x2" name="x2" />
<input type="text" size="4" id="y2" name="y2" />
<input type="text" size="4" id="w" name="w" value="<?php echo $width;?>" />
<input type="text" size="4" id="h" name="h" value="<?php echo $height;?>" />
<input type="text" size="4" id="nume" name="nume" value="<?php echo $num;?>" />
<input type="text" size="4" value="<?php echo $old_width;?>" />
<input type="submit" name="decupata" value="Adauga imaginea" class="buton">
</form>
You take imagesy and imagex from url instead of from created image. Create image first out of this file, like imagecreatefromjpeg