Advertisement
gitlez

Untitled

Jun 2nd, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4. Instructions:
  5. - 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).
  6.  
  7. */
  8. $imgFiles = Array();
  9. $dh = opendir('.');
  10. while($file = readdir($dh)){
  11. $ext = strtolower(pathinfo($file,PATHINFO_EXTENSION));
  12. $imgExts = Array('jpg','gif','png');
  13. if(in_array($ext,$imgExts)){
  14. $imgFiles[] = $file;
  15. }
  16. }
  17.  
  18. ?>
  19. <html>
  20. <head>
  21. <title>Easy Slideshow</title>
  22. <script type="text/javascript" language="Javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
  23. <script type="text/javascript" language="Javascript">
  24.  
  25. // Following speeds are in milliseconds ( 1 second = 1000 miliseconds);
  26. var aniSpeed = 500;
  27. var rotationInterval = 4000;
  28.  
  29. // No Need to change the following variables
  30. var winW = 0;
  31. var winH = 0;
  32. var numOfImages = 0;
  33. var origWH = new Array();
  34. var index = 1;
  35. var curImg;
  36. var tInterval;
  37.  
  38.  
  39. function screenDimensions(){
  40. winW = $(window).width();
  41. winH = $(window).height();
  42. }
  43. function imgSizer(){
  44. // Image Scalling To Window
  45. var img = $('#easySlideshow_G12 img:nth-child(' + index + ')');
  46. var origW = origWH[index-1][0];
  47. var origH = origWH[index-1][1];
  48. if(origW > winW || origH > winH){
  49. var hR = origW / winW;
  50. var vR = origH / winH;
  51. var ratio = ((hR > vR)? hR : vR);
  52. $(img).width(Math.round(origW / ratio));
  53. $(img).height(Math.round(origH / ratio));
  54. }else{
  55. $(img).width(origW);
  56. $(img).height(origH);
  57. }
  58. // Center the image in the window
  59. $(img).css({left: ((winW - $(img).width())/2), top: ((winH - $(img).height())/2)});
  60. }
  61. function slideshow(){
  62. tInterval = clearInterval(tInterval);
  63. if(curImg != undefined && curImg != null){
  64. $(curImg).fadeOut(aniSpeed);
  65. }
  66. $('#easySlideshow_G12 img:nth-child(' + index + ')').fadeIn(aniSpeed+1, function(){
  67. curImg = this;
  68. tInterval = setInterval(slideshow, rotationInterval);
  69. });
  70. imgSizer();
  71. index = ((index == (numOfImages))? 1 : index+1);
  72. }
  73. $(function(){
  74. screenDimensions();
  75. numOfImages = $('#easySlideshow_G12 img').length;
  76. $('#easySlideshow_G12 img').each(function(){
  77. origWH.push(new Array($(this).width(), $(this).height()));
  78. $(this).css({position: 'absolute', left: 0, top: 0, display: 'none', cursor: 'pointer'});
  79. }).click(function(){
  80. window.open($(this).attr('src'));
  81. });
  82. $('#easySlideshow_G12 img:last').load(function(){
  83. slideshow();
  84. });
  85. $(window).resize(screenDimensions);
  86. });
  87. </script>
  88. </head>
  89. <body>
  90. <div id="easySlideshow_G12">
  91. <?php
  92. $c = count($imgFiles);
  93. for($i=0;$i<$c;++$i){
  94. $imgInfo = getimagesize($imgFiles[$i]);
  95. echo '<img src="' . $imgFiles[$i] . '" ' . $imgInfo[3] . ' />' . PHP_EOL;
  96. }
  97. ?>
  98. </div>
  99. </body>
  100. </head>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement