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); Link to comment https://forums.phpfreaks.com/topic/282812-resize-an-image/ Share on other sites More sharing options...
TapeGun007 Posted October 8, 2013 Author Share Posted October 8, 2013 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? Link to comment https://forums.phpfreaks.com/topic/282812-resize-an-image/#findComment-1453087 Share on other sites More sharing options...
Ch0cu3r Posted October 8, 2013 Share Posted October 8, 2013 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 Link to comment https://forums.phpfreaks.com/topic/282812-resize-an-image/#findComment-1453108 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. Link to comment https://forums.phpfreaks.com/topic/282812-resize-an-image/#findComment-1453111 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. Link to comment https://forums.phpfreaks.com/topic/282812-resize-an-image/#findComment-1453133 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() Link to comment https://forums.phpfreaks.com/topic/282812-resize-an-image/#findComment-1453134 Share on other sites More sharing options...
TapeGun007 Posted October 8, 2013 Author 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. Link to comment https://forums.phpfreaks.com/topic/282812-resize-an-image/#findComment-1453136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.