Saving an image file after imagerotate function...

I copied the imagerotate function straight off the manual:

// File and rotation
$filename = ‘test.jpg’;
$degrees = 180;

// Content type
header(‘Content-type: image/jpeg’);

// Load
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

// Output
But I find if it is not the first thing sent to the browser the return is machine code characters. So I tried to save $rotate to a new file name, which I prefer,( since once rotated by the client they should stay rotated) but I can’t save it as a file either. I guess you need to send the header tag, but how do you do that in the middle of the page? I would prefer to write the rotated image to a new file or overwrite the old one.
Any ideas??

I think there is some misunderstanding… this script produces an image (binary file). If you want to display it in the middle of some page, you need to include it using HTML tag. So, for example, if the script you posted above is saved in the file named rotated.php, and you have a page named index.php, you can use this HTML code in the index.php:

<?php echo 'Rotated image: <img src="rotated.php" />'; ?>

Sponsor our Newsletter | Privacy Policy | Terms of Service