// resize the original image to size of editor $resizedImage = imagecreatetruecolor($imgW, $imgH); imagecopyresampled($resizedImage, $source_image, 0, 0, 0, 0, $imgW, $imgH, $imgInitW, $imgInitH); // rotate the rezized image $rotated_image = imagerotate($resizedImage, -$angle, 0); // find new width & height of rotated image $rotated_width = imagesx($rotated_image); $rotated_height = imagesy($rotated_image); // diff between rotated & original sizes $dx = $rotated_width - $imgW; $dy = $rotated_height - $imgH; // crop rotated image to fit into original rezized rectangle $cropped_rotated_image = imagecreatetruecolor($imgW, $imgH); imagecolortransparent($cropped_rotated_image, imagecolorallocate($cropped_rotated_image, 0, 0, 0)); imagecopyresampled($cropped_rotated_image, $rotated_image, 0, 0, $dx / 2, $dy / 2, $imgW, $imgH, $imgW, $imgH); // crop image into selected area $final_image = imagecreatetruecolor($cropW, $cropH); imagecolortransparent($final_image, imagecolorallocate($final_image, 0, 0, 0)); imagecopyresampled($final_image, $cropped_rotated_image, 0, 0, $imgX1, $imgY1, $cropW, $cropH, $cropW, $cropH); // finally output png image //imagepng($final_image, $output_filename.$type, $png_quality); $mysqlObject = new mysqlModule(); $sessionObject = new sessionModule(); $mysqlObject->commandDataBase('INSERT INTO `page_images` (`page`, `path`) VALUES ("' . $sessionObject->getPage() . '", "' . $filename . $type . '")'); imagejpeg($final_image, $output_filename . $type, $jpeg_quality); $response = array("status" => 'success', "url" => $real_filename . $type); } $realImageName = str_replace('../../images/temp/', '', $imgUrl); rename('../../images/page/original/' . $realImageName, '../../images/page/original/' . $filename . $type); unlink($imgUrl); print json_encode($response);
function getCurrentPicture() { $sessionObject = new sessionModule(); $mysqlObject = new mysqlModule(); $table = ''; $images_table = ''; $search_name = ''; $imageName = ''; if ($_POST['pictureType'] === 'currentUserPicture') { $table = 'users'; $images_table = 'profile_images'; $search_name = $sessionObject->getUserName(); $imageName = 'img_id'; $search_subject = 'name'; } else { if ($_POST['pictureType'] === 'currentStoryPicture') { $table = 'story'; $images_table = 'story_images'; $search_name = $_POST['storyName']; $imageName = 'img_id'; $search_subject = 'name'; } else { if ($_POST['pictureType'] === 'currentPagePicture') { $table = 'page'; $images_table = 'page_images'; $search_name = $sessionObject->getPage(); $imageName = 'imageLink'; $search_subject = 'title'; } } } if ($_POST['pictureType'] === 'currentPagePicture') { $imageId = $sessionObject->getPage(); } else { $imageId = $mysqlObject->queryDataBase('SELECT ' . $imageName . ' FROM ' . $table . ' WHERE ' . $search_subject . ' = "' . $search_name . '"')[0][$imageName]; } echo $mysqlObject->queryDataBase('SELECT path FROM ' . $images_table . ' WHERE id = "' . $imageId . '"')[0]['path']; }