Author Topic: Rotating picture by user online  (Read 56417 times)

0 Members and 1 Guest are viewing this topic.

Offline lemccoy

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • DrunkIsland
Re: Rotating picture by user online
« Reply #30 on: February 18, 2006, 01:50:06 PM »
Works like a champ...thanks V@no!

Offline sparky

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Rotating picture by user online
« Reply #31 on: October 16, 2006, 11:31:16 PM »
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?

Offline sparky

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Rotating picture by user online
« Reply #32 on: October 17, 2006, 12:00:59 AM »
To add the rotate button for the admin:

Replace includes/rotate.php with this:
Code: [Select]
<?
// 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:
Code: [Select]
if ($user_info['user_level'] == ADMIN) {
  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=editimage&amp;image_id=".$image_id))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=removeimage&amp;image_id=".$image_id))."\" target=\"_blank\">".$lang['delete']."</a>&nbsp;";
}

REPLACE WITH:
Code: [Select]
if ($user_info['user_level'] == ADMIN) {
  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=editimage&amp;image_id=".$image_id))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=removeimage&amp;image_id=".$image_id))."\" target=\"_blank\">".$lang['delete']."</a>&nbsp;";
  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;wize=90")."\">".$lang['rotate_neg']."</a>&nbsp;";
  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;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."&amp;wize=270")."\">".$lang['rotate_pos']."</a>";[/qcode]

Offline matosale

  • Full Member
  • ***
  • Posts: 160
    • View Profile
    • My Way of Life
Re: Rotating picture by user online
« Reply #33 on: October 11, 2007, 06:05:08 PM »
Iv'e tried this with 1.7.4 without luck. The links are shown, but nothing happens when clicked. Am I missing something?
Thanks!
Alejandro Matos
   Lima - Perú

   Linz - Austria
   Helsinki - Finland
   Seville - Spain



Offline Eremit

  • Pre-Newbie
  • Posts: 6
    • View Profile
Re: Rotating picture by user online
« Reply #34 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'])) {
  
	
  
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$degrees0);
	
	
$rotate_thumb imagerotate($source_thumb$degrees0);

	
//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"&"));


?>
« Last Edit: November 04, 2011, 04:47:52 AM by Rembrandt »

Offline maylord

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: Rotating picture by user online
« Reply #35 on: November 03, 2011, 09:53:53 PM »
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

Offline Redstick

  • Pre-Newbie
  • Posts: 1
    • View Profile
Re: Rotating picture by user online
« Reply #36 on: June 27, 2017, 11:07:36 PM »
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?