Jump to content

Rotating picture on server


Bogey

Recommended Posts

Hi all,

 

Users can upload their own photoalbums on my website, but I want them to be able to rotate the photo's:

I have this code, the code rotates the photo (in browser is show rotated) but picture itself on server isn't changed, so when viewing picture, it still not rotated... what's wrong with code underneath? How can I save the rotated picture over the existing picture?

<?php$fotoID = stripslashes($_GET['a']);$tableName = stripslashes($_GET['b']); include($_SERVER["DOCUMENT_ROOT"]."/config.php"); //Include de config met username en passwordsmysql_connect("localhost",$GLOBALS["dbuser"],$GLOBALS["dbpass"]) or die(mysql_error());mysql_select_db($GLOBALS["dbname"]); $resultFotos = mysql_query("SELECT * FROM " . $tableName . " WHERE id='$fotoID'");$rowFotos = mysql_fetch_array($resultFotos);$bestandsnaam = $rowFotos['bestandsnaam'];$albumID = $rowFotos['album_id']; // File and rotation$fotoFile = $_SERVER["DOCUMENT_ROOT"]. "/images/fotoalbums/id" . $albumID . "/" . $bestandsnaam . ".jpg";$thumbsFile = $_SERVER["DOCUMENT_ROOT"]. "/images/fotoalbums/id" . $albumID . "/thumbs/" . $bestandsnaam . "_thumb.jpg";$degrees = 90; // Content typeheader('Content-type: image/jpeg'); // Load$sourceFoto = imagecreatefromjpeg($fotoFile) or die('Error opening file '.$fotoFile);$sourceThumb = imagecreatefromjpeg($thumbsFile)or die('Error opening file '.$thumbsFile); // Rotate$rotateFoto = imagerotate($sourceFoto, $degrees, 0);$rotateThumb = imagerotate($sourceThumb, $degrees, 0); // Outputimagejpeg($rotateFoto);imagejpeg($rotateThumb); // Free the memoryimagedestroy($sourceFoto);imagedestroy($sourceThumb);imagedestroy($rotateFoto);imagedestroy($rotateThumb);?>
Edited by Bogey
Link to comment
Share on other sites

Calling imagejpeg() twice is going to output a corrupted image. You have two separate images there, what did you want the result to look like?

Link to comment
Share on other sites

I have pictures on server and thumbs for example:

imagespicture1.jpg

imagespicture2.jpg

imagespicture3.jpg

imagesthumbspicture1_thumb.jpg

imagesthumbspicture2_thumb.jpg

imagesthumbspicture3_thumb.jpg

 

I could happen, that a picture is wrong, for example up side down.

Then I would like that user is able to rotate picture 2 times 90degrees, so picture shows how supposed.

When rotate picture by user, then the rotated picture needs to be save over the source picture, so I don't want a copy, just the new (rotated) picture repace the old one.

Link to comment
Share on other sites

imagejpeg() will just output the image data straight to the browser unless you pass it parameters.

 

If you want to save the result in a file then add the file name in the second parameter.

$destination = 'file.jpg';imagejpeg($rotateFoto, $destination);

You should remove the content type header() line if you want to see text output from your PHP script.

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...