Jump to content

Some help about gallery would be helpful here :)


quelle

Recommended Posts

My gallery is making thumbs fine and listing them aswell. The pagination works fine but i cannot handle with these errors whose show under the thumbs in webiste. Seems like the code in else if statement is missing arguments :S, Let's take a look !

 

Warning: Missing argument 1 for makeThumb(), called in D:\xampp\htdocs\website\galerija\index.php on line 167 and defined in D:\xampp\htdocs\website\galerija\index.php on line 136

Warning: Missing argument 2 for makeThumb(), called in D:\xampp\htdocs\website\galerija\index.php on line 167 and defined in D:\xampp\htdocs\website\galerija\index.php on line 136

Warning: imagesx() expects parameter 1 to be resource, null given in D:\xampp\htdocs\website\galerija\index.php on line 145

Warning: imagesy() expects parameter 1 to be resource, null given in D:\xampp\htdocs\website\galerija\index.php on line 145

Warning: Division by zero in D:\xampp\htdocs\website\galerija\index.php on line 150

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in D:\xampp\htdocs\website\galerija\index.php on line 152

Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\website\galerija\index.php on line 153

Warning: imagedestroy() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\website\galerija\index.php on line 161

Warning: imagedestroy() expects parameter 1 to be resource, null given in D:\xampp\htdocs\website\galerija\index.php on line 162

 

That's the "problem" code which appears under pictures

 

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);
}

And these are my 3 functions i use to do that all i think no more source is needed even those 2 functions aren't needed, the only problem as i see is in makeThumb function

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.