4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: pietg on May 20, 2003, 10:24:39 PM
-
Hello All,
Just wondering.
Is it possible to tweak 4images to make it able for visitors of the gallery to rotate the picture on there screen?
So if a picture is oriented the wrong way, people can "rotate" it and view it the right way.
Hope somebody knows a trick to do this.
Kind regards,
Piet
-
There are plenty of third party Java applets, browser plugins and DHTML scripts out there that do this already.
-
Hi Chris,
Completely forgot to search :oops:
I searched hotscripts.com and now I can do a lot of things like scale, zoom, snow, swirl, tunnel, warp etc with the pictures but not what I want.
Maybe I am looking at the wrong place?
All I want is two extra buttons next to the picture in the details.php. One to flip the pic to the left and one to the right. If somebody clicks on the button the pciture should turn.
Could somebody help me with this? Perhaps lead me to the right script.
Kind regards,
Piet
-
Try this script (fairly basic at the moment). Copes with jpg and gif files. Only rotates the image 900 clockwise, but this can be changed within the script by amending the variable $degrees.
Add a new script /includes/rotate.php
<?
//define variables and includes...
define('GET_CACHES', 1);
define('ROOT_PATH', './../');
include(ROOT_PATH.'global.php');
require(ROOT_PATH.'includes/sessions.php');
$user_access = get_permission();
$path_to_media = ROOT_PATH."data/media/".$cat_id."/";
$path_to_thumbs = ROOT_PATH."data/thumbnails/".$cat_id."/";
$ext=eregi( ".([^\.]+)$", $file, $r ) ? $r[1] : "";
$ok=false;
$degrees = 270;
// Load existing images
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 ($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
$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);
imagejpeg($rotate_thumb,$new_thumb);
}
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, "&"));
?>
Go to ./details.php.
Find:
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>";
}
Replace with:
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&cat_id=".$image_row['cat_id']."&file=".$image_row['image_media_file'])."\">".$lang['rotate']."</a> ";
}
This adds a link [rotate] to the options of [edit] and [delete]
After rotation the image is re-displayed.
Go to ./lang/{your language}/main.php
Find:
$lang['edit'] = "[Edit]";
$lang['delete'] = "[Delete]";
Add below:
$lang['rotate'] = "[Rotate]";
Note: The image is renamed by the script, so that the browser is forced to display the 'new' image, otherwise it may show the cached version. Multiple rotations will degrade the picture quality.
-
@boatman9999:
a few things:
- define('GET_CACHES', 1); is not needed in your case
- there is no check if user is admin, so anyone who knows about existing rotate.php file could rotate the images.
- for jpeg files u should use quality value, otherwise it will use 75 which is not quet enough (IMO) (reference: http://php.net/manual/en/function.imagejpeg.php)
-
Thanks again V@no for your feedback.
Some changes made in line with your comments and script now able to rotate clockwise or anti-clockwise by clicking appropriate link. Script now also uses a more standard approach to coding.
Add a new script /includes/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, "&"));
?>
Go to ./details.php.
Find:
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>";
}
Replace with:
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=neg")."\">".$lang['rotate_neg']."</a> ";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=pos")."\">".$lang['rotate_pos']."</a>";
}
Go to ./lang/{your language}/main.php
Find:
$lang['edit'] = "[Edit]";
$lang['delete'] = "[Delete]";
Add below:
$lang['rotate_neg'] = "[Rotate-Anti Clockwise]";
$lang['rotate_pos'] = "[Rotate-Clockwise]";
-
I have tried your code and can't get it working :(
I even tried modifying to:
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a> ";
$admin_links .= ($config['user_rotate_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=neg")."\">".$lang['rotate_neg']."</a> ";
$admin_links .= ($config['user_rotate_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=pos")."\">".$lang['rotate_pos']."</a>";
I use a template on my site. You can see the site here:
www.the-real.com/pics
Thanks for any info? If you need more details let me know.
-
When you say it doesn't work, what doesn't work?
Do the links show up correctly, but the image fails to rotate or can you not even see the links?
If the latter, does the person viewing have authority to delete the image? If not, then the links will not display.
If the links show up, do you get any other error messages when you try to use them?
-
I login as my admin account. I should have authority to delete? I do not see the links at all.
-
If you are logged in as Admin you won't see the links unless you add the links to the bit of the script which checks if the user_level is ADMIN.
If you want to do this go to details.php and then find
// Admin Links
$admin_links = "";
if ($user_info['user_level'] == ADMIN) {...
then add in the new links :
$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=neg")."\">".$lang['rotate_neg']."</a> ";
$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=pos")."\">".$lang['rotate_pos']."</a>";
below the existing ones. Remember to paste the new links before the closing ' }' of the if statement.
-
I,ve tried it, but it doesn`t work. If I click at the rotate-button, I come to the startsite. And only the admin can rotate? It would be better, if the user could rotate too. Whats my mistake? :oops:
-
The original MOD allowed only the image 'owner' to rotate, so if you install that as described then it should work.
Users who do not 'own' the image cannot rotate it, otherwise someone could go to your site and turn all the pictures upside down!
The second amendment is an add-on and allowed the admin to rotate also.
-
Oh, thanx, how silli. 8O (Me) :P
-
There is no button. It doesn´t work. :roll:
-
There's no button where? More details please.
-
To add the rotate button for the admin:
Replace includes/rotate.php with this:
<?
// 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 image
header("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;
}
?>
Open details.php
FIND:
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> ";
}
REPLACE WITH:
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>";
}
When an Image is uploaded, you get a page with te result, is it possible to add the rotate option to that page?
:!:
-
I found it out myself:
Open member.php
Find:$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n".$media."\n</td>\n</tr>\n</table>\n";
Replace with:$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n<div align=\"center\"><a href=\"./includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=neg\">".$lang['rotate_neg']."</a> <a href=\"./includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=pos\">".$lang['rotate_pos']."</a></div><br />".$media."\n</td>\n</tr>\n</table>\n";
-
Boatman, many thanks for this code. Great time saver. Has there been any further development of this code? It would be great if admin had this ability not just at upload time but at any time. This would be good for editing after a bulk upload. If a zoom function could be added 4images in my opinion would be very much enhanced.
All the best, and thanks again.
Pete
-
... If a zoom function could be added 4images in my opinion would be very much enhanced. ...
... it is possible ... but it is only a example an only for IE ... here (http://klick.kl.funpic.de/details.php?image_id=3107)
-
That looks nice. Any idea where the code is available?
-
Boatman, many thanks for this code. Great time saver. Has there been any further development of this code?
Sorry. No further development at this stage, I just don't have the time. Anybody is welcome to add to the code if they have anything to input.
-
I found it out myself:
Open member.php
Find:$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n".$media."\n</td>\n</tr>\n</table>\n";
Replace with:$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n<div align=\"center\"><a href=\"./includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=neg\">".$lang['rotate_neg']."</a> <a href=\"./includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=pos\">".$lang['rotate_pos']."</a></div><br />".$media."\n</td>\n</tr>\n</table>\n";
I think you meant :
$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n<div align=\"center\"><a href=\"./includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=neg\">".$lang['rotate_neg']."</a> <a href=\"./includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=pos\">".$lang['rotate_pos']."</a></div><br />".$media."\n</td>\n</tr>\n</table>\n";
with this one :
$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n<div align=\"center\"><a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=neg")."\">".$lang['rotate_neg']."</a> <a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=pos")."\">".$lang['rotate_pos']."</a></div><br />".$media."\n</td>\n</tr>\n</table>\n";
;)
-
I am trying this on another 4images site I have just created and it just bounces back to the index.php after clickign the rotate button and doesn't change the picture. Any ideas?
-
Would it be possible to see the codings you made ? It would be a lot more easier to determine the source of the problem. ;)
-
//is there an image_id and does the user have permission to delete the image? If not, send them back to the index page!
OK that is what the problem is. I logged in as the user (family site) and it allowed to rotate. Let me go back and check the code...wow that was a fast response!
//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;
}
I think this is the problem. I can delete as an admin I just checked.
Would there be a snippet of code that could replace this to just check if it's user owner or admin?
Oh Wait! If I have it setup that users can delete their own posts, then I don't even need this code, correct? Cause it checks here:
//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'])) {
Does that make sense?
-
Disgarding the fact the replacement above is the not the correct way to call it, in which file did you applyed these modifications ? More details please.
-
ok in rotate.php I have edited the checking permissions area to come up with:
<?
// 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;
// }
//is the user an administrator? If not, send them back to the index page!
if ($user_info['user_id'] != ADMIN) {
header("Location: ".$site_sess->url(ROOT_PATH."index.php", "&"));
exit;
}
//so far so good, more variables need defining...
this isn't working however either. Basically I only want admins to be able to rotate the pictures. I can deal with the templates/links. Thanks Oracle!
-
If rotates.php file is under the includes folder, there's no need to include this block :
//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();
However, you'd need to import the file in the appropriate source file from your ROOT_PATH instead. ;)
//is the user an administrator? If not, send them back to the index page!
if ($user_info['user_id'] != ADMIN) {
header("Location: ".$site_sess->url(ROOT_PATH."index.php", "&"));
exit;
}
move it below :
//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;
// }
As for this line,
if (!$image_row || $image_row['user_id'] <= USER_AWAITING || ($user_info['user_id'] != $image_row['user_id'])) {
you could say :
$check_user = $user_info['user_level'] == ADMIN;
if (!$image_row || $image_row['user_id'] != $check_user) {
However, you might hear other inputs on this.
-
I have just disabled all checks within rotate.php :?
The links will only showup for admins. Hopefully no-one is mean enough to find out which site it is and rotate all my pictures! (BTW I have never posted the link here!) :lol:
Oh, and I needed to have the
//define variables and includes (should be no need to change these)
or else I got errors.
-
Your condition is wrong, you must use user_level and not user_id ;)
here is the fixed version of conditional block:<?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 user is admin? If not, send them back to the index page!
if (!$image_id || $user_info['user_level'] != ADMIN) {
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);
//did we get any result from the database? If not, send them back to the index page!
if (!$image_row) {
header("Location: ".$site_sess->url(ROOT_PATH."index.php", "&"));
exit;
}
//so far so good, more variables need defining...
-
Works like a champ...thanks V@no!
-
We have one post after another flipping stuff around and it's getting a little confusing. I understand this is how things improve through community participation but I'm not sure which posters found a working solution as some people are updating pieces of other's work.
I was wondering if someone can post a verified final working version of this all in one place.
I've tried every rotate.php script version in this thread and none of them are working for me.
Depending on the version of rotate.php I get one of two things...
1. White screen and nothing else happens.
or
2. Internal Server Error.
I'm using 4images 1.7.2
I'm only interested in the admin having this new function. So I added the rotate.php to the includes directory. I added the rotate text to my language file. Then I changed the details.php so that there are links for the admin to rotate on the details page. (the links are displaying fine.)
That's all I did. Did I miss something or do I need to find the correct "rotate.php" version or combination of pieces of these rotate.php versions?
-
To add the rotate button for the admin:
Replace includes/rotate.php with this:
<?
// 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 image
header("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;
}
?>
Open details.php
FIND:
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> ";
}
REPLACE WITH:
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>";
}
When an Image is uploaded, you get a page with te result, is it possible to add the rotate option to that page?
:!:
Even though I found a major problem with your code, I still can't get it to work. :!:
:arrow: In your rotate.php you are looking for variable wize to be "pos"...
[qcode]//clockwise or anticlockwise?
$degrees=0;
if ($wize=="neg"){$degrees = 90;}
if ($wize=="180"){$degrees = 180;}
if ($wize=="pos"){$degrees = 270;}
[/qcode]
:arrow: But your new admin links are passing variable wize as "270"...
[qcode]$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&wize=270")."\">".$lang['rotate_pos']."</a>";[/qcode]
-
Iv'e tried this with 1.7.4 without luck. The links are shown, but nothing happens when clicked. Am I missing something?
Thanks!
-
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'])) {
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, "&"));
?>
-
I'm looking for a script that rotates an image like the one in the first post!
My version is the latest 1.7.10... Is there a chance to get it work?
Martin
-
How can i do this with V1.8?
Is there a ready made mod/plug in?
Will the solution given in this thread work with 1.8?