1
Mods & Plugins (Requests & Discussions) / Re: Rotating picture by user online
« on: June 28, 2008, 05:24:24 PM »
Hi,
i have the same problem.
The button for "rotate" is still there but the code does not rotate the image. After the operation as "root" i am in the index.php.
Can someone help me?
Deutsch:
Ich habe das gleiche Problem.
Der Button ist da aber wenn ich darauf klicke lande ich in der index.php im Hauptverzeichnis.
Kann jemand helfen?
Eremit
-> rotate.php
<?
// 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'])) {
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?
{
} //end of processing
//display new rotated image
header("Location: ".$site_sess->url(ROOT_PATH."details.php?&".URL_IMAGE_ID."=".$image_id, "&"));
?>
i have the same problem.
The button for "rotate" is still there but the code does not rotate the image. After the operation as "root" i am in the index.php.
Can someone help me?
Deutsch:
Ich habe das gleiche Problem.
Der Button ist da aber wenn ich darauf klicke lande ich in der index.php im Hauptverzeichnis.
Kann jemand helfen?
Eremit
-> rotate.php
<?
// 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 image
header("Location: ".$site_sess->url(ROOT_PATH."details.php?&".URL_IMAGE_ID."=".$image_id, "&"));
?>