jaymc Posted September 18, 2006 Share Posted September 18, 2006 Ok, Im just making a script that will make resized thumbnails to save on bandwidth..Ive mastered the image creation, however, I need the image displayed with some HTML theirfor I cant use the 'setting headers' approach[code]<?// File and new size$filename = 'JMC.jpg';// Content type header('Content-type: image/jpeg');// Get new sizes// list($width, $height) = getimagesize($filename);$newwidth = 76;$newheight = 62;// Load$thumb = imagecreatetruecolor($newwidth, $newheight);$source = imagecreatefromjpeg($filename);// Resizeimagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);// Outputimagejpeg($thumb, null, 100);?> [/code] I basically need to do something like this[b]<img src="$thumb">[/b]But obviously it doesnt work like that. Any help?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/21207-image-stuff/ Share on other sites More sharing options...
brendandonhue Posted September 18, 2006 Share Posted September 18, 2006 You can send the Content-type header to tell the browser its a jpg. If that's in image.php, you could then do <img src="image.php"> in your HTML file. Quote Link to comment https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94275 Share on other sites More sharing options...
jaymc Posted September 18, 2006 Author Share Posted September 18, 2006 How would that work?See the ECHO at the bottom. It doesnt work...[code]<?// File and new size$filename = 'JMC.jpg';//$percent = 0.5;// Content type header('Content-type: image/jpeg');// Get new sizes//list($width, $height) = getimagesize($filename);$newwidth = 76;$newheight = 62;// Load$thumb = imagecreatetruecolor($newwidth, $newheight);$source = imagecreatefromjpeg($filename);// Resizeimagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);// Outputimagejpeg($thumb, null, 100);echo "<img src=image.php>";?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94281 Share on other sites More sharing options...
jaymc Posted September 18, 2006 Author Share Posted September 18, 2006 Sorry, I see what you mean, just didnt want to have it as 2 different pagesBut yeh, its working fine :)Thanks Quote Link to comment https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94283 Share on other sites More sharing options...
jaymc Posted September 18, 2006 Author Share Posted September 18, 2006 Ok Ive got a new problemThe script works fine, but, if the file is a gif it doesnt workNote, when I say gif, its actually named file.jpg but the image is still a gifAny way around it? Quote Link to comment https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94299 Share on other sites More sharing options...
AndyB Posted September 19, 2006 Share Posted September 19, 2006 Do you mean some clown had an image called bozo.gif and renamed it real_bozo.jpg?http://ca.php.net/manual/en/function.getimagesize.php returns an array. The second index is the real file type regardless of the file extension.[code]$x = getimagesize($img);if ($x[2]!=2) { echo "Hey, that's not a jpg file"; exit();}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94322 Share on other sites More sharing options...
jaymc Posted September 19, 2006 Author Share Posted September 19, 2006 Yeh thats what I mean..Images dont really need extensions. If you rename bozo.gif to bozo.jpg the image will still workI just dont get why it doesnt work with the php image stuffIn my script when someone uploads an image it automatically gets renamed image.jpg regardless of the real file typeAny way around it? Quote Link to comment https://forums.phpfreaks.com/topic/21207-image-stuff/#findComment-94654 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.