• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Rotating images in PHP.

xoggoth

More fingers than teeth
Joined
Jul 8, 2005
Messages
17,132
Likes received
4,950
Thanks received
1,184
Location
xoggoth towers
I made a web page for an artist friend so she could upload photos of her pictures and add her own titles and descriptions. The problem is that when she uploads from her phone the images are the wrong way round. Found methods on Google and I was hoping to make it easy for her by rotating 90' every time she clicked an image. Simple test code below.

The problem with it is that rotate only works once on any given image, call the code a second time and nowt happens. Even changing rotation degrees makes no difference. Any ideas? Cheers.

PHP stuff:

$filename = getcwd()."/20200526_100502.jpg";
rotate($filename);
function rotate($filename)
{
$imageResource = imagecreatefromjpeg($filename);
$image = imagerotate($imageResource,-180,0);
imagejpeg($image, $filename);
imagedestroy($imageResource);
imagedestroy($image);
}

html stuff.....

<img class='img' src='20200526_100502.jpg'>
 
Last edited: 20:12
PS Some code has:

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

That makes the screen go black!

PPS Also tried the exif thing. Her images don't seem to have any exif property.
 
Last edited: 20:34

Advertisers

Back
Top