Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Instructions:
- - Place this script in a directory with images, then navigate to this script with a browser (with a server running, capable of running PHP scripts).
- */
- $imgFiles = Array();
- $dh = opendir('.');
- while($file = readdir($dh)){
- $ext = strtolower(pathinfo($file,PATHINFO_EXTENSION));
- $imgExts = Array('jpg','gif','png');
- if(in_array($ext,$imgExts)){
- $imgFiles[] = $file;
- }
- }
- ?>
- <html>
- <head>
- <title>Easy Slideshow</title>
- <script type="text/javascript" language="Javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
- <script type="text/javascript" language="Javascript">
- // Following speeds are in milliseconds ( 1 second = 1000 miliseconds);
- var aniSpeed = 500;
- var rotationInterval = 4000;
- // No Need to change the following variables
- var winW = 0;
- var winH = 0;
- var numOfImages = 0;
- var origWH = new Array();
- var index = 1;
- var curImg;
- var tInterval;
- function screenDimensions(){
- winW = $(window).width();
- winH = $(window).height();
- }
- function imgSizer(){
- // Image Scalling To Window
- var img = $('#easySlideshow_G12 img:nth-child(' + index + ')');
- var origW = origWH[index-1][0];
- var origH = origWH[index-1][1];
- if(origW > winW || origH > winH){
- var hR = origW / winW;
- var vR = origH / winH;
- var ratio = ((hR > vR)? hR : vR);
- $(img).width(Math.round(origW / ratio));
- $(img).height(Math.round(origH / ratio));
- }else{
- $(img).width(origW);
- $(img).height(origH);
- }
- // Center the image in the window
- $(img).css({left: ((winW - $(img).width())/2), top: ((winH - $(img).height())/2)});
- }
- function slideshow(){
- tInterval = clearInterval(tInterval);
- if(curImg != undefined && curImg != null){
- $(curImg).fadeOut(aniSpeed);
- }
- $('#easySlideshow_G12 img:nth-child(' + index + ')').fadeIn(aniSpeed+1, function(){
- curImg = this;
- tInterval = setInterval(slideshow, rotationInterval);
- });
- imgSizer();
- index = ((index == (numOfImages))? 1 : index+1);
- }
- $(function(){
- screenDimensions();
- numOfImages = $('#easySlideshow_G12 img').length;
- $('#easySlideshow_G12 img').each(function(){
- origWH.push(new Array($(this).width(), $(this).height()));
- $(this).css({position: 'absolute', left: 0, top: 0, display: 'none', cursor: 'pointer'});
- }).click(function(){
- window.open($(this).attr('src'));
- });
- $('#easySlideshow_G12 img:last').load(function(){
- slideshow();
- });
- $(window).resize(screenDimensions);
- });
- </script>
- </head>
- <body>
- <div id="easySlideshow_G12">
- <?php
- $c = count($imgFiles);
- for($i=0;$i<$c;++$i){
- $imgInfo = getimagesize($imgFiles[$i]);
- echo '<img src="' . $imgFiles[$i] . '" ' . $imgInfo[3] . ' />' . PHP_EOL;
- }
- ?>
- </div>
- </body>
- </head>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement