Jump to content

Resize an image


TapeGun007

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.