4images Modifications / Modifikationen > Mods & Plugins (Requests & Discussions)

Rotating picture by user online

(1/8) > >>

pietg:
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

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

pietg:
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

boatman9999:
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


--- Code: ---<?

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


?>
--- End code ---

Go to ./details.php.

Find:

--- Code: ---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>";
}

--- End code ---

Replace with:

--- Code: ---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;";
   
}

--- End code ---
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:

--- Code: ---$lang['edit'] = "[Edit]";
$lang['delete'] = "[Delete]";
--- End code ---

Add below:

--- Code: ---$lang['rotate'] = "[Rotate]";
--- End code ---

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.

V@no:
@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)

Navigation

[0] Message Index

[#] Next page

Go to full version