Search code examples
phpimageimage-rotation

php rotate and save image - not doing anything?


I'm trying to use the following code to rotate and save an image, but it doesn't appear to be doing anything, nor is it spitting out any errors?

Here's my code:

header('Content-type: image/jpeg');

$path   = '/Volumes/yoda/websites/zepel.website.2013/images/blog/display';
$file   = '10.jpg';
$degrees    = 90;

$filename   = $path."/".$file;

$source     = imagecreatefromjpeg($filename) or notfound();
$rotate     = imagerotate($source,$degrees,0);

imagejpeg($filename,$rotate);

imagedestroy($source);
imagedestroy($rotate);

Any help would be greatly appreciated. My images folder is set to 777 too. I can't seem to figure out why it's not working?


Solution

  • Give this a whirl: (tested)

    <?php
    
    $path   = '/Volumes/yoda/websites/zepel.website.2013/images/blog/display';
    $file   = '10.jpg';
    $degrees = 90;
    
    header('Content-type: image/jpeg');
    
    $filename = $path . "/" .$file;
    
    $source = imagecreatefromjpeg($filename) or notfound();
    $rotate = imagerotate($source,$degrees,0);
    
    imagejpeg($rotate);
    imagedestroy($source);
    imagedestroy($rotate);
    
    ?>