<?// change to suit your needs eg: define (JPG_QUALITY, '75'); gives a more compressed// image file, but a poorer quality, when re-writing the jpeg after rotation.define('JPG_QUALITY', '100'); //define variables and includes (should be no need to change these)define('ROOT_PATH', './../');include(ROOT_PATH.'global.php');require(ROOT_PATH.'includes/sessions.php');$user_access = get_permission();//is there an image_id and does the user have permission to delete the image? If not, send them back to the index page!if (!$image_id || ($config['user_delete_image'] != 1)) { header("Location: ".$site_sess->url(ROOT_PATH."index.php", "&")); exit; } //if ok so far, read the image info from the database $sql = "SELECT image_id, cat_id, user_id, image_name, image_media_file, image_thumb_file FROM ".IMAGES_TABLE." WHERE image_id = $image_id"; $image_row = $site_db->query_firstrow($sql);//is the user a registered user and the 'owner' of the image? If not, send them back to the index page! if ($user_info['user_level'] == ADMIN OR !$image_row || $image_row['user_id'] <= USER_AWAITING || ($user_info['user_id'] = $image_row['user_id'])) { //so far so good, more variables need defining...$ok=false;$file=$image_row[image_media_file];$cat_id=$image_row[cat_id];$path_to_media = ROOT_PATH.MEDIA_DIR."/".$cat_id."/";$path_to_thumbs = ROOT_PATH.THUMB_DIR."/".$cat_id."/";$ext = get_file_extension($file); //clockwise or anticlockwise?$degrees=0;if ($wize=="neg"){$degrees = 90;}if ($wize=="180"){$degrees = 180;}if ($wize=="pos"){$degrees = 270;}// Load existing images (if a 'jpg')if (($ext == "jpg") || ($ext == "jpeg")){ $source_image = imagecreatefromjpeg($path_to_media.$file);$source_thumb = imagecreatefromjpeg($path_to_thumbs.$file);$ok=true;}// Load existing images (if a 'gif')if ($ext == "gif"){ $source_image = imagecreatefromgif($path_to_media.$file);$source_thumb = imagecreatefromgif($path_to_thumbs.$file);$ok=true;}if ($ok) //is it ok to process?{ // Rotate $rotate_image = imagerotate($source_image, $degrees, 0); $rotate_thumb = imagerotate($source_thumb, $degrees, 0); //Create new file names using timestamp as 'random' prefix to force browser to reload $new_file_name=time().".".$ext; $new_image = $path_to_media.$new_file_name; $new_thumb = $path_to_thumbs.$new_file_name; //Output 'new' images if (($ext == "jpg") || ($ext == "jpeg")) { imagejpeg($rotate_image,$new_image,JPG_QUALITY); imagejpeg($rotate_thumb,$new_thumb,JPG_QUALITY); } if ($ext == "gif") { imagegif($rotate_image,$new_image); imagegif($rotate_thumb,$new_thumb); } //Delete 'old' files unlink($path_to_media.$file); unlink($path_to_thumbs.$file); imagedestroy($rotate_image); imagedestroy($rotate_thumb); imagedestroy($source_image); imagedestroy($source_thumb); //write 'new' filenames to database $sql=" UPDATE `4images_images` SET `image_media_file` = '$new_file_name',`image_thumb_file` = '$new_file_name' WHERE `image_id` = '$image_id' LIMIT 1"; $result = $site_db->query($sql);} //end of processing//display new rotated imageheader("Location: ".$site_sess->url(ROOT_PATH."details.php?&".URL_IMAGE_ID."=".$image_id, "&"));} elseif (!$image_row || $image_row['user_id'] <= USER_AWAITING || ($user_info['user_id'] != $image_row['user_id'])) { header("Location: ".$site_sess->url(ROOT_PATH."index.php", "&")); exit; }?>
if ($user_info['user_level'] == ADMIN) { $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=editimage&image_id=".$image_id))."\" target=\"_blank\">".$lang['edit']."</a> "; $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=removeimage&image_id=".$image_id))."\" target=\"_blank\">".$lang['delete']."</a> ";}
if ($user_info['user_level'] == ADMIN) { $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=editimage&image_id=".$image_id))."\" target=\"_blank\">".$lang['edit']."</a> "; $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=removeimage&image_id=".$image_id))."\" target=\"_blank\">".$lang['delete']."</a> "; $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=90")."\">".$lang['rotate_neg']."</a> "; $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=270")."\">".$lang['rotate_pos']."</a>";}
<?// change to suit your needs eg: define (JPG_QUALITY, '75'); gives a more compressed// image file, but a poorer quality, when re-writing the jpeg after rotation.define('JPG_QUALITY', '100'); //define variables and includes (should be no need to change these)define('ROOT_PATH', './../');include(ROOT_PATH.'global.php');require(ROOT_PATH.'includes/sessions.php');$user_access = get_permission();//is there an image_id and does the user have permission to delete the image? If not, send them back to the index page!if (!$image_id || ($config['user_delete_image'] != 1)) { header("Location: ".$site_sess->url(ROOT_PATH."index.php", "&")); exit; } //if ok so far, read the image info from the database $sql = "SELECT image_id, cat_id, user_id, image_name, image_media_file, image_thumb_file FROM ".IMAGES_TABLE." WHERE image_id = $image_id"; $image_row = $site_db->query_firstrow($sql);//is the user a registered user and the 'owner' of the image? If not, send them back to the index page! if (!$image_row || $image_row['user_id'] <= USER_AWAITING || ($user_info['user_id'] != $image_row['user_id'])) { header("Location: ".$site_sess->url(ROOT_PATH."index.php", "&")); exit; } //so far so good, more variables need defining...$ok=false;$file=$image_row[image_media_file];$cat_id=$image_row[cat_id];$path_to_media = ROOT_PATH.MEDIA_DIR."/".$cat_id."/";$path_to_thumbs = ROOT_PATH.THUMB_DIR."/".$cat_id."/";$ext = get_file_extension($file); //clockwise or anticlockwise?$degrees=0;if ($wize=="pos"){$degrees = 270;}if ($wize=="neg"){$degrees = 90;}// Load existing images (if a 'jpg')if (($ext == "jpg") || ($ext == "jpeg")){ $source_image = imagecreatefromjpeg($path_to_media.$file);$source_thumb = imagecreatefromjpeg($path_to_thumbs.$file);$ok=true;}// Load existing images (if a 'gif')if ($ext == "gif"){ $source_image = imagecreatefromgif($path_to_media.$file);$source_thumb = imagecreatefromgif($path_to_thumbs.$file);$ok=true;}if ($ok) //is it ok to process?{ // Rotate $rotate_image = imagerotate($source_image, $degrees, 0); $rotate_thumb = imagerotate($source_thumb, $degrees, 0); //Create new file names using timestamp as 'random' prefix to force browser to reload $new_file_name=time().".".$ext; $new_image = $path_to_media.$new_file_name; $new_thumb = $path_to_thumbs.$new_file_name; //Output 'new' images if (($ext == "jpg") || ($ext == "jpeg")) { imagejpeg($rotate_image,$new_image,JPG_QUALITY); imagejpeg($rotate_thumb,$new_thumb,JPG_QUALITY); } if ($ext == "gif") { imagegif($rotate_image,$new_image); imagegif($rotate_thumb,$new_thumb); } //Delete 'old' files unlink($path_to_media.$file); unlink($path_to_thumbs.$file); imagedestroy($rotate_image); imagedestroy($rotate_thumb); imagedestroy($source_image); imagedestroy($source_thumb); //write 'new' filenames to database $sql=" UPDATE `4images_images` SET `image_media_file` = '$new_file_name',`image_thumb_file` = '$new_file_name' WHERE `image_id` = '$image_id' LIMIT 1"; $result = $site_db->query($sql);} //end of processing//display new rotated imageheader("Location: ".$site_sess->url(ROOT_PATH."details.php?&".URL_IMAGE_ID."=".$image_id, "&"));?>