Jump to content

Resize an image


Go to solution Solved by 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?

Edited by TapeGun007
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

Edited by Ch0cu3r
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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