Php Image Display Script

I can't get the to work. It fails on line 19. "$old_x = imagesx($im);" :confused:

Call to undefined function: imagesx() in C:\nuke\html\foto3.php on line 19.

Do I need some require's before I can run this?
 
Last edited:
I'm thinking its more to do with not getting a filename into it.

To simplify it for testing, I've removed the function like this and just populated the variables.

Code:
<?php
	
	$if = './1.jpg';
	$of = null;
	$quality = 65;
	$new_w = 200;
	$new_h = 200;
			
		
	if(eregi('(jpg|jpeg)$', $if)) {
		$type = 'jpg';
		$im = imagecreatefromjpeg($if);
	}
	elseif(eregi('png$', $if)){
		$type = 'png';
		$im = imagecreatefrompng($if);
	}
	elseif(eregi('gif$', $if)){
		$type = 'gif';
		$im = imagecreatefromgif($if);
	}
	
	$old_x = imagesx($im);
	$old_y = imagesy($im);
	
	if($old_x > $new_w || $old_y > $new_h) {
		
		if ($old_x > $old_y) {
			$thumb_w = $new_w;
			$thumb_h = $old_y * ($new_h / $old_x);
		}
		if ($old_x < $old_y) {
			$thumb_w = $old_x * ($new_w / $old_y);
			$thumb_h = $new_h;
		}
		if ($old_x == $old_y) {
			$thumb_w = $new_w;
			$thumb_h = $new_h;
		}
		
		$dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
		imagecopyresampled($dst_img, $im, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
		
		$im = $dst_img;
		
	}
	
	if($of && !is_writable(dirname($of))) {
		die('Whoops - your album directory is not writable. Please fix this, or I won\'t be able to generate any thumbnails!');
	}
	
	if($type == 'jpg'){
		imagejpeg($im, $of, $quality); 
	} 
	elseif($type == 'png') {
		imagepng($im, $of); 
	}
	else {
		imagegif($im, $of);
	}
	
	@imagedestroy($dst_img); 
	@imagedestroy($im);
	

?>

I'm guessing, does your code actually create a smaller image. The code I've used just resize's it. I'd much rather persevere with the code you've posted if it actually shrinks the image server side.
 
Last edited:
Back
Top Bottom