sturbitt Posted March 20, 2006 Share Posted March 20, 2006 I am trying to teach myself PHP and I have run through a few tutorial and set myself a project. I am now stuck.I am trying to get PHP to generate thumnails for all my pictures, which are all in directories, and displaythem onto an HTML web page. I am running into a lot of issues with headers. I am sure this must be a fairly simple thing to do. All my pictures are jpgs and are in the directory the PHP is running in. Most of my tries have been cut and pasted examples. Any ideas or points in the right direction would be much Apprenticed. Here is one of my attempts:<?php ob_start(); ?><html><body><br>Start of HTML.<br><?php// Content typeheader('Content-type: image/jpeg');//echo "<br>$image<br>";//$filename = $image;$filename = "test.jpg";$percent = 0.5;// Get new sizeslist($width, $height) = getimagesize($filename);$newwidth = 150;$newheight = 150;// Load$thumb = imagecreatetruecolor($newwidth, $newheight);$filename = imagecreatefromjpeg($filename);// Resizeimagecopyresized($thumb, $filename, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);// Outputimagejpeg($thumb);//return $thumb;ob_end_flush();?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 20, 2006 Share Posted March 20, 2006 You can remove the lines before the "<?php" opening tag. This routine is not sending HTML code, but a binary image. Also, remove the "<?php ob_start(); ?>" and "ob_end_flush();".A comment on your code:You specify a "$percent = 0.5;", but then you have fixed the new height and width at 150px. This is going to make you thumbnail images look distorted. You should use:[code]<?php$percent = 0.5;// Get new sizeslist($width, $height) = getimagesize($filename);$newwidth = $width * $percent;$newheight = $height * $percent;?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
sturbitt Posted March 20, 2006 Author Share Posted March 20, 2006 Thanks for the tips - my coding needs a lot of work as yet.Howerver I still get a lot of gobbledy-gook out and / or header information warnings:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\tutorial\picture\index.php:2) in c:\program files\easyphp1-8\www\tutorial\picture\index.php on line 5ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC 2!!22222222222222222222222222222222222222222222222222ÿÀ––"ÿÄ ÿĵ}!1.........[/quote]Any ideas? I am tearing my hair out - and I didn't have much to start with! ;-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.