Jump to content

some major image display issues


Recommended Posts

Alrighty...here's the problem.  I have images on a server and stored in a database and i'd like to display them as thumbnails in the browser.  Every other time I've done this, I've saved thumbnail versions on the server.  I find this a waste of space and would like to figure out how to display them dynamically without having to save  individual versions.  I get to the point of using imagejpeg() to output it to the browser but the browser can not decode what's going on.  From my understanding i'm supposed to use "header("content-type: image/jpeg");" but i'm unclear as to where to put this because when i put it at the beginning before any output like it's supposed to be,  all that displays is the url of the current page on a blank white page.

 

any help?

 

currently i have an index file which includes show.php.  i have the header statement at the very beginning of the index.php

 

this is the display code from show.php

//make thumbnail of larger image
		list($width, $height, $type, $attr) = getimagesize($imagelink);

		//determine orientation of image
		if ($width >= $height) {
			$orientation = 0;
		}
		else {
			$orientation = 1;
		}

		$orig = imagecreatefromjpeg($imagelink);		

		// Set a maximum height and width
		if ($orientation == 0) {
			$thumbheight = 72;
			$thumbwidth  = 108;
		} else {
			$thumbheight = 97;
			$thumbwidth  = 82;
		}

		//create memory for thumbnail
		$thumb = imagecreatetruecolor($thumbwidth,$thumbheight);
		$fg = imagecolorallocate($thumb,255,255,255);
		imagefilledrectangle($thumb,0,0,100,75,$fg);


		//copy large image to thumbnail
		imagecopyresampled($thumb,$orig,0,0,0,0,$thumbwidth,$thumbheight,$width,$height);

		//write thumb to browser
		imagejpeg($thumb);

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.