Jump to content

can't understand how to edit it for my website

- - - - -

  • Please log in to reply
1 reply to this topic

#1
waqaspuri

waqaspuri

    Newbie

  • Members
  • Pip
  • 1 posts
Hi,

All genius,

Have uploaded a simple photo gallery but it is sort the thumbs not in series, it grab the information of a image and place it on the website by it's width and height, i would like it to pick and place the image in a series, ex. 1.jpg should be first ... then 2.jpg should be the next one to line up with the other image, it is the completed script just need help in order to set the the way it is being sorted at Welcome to Daily Regional Times Online Newspaper


<?php

	# SETTINGS

	$max_width = 200;

	$max_height = 200;

	$per_page = 10;

	

	$page = $_GET['page'];

	

	$has_previous = false;

	$has_next = false;

	

	function getPictures() {

		global $page, $per_page, $has_previous, $has_next;

		if ( $handle = opendir(".") ) {

			$lightbox = rand();

			echo '<ul id="pictures">';

			

			$count = 0;

			$skip = $page * $per_page;

			

			if ( $skip != 0 )

				$has_previous = true;

			

			while ( $count < $skip && ($file = readdir($handle)) !== false ) {

				if ( !is_dir($file) && ($type = getPictureType($file)) != '' )

					$count++;

			}

			$count = 0;

			while ( $count < $per_page && ($file = readdir($handle)) !== false ) {

				if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {

					if ( ! is_dir('thumbs') ) {

						mkdir('thumbs');

					}

					if ( ! file_exists('thumbs/'.$file) ) {

						makeThumb( $file, $type );

					}

					echo '<li><a href="'.$file.'" rel="lightbox['.$lightbox.']">';

					echo '<img src="thumbs/'.$file.'" alt="" />';

					echo '</a></li>';

					$count++;

				}

			}

			echo '</ul>';

			

			while ( ($file = readdir($handle)) !== false ) {

				if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {

					$has_next = true;

					break;

				}

			}

		}

	}

	

	function getPictureType($file) {

		$split = explode('.', $file); 

		$ext = $split[count($split) - 1];

		if ( preg_match('/jpg|jpeg/i', $ext) ) {

			return 'jpg';

		} else if ( preg_match('/png/i', $ext) ) {

			return 'png';

		} else if ( preg_match('/gif/i', $ext) ) {

			return 'gif';

		} else {

			return '';

		}

	}

	

	function makeThumb( $file, $type ) {

		global $max_width, $max_height;

		if ( $type == 'jpg' ) {

			$src = imagecreatefromjpeg($file);

		} else if ( $type == 'png' ) {

			$src = imagecreatefrompng($file);

		} else if ( $type == 'gif' ) {

			$src = imagecreatefromgif($file);

		}

		if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {

			$newW = $oldW * ($max_width / $oldH);

			$newH = $max_height;

		} else {

			$newW = $max_width;

			$newH = $oldH * ($max_height / $oldW);

		}

		$new = imagecreatetruecolor($newW, $newH);

		imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);

		if ( $type == 'jpg' ) {

			imagejpeg($new, 'thumbs/'.$file);

		} else if ( $type == 'png' ) {

			imagepng($new, 'thumbs/'.$file);

		} else if ( $type == 'gif' ) {

			imagegif($new, 'thumbs/'.$file);

		}

		imagedestroy($new);

		imagedestroy($src);

	}

?>

Edited by Orjan, 04 March 2011 - 08:03 AM.
Use php tags when postinng php


#2
rhossis

rhossis

    Learning Programmer

  • Members
  • PipPipPip
  • 46 posts
Hi, am thinking maybe you can, instead of using readdir() function which will process files in the order in which they were saved you can use the scandir() function to obtain an array of the file names, and then sort the array, then feed it into your image loading scripts.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users