Guest User

Untitled

a guest
May 22nd, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. <?php
  2. # SETTINGS
  3. $max_width = 100;
  4. $max_height = 100;
  5. $per_page = 24;
  6.  
  7. $page = $_GET['page'];
  8.  
  9. $has_previous = false;
  10. $has_next = false;
  11.  
  12. function getPictures() {
  13. global $page, $per_page, $has_previous, $has_next;
  14. if ( $handle = opendir(".") ) {
  15. $lightbox = rand();
  16. echo '<ul id="pictures">';
  17.  
  18. $count = 0;
  19. $skip = $page * $per_page;
  20.  
  21. if ( $skip != 0 )
  22. $has_previous = true;
  23.  
  24. while ( $count < $skip && ($file = readdir($handle)) !== false ) {
  25. if ( !is_dir($file) && ($type = getPictureType($file)) != '' )
  26. $count++;
  27. }
  28. $count = 0;
  29. while ( $count < $per_page && ($file = readdir($handle)) !== false ) {
  30. if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
  31. if ( ! is_dir('thumbs') ) {
  32. mkdir('thumbs');
  33. }
  34. if ( ! file_exists('thumbs/'.$file) ) {
  35. makeThumb( $file, $type );
  36. }
  37. echo '<li><a href="'.$file.'" class="zoom" rel="group">';
  38. echo '<img src="thumbs/'.$file.'" alt="" />';
  39. echo '</a></li>';
  40. $count++;
  41. }
  42. }
  43. echo '</ul>';
  44.  
  45. while ( ($file = readdir($handle)) !== false ) {
  46. if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
  47. $has_next = true;
  48. break;
  49. }
  50. }
  51. }
  52. }
  53.  
  54. function getPictureType($file) {
  55. $split = explode('.', $file);
  56. $ext = $split[count($split) - 1];
  57. if ( preg_match('/jpg|jpeg/i', $ext) ) {
  58. return 'jpg';
  59. } else if ( preg_match('/png/i', $ext) ) {
  60. return 'png';
  61. } else if ( preg_match('/gif/i', $ext) ) {
  62. return 'gif';
  63. } else {
  64. return '';
  65. }
  66. }
  67.  
  68. function makeThumb( $file, $type ) {
  69. global $max_width, $max_height;
  70. if ( $type == 'jpg' ) {
  71. $src = imagecreatefromjpeg($file);
  72. } else if ( $type == 'png' ) {
  73. $src = imagecreatefrompng($file);
  74. } else if ( $type == 'gif' ) {
  75. $src = imagecreatefromgif($file);
  76. }
  77. if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
  78. $newW = $oldW * ($max_width / $oldH);
  79. $newH = $max_height;
  80. } else {
  81. $newW = $max_width;
  82. $newH = $oldH * ($max_height / $oldW);
  83. }
  84. $new = imagecreatetruecolor($newW, $newH);
  85. imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
  86. if ( $type == 'jpg' ) {
  87. imagejpeg($new, 'thumbs/'.$file);
  88. } else if ( $type == 'png' ) {
  89. imagepng($new, 'thumbs/'.$file);
  90. } else if ( $type == 'gif' ) {
  91. imagegif($new, 'thumbs/'.$file);
  92. }
  93. imagedestroy($new);
  94. imagedestroy($src);
  95. }
  96. ?>
  97.  
  98. function getPictures() {
  99. global $page, $per_page, $has_previous, $has_next;
  100.  
  101. if (!is_dir('thumbs')) {
  102. mkdir('thumbs');
  103. }
  104.  
  105. if ($handle = opendir(".")) {
  106. $lightbox = rand();
  107.  
  108. $files = array();
  109.  
  110. while (($file = readdir($handle)) !== false) {
  111. if (!is_dir($file) && ($type = getPictureType($file)) != '') {
  112. $files[] = $file;
  113. }
  114. }
  115.  
  116. natsort($files);
  117.  
  118. $has_previous = $skip != 0;
  119. $has_next = (count($files) - $skip - $per_page) > 0;
  120.  
  121. $spliceLength = min($per_page, count($files) - $skip);
  122. $files = array_slice($files, $skip, $spliceLength);
  123.  
  124. echo '<ul id="pictures">';
  125.  
  126. foreach($files as $file) {
  127. if (!file_exists('thumbs/' . $file)) {
  128. $type = getPictureType($file);
  129. makeThumb($file, $type);
  130. }
  131.  
  132. echo '<li><a href="' . $file . '" class="zoom" rel="group">';
  133.  
  134. echo '<img src="thumbs/' . $file . '" alt="" />';
  135.  
  136. echo '</a></li>';
  137. }
  138.  
  139. echo '</ul>';
  140. }
  141. }
  142.  
  143. $output[$file] = '<li>etc</li>';
  144.  
  145. function natksort($array) {
  146. $keys = array_keys($array);
  147. natsort($keys);
  148.  
  149. $ret = array();
  150. foreach ($keys as $k) {
  151. $ret[$k] = $array[$k];
  152. }
  153.  
  154. return $ret;
  155. }
  156.  
  157. $output = natksort($output);
  158. echo '<ul>';
  159. foreach ($output as $out) {
  160. echo $out;
  161. }
  162. echo '</ul>';
  163.  
  164. uksort($array, 'strnatcasecmp');
  165.  
  166. uksort($output, "strnatcmp");
Add Comment
Please, Sign In to add comment