|
|
Image Gallery Tutorial Using Hoverbox - A php solution to coding the Hoverbox Image Gallery | ||
Discussion by jlhaslip with 16 Replies.
Last Update: February 11, 2011, 2:25 am ( View Rated (2) ) | |||
![]() |
|
|
I liked the css included in the original Tutorial as found on the Sonspring site, but I knew there was more than one use for the Hoverbox and took it upon myself to explore the use of the Hoverbox on a site I webmaster.
- One thing that wasn't right was having to hardcode the image tags, so the first version I wrote used php to fill the Hoverbox by reading the Image filenames from the Image folder and inserting them into the html.
- Another was the use of the anchor (<a>) tag to trick Internet Explorer into activating the on-hover event, so I included the filename as the target of the anchor tag so that the on-click event actually does something. It opens a window and displays the full sized picture in your browser.
- The website I wanted to use the Image Gallery on is for a Minor Hockey program and I also wanted a 'randomization' of the pictures so that each time you viewed the page a different selection of pictures was displayed. This avoids the possibility of suspicious selection methods (Why isn't little Johnny's picture on the site?)
- and lastly, I wanted this code to be flexible in terms of the number of pictures displayed on the page, so I have a 'maximum number' variable which displays, well, a maximum number of pictures. This raised the possibilty of there not being enough Images, so a check is made to display the lesser of the max_num or actual_num of pictures.
CODE
// Hoverbox Image Gallery - adapted
//
// Original Hoverbox code by Nathan Smith
// http://sonspring.com/journal/hoverbox-image-gallery
//
// PHP script adaptation by Jim Haslip jlhaslip@yahoo.ca
//
// A main feature in the original Hoverbox was a method for the thumbnail
// Images to grow to double the thumbnail size when hovered over.
// The Hoverbox swap of Images is entirely CSS-based. No javascript was injured in
// the making of this display.
//
// Added in this script are :
// - an on-click event to display the Images full size
// - added the php scripting to load the contents from a directory
// - added a max number of images to be displayed
// - added a random feature for selecting the Images to be displayed
//
// There could be several versions adapted from this script. ie: remove the full size
// on-click feature, change the maximum number to display, remove the randomness.
// I will eventually have each of these versions available, but at present,
// you will have to Mod the script yourself.
//
//
//
<?php
echo '<ul class="hoverbox">';
//
// set some variables used in the script
//
$max_num = 15; // maximum images displayed in the Hoverbox
$j=0; // a counter variable
$narray = array(); // declare an array containing the file-names of the images
//
// set directory paths here.
// There are Bandwidth issues with loading the 'full-size' pictures for use as thumbs
// and mid-size, however, there is a time-delay issue on-click when the full-size
// picture must then be downloaded. Your call on that one. The Demo uses three Folders.
// To minimize the bandwidth usage, use only one directory of optimized pictures,
// but be sure to alter the paths accordingly.
// All occurences of a picture MUST have the SAME NAME whether in one or three directories.
// The filenames don't appear to be case-sensitive. ( PIC001 = pic001 = PiC001 = pIc001 )
//
$dir = "images/"; // name of the folder where the Thumbnail images are stored
$mid_dir = "mid_images/"; // name of the folder where the Mid-sized images are stored
$full_dir = "full_images/"; // name of the folder where the Full-sized images are stored
//
// check to confirm the directories exist and can be opened
//
if (is_dir($dir) && (is_dir($mid_dir)) && (is_dir($full_dir)) ) {
$dh= @opendir($dir) or die("Unable to open $path please notify the administrator. Thank you.");
//
// loop while you read the entire directory listing selecting only files which
// 1. are not the (.) or (..) directories
// 2. are jpeg ( or as specified in the file type below )
// 3. exist in both the mid-size and full-size directories named in the path variables
//
while (($file = readdir($dh)) !== false) {
//
// ignore the directory entries and only select the .jpg file extension files
// alter the '.jpg' to suit your format
//
if (($file != '.') && ($file != '..') && (stristr($file,'.jpg'))) {
//
// confirm the file exists in both the mid and full directories
//
if ((file_exists($mid_dir . $file)) && (file_exists($full_dir . $file))) {
//
// add them to an array if all is good so far
//
$narray[]=$file;
//
// increase counter when a file is added to the array
//
$n++;
}
}
}
//
// reset the max_num if not enough pictures meet the criteria
//
if ($n < $max_num) {
$max_num = $n;
}
//
// randomize the array for presentation
//
shuffle( $narray);
//
// echo the correct html as per the Hoverbox Tutorial found at
// http://www.sonspring.com
//
while ( $j <= $max_num-1) {
echo "\t" . '<li><a href="' . $full_dir . $narray[$j] . '" alt="full-size">
<img src="' . $dir . $narray[$j] . '" alt="' . $dir . $narray[$j] . '" >
<img src="' . $mid_dir . $narray[$j] . '" alt="mid-size" class="preview" /></a></li> ' . "\n\r\t";
$j++;
}
}
//
// report an error on the directory confirmation
//
else {
echo 'There is a problem with the directories. Please Notify the Administrator. Thank You.';}
closedir($dh);
echo '</ul>';
?>
View a Sample Page Here.
It may have been something to do with the editting and transfer of the text to/from a mac machine and then to the Linux server, although I have done it that way before, so go figure?
Enjoy.
Either I don't understand the problem you are having, or I can't duplicate it.
I have checked this script with three browsers and two versions of php and it all works well for me.
Only thing that I can't check is the function in Internet Explorer 7 because I do not have that Browser installed. What browser are you using? Please post it here or pm me and I will see what can be done. Thanks.
Sprnknwn and Flakes,
Thanks for your comments and good luck with it.
Thanks Jhaslip.
Here's a screenshot of the problem I encounter, the hover doesnt really stand out from other pictures, and get cover by the thumbnail of others...
http://img.photobucket.com/albums/v507/hyp...er/hoverpic.jpg
although i think IE7 is still in its beta stages so it might be fixed when the final comes out (although knowing past IE's it might not be)
I will definately look into this problem. It is probably something to do with an IE6 hack and IE7 that doesn't need the hack. Usually, this can be solved by using a conditional statement for IE and different CSS file for those browsers which need it.
Stay tuned for the modifications to come.
*by the way*, does the 'on-click' okay work in IE7?
I dont really know what's the main problem with this script that allows IE7.0 to display it incorrectly but could someone explain further which is the main problem causing it so I can post up a bug report and the production team may solve it...
Don't worry about anything. I am sure that IE knows all about the problems with IE's non-standard rendering of CSS. They are in the middle of fixing it, so relax.
The only fix is for me to have some time to research the CSS and I simply do not have the time until probably this weekend.
I promise to get to it and advise you when it is available for testing and you can do the beta test for me.
btw, the actual hoverbox image gallery from the sonspring site did not have a problem with that css thing and it works perfectly with IE7.0...
http://host.sonspring.com/hoverbox/
I built a web page for him using the Hoverbox Gallery php script above.
http://www.taryngillies.com
Any and all comments are appreciated.
Image Gallery Tutorial Using Hoverbox
I started to use Hoverbox for my personal website and came across this problem. When I place a portrait orientated photo in the Hoverbox landscape style template it is all stretched. I have portrait and landscape orientated photographs and I want the previews and thumbnails to be proportionate when viewed. What can I do to fix that?
Any help would be appreciated.
Thanks!
-question by Michael
I found some php image gallery scripts listed on the site.
It is good to know of this site.
Free and open source PHP image gallery scripts. These photo gallery scripts will allow you to showcase or sell your images, artwork or prints online.
Similar Topics:
Turning An Image Into A Cartoon Sty...
Expanding Image Gallery
Can You Suggest A Beginner Php Tuto...
Fancy Lines In Signature Adobe Photoshop 7+ (0)
|
(0) Starting Or Stopping Apache And Mysql Server Via Batch File
|
Loading...
HOME 






