I'm trying to build a crude album viewing site. There are three files I'm working with:

  • index.php: Contains html code.
  • images.php: Builds images from browser URL and an array.
  • include: Builds an array of images from a given directory.

Given:
image.php

<?php
	include('include.php');
	buildImageArray("images/");
	
	$image = $_GET['show_img'];
	$tmp_img = $my_pics[$image];

	//@imagecopyresized( $tmp_img, $img, 0, 0, 100, 100, $new_width+100, $new_height+100, $width, $height );
	header('Content-Type: image/jpeg');

	@imagejpeg( $tmp_img );	
?>

All I get for output is the address I put in to begin with. I have gotten this type of setup to work before, just not with the way I want to include the array setup.

<?php
$large[4];
$medium[8];
$small[88];
$image_container[100];
function buildImageArray($pathToImages)
{
	$dir = opendir( $pathToImages );
	$counter = 0;
	
	while (false !== ($fname = readdir( $dir ))) {
		$info = pathinfo($pathToImages . $fname);
		if ( strtolower($info['extension']) == 'jpg' )
		{		
			$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
			$width = imagesx( $img );
			$height = imagesy( $img );
			
			$tmp_img = imagecreatetruecolor( $width, $height );
			
			$image_container[$counter] = $tmp_img;
			$counter++;
		}
	}
	closedir( $dir );
}

/*function fillImageArrays($container)
{
	// fill large ones
	for($i=0;i<sizeof($large);i++)
}*/
?>

My index.php file has something simple like:

<img src="images.php?show_img=3" />

However, sometimes when I load the page I get nothing, but other times I refresh the page quickly and can see a broken image.

I have all of the error reporting turned on, but I'm not getting any errors at all.

I have had some very basic PHP experience in the past, but I code very well in C++. Can anyone point me in the write direction, or point out a syntax error I am overlooking?

@imagejpeg( $tmp_img );

Line 11 in the above quote is incorrect. You first need to get the image then use a separate function to display the image. To make it simple, I have combined them into one line so try replacing line 11 in the above quote with the following

imagejpeg(imagecreatefromjpeg($tmp_img));

Also you may want to check the following link for more info:
http://au.php.net/manual/en/function.imagecreatefromjpeg.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.