RSGallery2 Support Forums
Welcome, Guest. Please login or register.

Login with username, password and session length
  Home    Forum    Help    Search    Login    Register  
*
News : December 03, 2008, 12:13:00 am
+  RSGallery2 Support Forums
|-+  RSgallery2 support forums
| |-+  Features (Moderators: Jonah, Tomislav Ribicic, Daniel Tulp, Ronald Smit)
| | |-+  3 Features
Advanced search
  « previous next »
Pages 1
Author
Topic: 3 Features  (Read 3182 times)
« on: June 12, 2007, 09:56:20 am »
Julio Sene Offline
Newbie
*
Posts: 7



Hi,

First of all, let me say who I am.  My name is Julio, I’m a computer engineer and photographer. I’m from Brazil, English isn’t my first language, but I hope that you understand me.

I have already developed a web site with gallery features to show my photos.  But, at now, I’m planning to migrate to Joomla, to have a flexible environment much more features. With the migration, I create a problem: what can I do with my photos? My first idea was rebuild my gallery system and create a Joomla component, but I decided to try to find a solution with features similar than my gallery and migrate to this new gallery. RSGallery was the gallery that is more similar than my original gallery system. I have already migrate all my photo albums to RSGallery, however there are some features that was implemented on my gallery that RSGallery don’t have. The features that I really need are:
1) Choose the icon (squared) crop position – on my gallery I show 3 options: center image, top/left, right/bottom. It’s very important, especially to images of people.
2) Water mark with images – important to maintain a visual identity. I created a function to merge images and use for it.
3) Create sub-albums and link it directly – It is important to organize photos by main subject. Example: books -> model_1, model_2, model_3, etc ; magazines -> magazine_1, magazine_2, etc.

The good news is that my gallery was writhed in PHP+MySQL and I hope that it can help you to create new features on RSGallery.

