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.
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
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.