Jump to content

Image Gallery [Help needed]


quelle

Recommended Posts

Lets say ive got a function like this one

function getPictures() {
	global $max_width, $max_height;
	if ( $handle = opendir(".") ) {
		$lightbox = rand();
		echo '<ul id="pictures">';
		while ( ($file = readdir($handle)) !== false ) {
			if ( !is_dir($file) ) {
				$split = explode('.', $file); 
				$ext = $split[count($split) - 1];
				if ( ($type = getPictureType($ext)) == '' ) {
					continue;
				}
				if ( ! is_dir('thumbs') ) {
					mkdir('thumbs');
				}
				if ( ! file_exists('thumbs/'.$file) ) {
					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);
				}
				echo '<li><a href="'.$file.'" rel="lightbox['.$lightbox.']">';
				echo '<img src="thumbs/'.$file.'" alt="" />';
				echo '</a></li>';
			}
		}
		echo '</ul>';
	}
}

What it does is:

It checks for files(images) in a directory, check for file types jpg, png or gif cuz I work on gd library and it supports only these 3 type of images and make thumbnails. My problem is I cant change the directory of images, after I do that I just got error or it doesnt read images at all. I tried

 

$dir = "/galerija/";
if ( $handle = opendir($dir) )

But nothing happens, it just leaves me blank space(as I said above it doesnt read images at all)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.