Code for function to create icon.
Code:
function gera_ico($image_path, $image_path_save=FALSE, $ico_pos = 1, $max_w=MAX_WIDTH, $max_h=MAX_HEIGHT){
// ico_pos = 1 for center image, 0 for top or left, 2 for right or bottom

    // Get the image complete path
$image_path = PATH_IMG  . $image_path;

// Load image
$img = null;
$extension = strtolower(end(explode('.',$image_path)));

if ($extension == 'jpg' || $extension == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
} else if ($extension == 'png') {
$img = @imagecreatefrompng($image_path);
} else if ($extension == 'gif') {
$img = @imagecreatefromgif($image_path);
} else if ($extension == 'bmp') {
$img = @imagecreatefromwbmp($image_path);
}


// If the image was load, get the width and height
if ($img) {

// Get the image size and scale to resize
$width = imagesx($img);
$height = imagesy($img);
$scale = max($max_w/$width, $max_h/$height);

// If the image is large, reduce
if ($scale < 1) {
$new_width = ceil($scale * $width)+1;
$new_height = ceil($scale * $height)+1;
// Create temp image
$tmp_img = imagecreatetruecolor($max_w, $max_h);
// Copy and resize
$shift_h = 0;
$shift_w = 0;
if ($ico_pos < 2){
if ($new_width > $new_height)
$shift_w = -1*($new_width - $max_w)/($ico_pos+1);
else if($new_width < $new_height)
$shift_h = -1*($new_height - $max_h)/($ico_pos+1);
}

imagecopyresized($tmp_img, $img, $shift_w, $shift_h, 0, 0, $new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
}
else
//echo "Error to load image!";    //--- for debug only!

// Create error image, if necessary
if (!$img) {
$img = imagecreate($max_w, $max_h);
imagecolorallocate($img, 204, 204, 204);
$c = imagecolorallocate($img, 153, 153, 153);
$c1 = imagecolorallocate($img, 0, 0, 0);
imageline($img, 0, 0, $max_w, $max_h, $c);
imageline($img, $max_w, 0, 0, $max_h, $c);
imagestring($img, 5, 5, 5, "Error", $c1);
}

// Save or show image
if($image_path_save){
imagejpeg($img,$image_path_save,95);
}
else{
header('Content-type: image/jpeg');
imagejpeg($img);
}
imagedestroy($img);

}

Water mark function
Code:
function merge_pix($source, $insertfile, $new_filename, $pos = 9, $opac = 50, $output = 'jpg')
{
// find extension
$insertfile_ext = split("[/\\.]", strtolower($insertfile));
$n = sizeof($insertfile_ext)-1;
$ext = $insertfile_ext[$n];
if ($ext == 'jpg')
{
$insertfile_id = imagecreatefromjpeg($insertfile);
}
elseif ($ext == 'png')
{
$insertfile_id = imagecreatefrompng($insertfile);
}
elseif ($ext == 'gif')
{
$insertfile_id = imagecreatefromgif($insertfile);
// Note: GIF support was been removed from ver 1.6
// Patent problem. The patent expire july 2003
}
$source_id = imagecreatefromjpeg($source);

$source_width = imageSX($source_id);
$source_height = imageSY($source_id);
$merge_width = imageSX($insertfile_id);
$merge_height = imageSY($insertfile_id);

switch($pos)
{
case 0: //middle
$dest_x = ( $source_width / 2 ) - ( $merge_width / 2 );
$dest_y = ( $source_height / 2 ) - ( $merge_height / 2 );
break;
case 1:  //top left
$dest_x = 0;
$dest_y = 0;
break;
case 2: //top right
$dest_x = $source_width - $merge_width;
$dest_y = 0;
break;
case 3: //bottom right
$dest_x = $source_width - $merge_width;
$dest_y = $source_height - $merge_height;
break;
case 4: //bottom left
$dest_x = 0;
$dest_y = $source_height - $merge_height;
break;
case 5: //top middle
$dest_x = ( ( $source_width - $merge_width ) / 2 );
$dest_y = 0;
break;
case 6: //middle right
$dest_x = $source_width - $merge_width;
$dest_y = ( $source_height / 2 ) - ( $merge_height / 2 );
break;
case 7: //bottom middle
$dest_x = ( ( $source_width - $merge_width ) / 2 );
$dest_y = $source_height - $merge_height;
break;
case 8: //middle left
$dest_x = 0;
$dest_y = ( $source_height / 2 ) - ( $merge_height / 2 );
break;
case 9: //bottom left but not close
$dest_x = 20;
$dest_y = $source_height - $merge_height - 20;
break;
}
if (function_exists('imagecopymerge'))
{
imagecopymerge($source_id, $insertfile_id, $dest_x, $dest_y, 0, 0, $merge_width, $merge_height, $opac);
}
if ($new_filename != '')
{
switch ($output)
{
case 'jpeg':
imagejpeg($source_id, $new_filename);
break;
case 'jpg':
imagejpeg($source_id, $new_filename);
break;
case 'png':
imagepng($source_id, $new_filename);
break;
case 'gif':
imagegif($source_id, $new_filename);
// Note: GIF support was been removed from ver 1.6
// Patent problem. The patent expire july 2003
break;
case 'bmp':
// only GD greater than ver 1.8
imagewbmp($source_id, $new_filename);
break;
default:
imagejpeg($source_id, $new_filename);
}
}
else
{
// show as jpeg
header("Content-type: image/jpeg");
imagejpeg($source_id,'',100);
}
}

Solution for sub-albums
The solution to create sub-albums is simple: on my database table for albums there are a column for “album ID” and another for “father ID”. If the “father ID” is “0” (default value) this is a principal album.
Logged
 
Reply #1
« on: June 16, 2007, 04:20:24 am »
Daniel Tulp Offline
Administrator
Hero Member
*****
Search search search before posting please Posts: 1870

WWW

thank you for your code, but let me answer a few things first

1) you can always turn off the squared thumbnails and have them proportional
2) the watermark feature is there, but it will cause problem on high traffic sites and causes certain bugs to occur on some servers
we plan on changing it, perhaps your solution is ok, am I correct in understanding that it lays a picture with for instance a logo, on top of the photo? is it created on the fly, or on upload?
3) This feature is already in place, when you create a new gallery, you can assign a Parent to it (or just edit existing galleries)
Logged

RSgallery2 developement team
RSgallery2 modules:
design.danieltulp.nl
 
Reply #2
« on: June 16, 2007, 06:51:11 pm »
Julio Sene Offline
Newbie
*
Posts: 7



Hi Daniel,

Thanks for your attention.

1) I know that can create proportional thumbnail, but I really need squared thumbnails to maintain compatibility with the web site template. On my gallery, I’ve been created just three options to crop the original photo to create the thumbnail. Is unnecessary to create a free crop option, just center, top/left, right/bottom. Unfortunately
it’s very important… Try to create a squared thumbnail, with crop at center, based on this photo http://www.juliosene.com//fotos/4d92ad82a0.jpg.

2) This code was developed to merge two pictures. $source is the photo, and $insertfile is the watermark logo. $new_filename is the name of the file that will be created by this function with the merged picture, if $new_filename is blank, the function just shows the final image. $pos is a number to define the position of the watermark logo into the main picture. $opac is the opacity of the watermark image and $output define the format for the final image. This solution is good to create images with an image as watermark and because is independent than freetype library.

3)Good news!
Logged
 
Print  Pages 1
« previous next »
Jump to: