raygene Posted May 9, 2007 Share Posted May 9, 2007 Hi, I need help with the following script for my phpbb driven free dating site and at this moment, it does crop and if you right click on the image, you may save it to your computer. See it in action here: http://www.matesjunction.com/mjfdatebb/profile.php?mode=cropimg If possible, I would like to have the following functions added or modified: - A proportional 3 X 4 portrait cropping canvas in percentages to keep all of my board's images consistent and the Resize Uploaded Avatars Mod would resize it to my board's 120 X 160 default size. This crop canvas cannot be lower than my board's default for the resize mod only reduces, not enlarge the image. - The actual cropping rectangle doesn't go to any of the edges of an image, it resizes within a few pixels inside of the edge. - When right clicked and saved, a PHP extension is added as a default instead of the original JPG file type, meaning that the user has to rename "imagename.php" to "imagename.jpg". Can this be corrected? - To avoid the above, could a "download" function be implemented thus saving extra steps for the user? Also, if there is a better script which would be easy to implement, please let me know. Thanks, Raygene <?php if (!defined('IN_PHPBB')) { exit; } // Session management $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); $u_frame = append_sid("{$phpbb_root_path}profile.$phpEx?mode=cropimg&action=frame"); $action = (isset($HTTP_GET_VARS['action'])) ? (string) $HTTP_GET_VARS['action'] : ''; if ($action == 'frame') { $cache_image = (isset($HTTP_POST_VARS['cache_image']) && file_exists($phpbb_root_path . 'cache/' . (int) $HTTP_POST_VARS['cache_image'])) ? (int) $HTTP_POST_VARS['cache_image'] : false; if (!$cache_image) { if (isset($_FILES['upload'])) { $errors = array(); $_FILES['upload'] = (array) $_FILES['upload']; $filename = basename($_FILES['upload']['name']); $filename = str_replace(array("\t", ' ', '/', '\\', '<', '>', '|', ':', '"', ';', "'"), '', $filename); $filesize = filesize($_FILES['upload']['tmp_name']); if (empty($filename)) { $errors[] = 'You didn\'t upload a file'; } if ($_FILES['upload']['error']) { $errors[] = 'There was something wrong with your file'; } $rand_name = time() + rand(); $move_to = $phpbb_root_path . 'cache/' . $rand_name; if (!is_uploaded_file($_FILES['upload']['tmp_name'])) { $errors[] = 'Hacking attempt'; } if (!sizeof($errors) && !@move_uploaded_file($_FILES['upload']['tmp_name'], $move_to)) { $errors[] = 'The uploaded file "' . $filename . '" could not be moved'; } if (!sizeof($errors)) { echo ' <form method="post" action="' . $u_frame . '" > <input type="hidden" name="cache_image" value="' . $rand_name . '" /> <input type="submit" name="submit" value="Continue" /> </form>'; } else { echo 'Sorry, an error occured. Your file was unable to be uploaded:' . '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>' . 'Click <a href="' . $u_frame . '">here</a> to return to the upload page.'; } } else { echo ' <form method="post" action="' . $u_frame . '" enctype="multipart/form-data"> <input type="file" name="upload" value="" /><br /> <input type="submit" name="submit" value="Upload" /> </form>'; } } else { $image = "{$phpbb_root_path}profile.$phpEx?mode=cropimg&action=image&image=$cache_image"; if (!isset($HTTP_POST_VARS['tx']) && !isset($HTTP_POST_VARS['fx'])) { echo ' <form method="post" action="'.$u_frame.'"> <input type="image" src="'.$image.'" /> <input type="hidden" name="cache_image" value="' . $cache_image . '" /> <br />'; if (!isset($HTTP_POST_VARS['x'])) { echo '<br /> Click to mark first corner, start in the upper left of the desired area'; } else { echo ' <input type="hidden" name="fx" value="'.$HTTP_POST_VARS['x'].'" /> <input type="hidden" name="fy" value="'.$HTTP_POST_VARS['y'].'" /><br /> Click to mark second corner, lower right of the desired area | <a href="'.$u_frame.'">start over</a>'; } echo ' </form> '; } if (isset($HTTP_POST_VARS['fx'])) { echo ' <form method="post" action="'.$u_frame.'"> <input type="hidden" name="cache_image" value="' . $cache_image . '" /> <input type="image" src="'.$image.'" /><br /> <input type="hidden" name="tx" value="'.$HTTP_POST_VARS['fx'].'" /> <input type="hidden" name="ty" value="'.$HTTP_POST_VARS['fy'].'" /> <input type="hidden" name="width" value="'.($HTTP_POST_VARS['x']-$HTTP_POST_VARS['fx']).'" /> <input type="hidden" name="height" value="'.($HTTP_POST_VARS['y']-$HTTP_POST_VARS['fy']).'" /> <div style="position: absolute; left:'.($HTTP_POST_VARS['fx']).'px; top: '.($HTTP_POST_VARS['fy']).'px; width: '.($HTTP_POST_VARS['x']-$HTTP_POST_VARS['fx']).'px; height: '.($HTTP_POST_VARS['y']-$HTTP_POST_VARS['fy']).'px; border: 1px solid #fff;"> </div><br /> Click image outside the crop rectangle | <a href="'.$u_frame.'">start over</a> </form>'; } if (isset($HTTP_POST_VARS['tx'])) { $dest_image = $phpbb_root_path . 'cache/' . $cache_image . '_new'; $img = @imagecreatetruecolor($HTTP_POST_VARS['width'],$HTTP_POST_VARS['height']); $org_img = @imagecreatefromjpeg($phpbb_root_path . 'cache/' . $cache_image); $ims = @getimagesize($phpbb_root_path . 'cache/' . $cache_image); @imagecopy($img,$org_img, 0, 0, $HTTP_POST_VARS['tx'], $HTTP_POST_VARS['ty'], $ims[0], $ims[1]); @imagejpeg($img,$dest_image,90); @imagedestroy($img); @unlink($phpbb_root_path . 'cache/' . $cache_image); echo ' <img src="'.$image.'&new_img=1" width="'.$HTTP_POST_VARS['width'].'" height="'.$HTTP_POST_VARS['height'].'" alt="" /><br /><br /> If satisfied, right click on the photo, left click on Save, type in a name<br/>with a <b>.jpg extension</b> and click the Close Window button at the bottom<br/>of the page. Congratulations, you now have a proper photo to upload.<br />If not, <a href="'.$u_frame.'">start over</a>.'; } } exit; } else if ($action == 'image') { $image = (isset($HTTP_GET_VARS['image'])) ? (int) $HTTP_GET_VARS['image'] : false; if (isset($HTTP_GET_VARS['new_img'])) { $image .= '_new'; } $image_path = ($image) ? "{$phpbb_root_path}cache/$image" : false; if ($image && file_exists($image_path)) { header('Content-type: image/jpg'); readfile($image_path); exit; } } // Output $page_title = 'Crop image'; $gen_simple_header = true; include("{$phpbb_root_path}includes/page_header.$phpEx"); // Template assignements... $template->set_filenames(array( 'body' => 'profile_cropimg_body.tpl', )); $template->assign_vars(array( 'U_FRAME' => $u_frame, )); $template->pparse('body'); include("{$phpbb_root_path}includes/page_tail.$phpEx"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/50721-need-help-with-interactive-image-cropping-script/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.