rotate image before upload using blueimp upload
Asked Answered
H

2

7

I'm using blueimp upload widget to upload images to my file server, which works fine.

The only issue is that, I want to rotate the image correctly before I upload it to server, so when I link to it through a URL it displays in the right orientation.

Any idea on which setting to use?

Hames answered 29/6, 2016 at 9:21 Comment(2)
You need to set Orientation of the image at server side. First you have to get the rotation value from the image using GDI. then you can rotate your image using Image.RotateFlip method to the correct rotation angle.Rees
Can you explain what you want to accomplish with example(step by step).Pina
B
4

Maybe you need another plugin, like https://fengyuanchen.github.io/cropper/

preview image rotate, then crop image

Blayne answered 24/9, 2016 at 8:21 Comment(0)
A
2

This is a backend solution. We dont allow tiff image uploads, so I didnt include the image type check.

$uploadedFile->tempName is the file path eg: "/var/www/site/upload/images/someImage.jpg"

if(exif_imagetype($uploadedFile->tempName) == 2)//2 IMAGETYPE_JPEG
{
$exif = exif_read_data($uploadedFile->tempName);
if(!empty($exif['Orientation']))
{
    $image = imagecreatefromjpeg($uploadedFile->tempName);

    switch($exif['Orientation']) 
            {
    case 8:
        $image = imagerotate($image,90,0);
        break;
    case 3:
        $image = imagerotate($image,180,0);
        break;
    case 6:
        $image = imagerotate($image,-90,0);
        break;
    }
        imagejpeg($image, $uploadedFile->tempName);
}
}
Aymara answered 27/9, 2016 at 6:30 Comment(1)
I'd give you a billion upvotes if i so could. For someone working with a php-API this is so easy to implement. Thank youRegurgitation

© 2022 - 2024 — McMap. All rights reserved.