TapeGun007 Posted October 8, 2013 Share Posted October 8, 2013 echo "<img src='test/zimages.jpg'>"; $thumb = ImageCreateTrueColor($finalwidth, $finalheight); $source = @ImageCreateFromJpeg('test/zimages.jpg'); ImageCopyResized($thumb, $source, 0, 0, 0, 0, $finalwidth, $finalheight, $width, $height); @ImageJpeg($thumb); Quote Link to comment Share on other sites More sharing options...
TapeGun007 Posted October 8, 2013 Author Share Posted October 8, 2013 (edited) I've read 100 posts on how to resize an image, and when I run this, it just spits out a bunch of garbage text (which when I pasted that in the original post, it deleted most of what I typed). I checked all the variables, and they are outputting the correct numbers. What am I doing wrong here? Edited October 8, 2013 by TapeGun007 Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 8, 2013 Share Posted October 8, 2013 (edited) The following line @ImageJpeg($thumb); will return the raw binary data for the resized image. You cannot mix raw image data with html. What you need to do is save this php code in a seperate file, say call this zimages.php and make it server the correct content type for jpg images <?hpp header('Content-type: image/jpeg'); // <-- added header content type $thumb = ImageCreateTrueColor($finalwidth, $finalheight); $source = @ImageCreateFromJpeg('test/zimages.jpg'); ImageCopyResized($thumb, $source, 0, 0, 0, 0, $finalwidth, $finalheight, $width, $height); @ImageJpeg($thumb); ?> Then in your html you'll call this script using echo "<img src='zimages.php'>"; Which should display the resized image of test/zimages.jpg Edited October 8, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Barand Posted October 8, 2013 Share Posted October 8, 2013 Don't forget to call image_destroy($thumb); image_destroy($source); after @ImageJpeg($thumb) to release the memory. Quote Link to comment Share on other sites More sharing options...
TapeGun007 Posted October 8, 2013 Author Share Posted October 8, 2013 Thank you gentlemen for the great input. However, I noticed something rather weird as it still fails to work. <?php header('Content-type: image/jpeg'); ?> test These are my first four lines of code, and I remarked everything else out. When I run this, I get a small broken image in the top left corner... and the word "test" never prints to the screen. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 8, 2013 Share Posted October 8, 2013 Not surprising - that is hardly a valid piece of image creation code. There is no imagecreate() and no imagejpeg() Quote Link to comment Share on other sites More sharing options...
Solution TapeGun007 Posted October 8, 2013 Author Solution Share Posted October 8, 2013 Ok, thanks... I will go look those up. I don't mind reading and research, just need a point in the right direction. 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.