0

Hey guys i am trying to crop uploaded image using php using following code.

if(isset($_POST["Crop"])){  
    $source_x=$_POST['x_value'];
    $source_y=$_POST['y_value'];
    $width=$_POST['w_value'];
    $height=$_POST['h_value'];

    $src="assets/images/uploads/1509432972_Koala.jpg";
    $crop = imagecreatetruecolor($width,$height); 
    imagecopy ($crop, $src, 0, 0, $source_x, $source_y, $width, $height); 
    imagejpeg($crop); 
    imagedestroy($src);
    imagedestroy($crop);
}

The problem that it is not working properly. Since there are lot of posts there to solve this, found a solution called GD library how to include it and crop all kind of images.

tan
  • 1,554
  • 2
  • 12
  • 34
  • What is the exact problem ? include GD library ? – tan Nov 01 '17 at 04:26
  • exact problem is couldn't crop the image using above code, no i didn't included it how to include and where to get that library? @tan – Pattatharasu Nataraj Nov 01 '17 at 04:29
  • What errors u see ? if not seeing anything, please enable errors https://stackoverflow.com/a/5438125/8197560 – tan Nov 01 '17 at 04:31
  • error is already enabled, but i didnt get any the code is working fine i guess, some more thing i need to add, dont know whats that.. – Pattatharasu Nataraj Nov 01 '17 at 04:34
  • 1
    imagecopy seems to expect a resource at 2nd parameter, not the file path ? – tan Nov 01 '17 at 04:36
  • 1
    $resSrc = imagecreatefromjpeg($src) and pass it to there. for any type see https://stackoverflow.com/a/10247150/8197560 – tan Nov 01 '17 at 04:39

0 Answers0