function cropImage($courseID) { // $targ_w = $_POST['w']; // $targ_h = $_POST['h']; $targ_w = $_POST['targetWidth']; $targ_h = $_POST['targetHeight']; $imageName = str_replace(' ', '_', $_POST['imageName']); $courseID = $_POST['courseID']; $jpeg_quality = 95; $src = 'images/' . $courseID . '.jpg'; $filename = $courseID . "_" . $imageName . ".jpg"; $output_filename = "images/{$filename}"; $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']); /*Save Renamed image*/ if (imagejpeg($dst_r, $output_filename, $jpeg_quality)) { $uploadFile = uploadFrontPageBanner($courseID, $imageName); echo '<div> <h3 class="alert alert-success text-center">Image Uploaded!</h3> <div class="container-fluid"> <div class="row-fluid"> <div class="col-md-8 thumbnail"> <img src="' . $output_filename . '"> </div> <div class="col-md-4"> <p class="well">The image “' . $imageName . '” has been uploaded to the “images” folder in the course files.</p> </div> </div> </div> </div>'; unlink("images/" . $courseID . ".jpg"); } else { echo 'Error uploading image'; } }
function cropImage($courseID) { $targ_w = 1075; $targ_h = 320; $courseID = $_POST['courseID']; $jpeg_quality = 95; $src = 'images/' . $courseID . '.jpg'; $filename = $courseID . "_cropped.jpg"; $output_filename = "images/{$filename}"; $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']); /*Save Renamed image*/ if (imagejpeg($dst_r, $output_filename, $jpeg_quality)) { $uploadFile = uploadFrontPageBanner($courseID); echo '<div style="margin-left:20px;"> <h2>Image Uploaded!</h2> <img src="' . $output_filename . '" style="width:700px;"> <p>To apply this image to a page, choose one of the Front Page themes from the custom tools.</p> <p>If you have already selected one of the Front Page themes for a page you will need to:</p> <ol> <li>Edit the page</li> <li>Launch the tools</li> <li>Save the page</li> </ol> </div>'; unlink("images/" . $courseID . ".jpg"); } else { echo "Error uploading image"; } }