4images Forum & Community
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 18, 2018, 08:42:32 AM

Login with username, password and session length
Search:     Advanced search
4images is now on facebook. Click here and become a fan!
Togle to toolbar
Translate this page with =>
Translate this page >
* Home Help Search Login Register
 
+  4images Forum & Community
|-+  4images Modifications / Modifikationen
| |-+  Mods & Plugins (Requests & Discussions) (Moderators: mawenzi, Rembrandt)
| | |-+  Rotating picture by user online
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 3 » »» Print
Author Topic: Rotating picture by user online  (Read 36784 times)
pietg
Jr. Member
**
Offline Offline

Posts: 86

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« 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
Logged
Chris
4images Moderator
4images Guru
*****
Offline Offline

Posts: 4487

Thank You
-Given: 0
-Receive: 31

Did u ever stop to think and then forget to start?


View Profile
« Reply #1 on: May 21, 2003, 12:25:44 AM »

There are plenty of third party Java applets, browser plugins and DHTML scripts out there that do this already.
Logged

pietg
Jr. Member
**
Offline Offline

Posts: 86

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« Reply #2 on: May 21, 2003, 10:34:52 AM »

Hi Chris,

Completely forgot to search  Embarassed

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
Logged
boatman9999
Jr. Member
**
Offline Offline

Posts: 50

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #3 on: May 06, 2005, 07:48:18 PM »

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?

//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:
1
2
3
4
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a>&nbsp;";
  $admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>";
}

Replace with:
1
2
3
4
5
6
elseif ($is_image_owner) {
  $admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a>&nbsp;";
  $admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>&nbsp;";
  $admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;cat_id=".$image_row['cat_id']."&amp;file=".$image_row['image_media_file'])."\">".$lang['rotate']."</a>&nbsp;";
   
}
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:
1
2
$lang['edit'] = "[Edit]";
$lang['delete'] = "[Delete]";

Add below:
1
$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.
Logged
V@no
If you don't tell me what to do, I won't tell you where you should go :)
Administrator
4images Guru
*****
Offline Offline

Posts: 17849

Thank You
-Given: 47
-Receive: 577

mmm PHP...


View Profile WWW
« Reply #4 on: May 06, 2005, 08:17:55 PM »

@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)
Logged

Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)
boatman9999
Jr. Member
**
Offline Offline

Posts: 50

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #5 on: May 15, 2005, 11:07:28 AM »

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?
// 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:

1
2
3
4
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a>&nbsp;";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>";
}

Replace with:

1
2
3
4
5
6
elseif ($is_image_owner) {
$admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a>&nbsp;";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>&nbsp;";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;wize=neg")."\">".$lang['rotate_neg']."</a>&nbsp;";
$admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;wize=pos")."\">".$lang['rotate_pos']."</a>";
}

Go to ./lang/{your language}/main.php
Find:

1
2
$lang['edit'] = "[Edit]";
$lang['delete'] = "[Delete]";

Add below:

1
2
$lang['rotate_neg'] = "[Rotate-Anti Clockwise]";
$lang['rotate_pos'] = "[Rotate-Clockwise]";





Logged
lemccoy
Jr. Member
**
Offline Offline

Posts: 90

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« Reply #6 on: August 16, 2005, 02:02:34 PM »

I have tried your code and can't get it working  Sad


I even tried modifying to:

       $admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>&nbsp;";
       $admin_links .= ($config['user_rotate_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;wize=neg")."\">".$lang['rotate_neg']."</a>&nbsp;";
       $admin_links .= ($config['user_rotate_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;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.
Logged
boatman9999
Jr. Member
**
Offline Offline

Posts: 50

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #7 on: August 17, 2005, 05:41:04 PM »

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?
Logged
lemccoy
Jr. Member
**
Offline Offline

Posts: 90

Thank You
-Given: 0
-Receive: 0


View Profile WWW
« Reply #8 on: August 17, 2005, 10:57:12 PM »

I login as my admin account.  I should have authority to delete?  I do not see the links at all.
Logged
boatman9999
Jr. Member
**
Offline Offline

Posts: 50

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #9 on: August 20, 2005, 07:14:28 PM »

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


1
2
3
// Admin Links
$admin_links = "";
if ($user_info['user_level'] == ADMIN) {...

then add in the new links :

1
2
$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;wize=neg")."\">".$lang['rotate_neg']."</a>&nbsp;";
$admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."includes/rotate.php?".URL_IMAGE_ID."=".$image_id."&amp;wize=pos")."\">".$lang['rotate_pos']."</a>";


below the existing ones. Remember to paste the new links before the closing ' }' of the if statement.
Logged
Momo
Newbie
*
Offline Offline

Posts: 17

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #10 on: October 09, 2005, 11:54:46 AM »

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?  Embarassed
Logged
boatman9999
Jr. Member
**
Offline Offline

Posts: 50

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #11 on: October 18, 2005, 01:03:56 PM »

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.
Logged
Momo
Newbie
*
Offline Offline

Posts: 17

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #12 on: October 18, 2005, 05:26:07 PM »

Oh, thanx, how silli.  Shocked (Me)   Razz
Logged
Momo
Newbie
*
Offline Offline

Posts: 17

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #13 on: October 18, 2005, 05:38:37 PM »

There is no button. It doesn´t work.   Rolling Eyes
Logged
boatman9999
Jr. Member
**
Offline Offline

Posts: 50

Thank You
-Given: 0
-Receive: 0


View Profile
« Reply #14 on: October 22, 2005, 07:25:25 PM »

There's no button where? More details please.
Logged
Pages: [1] 2 3 » »» Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.055 seconds with 19 queries.