smith
smith

Reputation: 5461

can't rotate the uploaded image using php

I try to rotate the uploaded image 90 degrees after uploading, I tried imagerotate() method, but it's not working.

Here is my code:

$tmp = $_FILES['photoimg']['tmp_name']; 
$path = "uploads/";  
move_uploaded_file($tmp, $path."newfile.jpg");  
$rotate = imagerotate($path."newfile.jpg", 90, 0);
imagejpeg($rotate);
imagedestroy($source);
imagedestroy($rotate);

Any help will be greately appreciated, thanks!

Upvotes: 0

Views: 249

Answers (1)

bitWorking
bitWorking

Reputation: 12655

imagerotate needs a resource as first parameter not a file path. You should get an error if you'd enable error reporting. error_reporting(E_ALL);

$source = imagecreatefromjpeg($path."newfile.jpg");
$rotate = imagerotate($source, 90, 0);
imagejpeg($rotate);
imagedestroy($source);
imagedestroy($rotate);

Upvotes: 2

Related Questions