Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orientation changes #21

Closed
jojomartius opened this issue Jul 24, 2020 · 3 comments
Closed

Orientation changes #21

jojomartius opened this issue Jul 24, 2020 · 3 comments

Comments

@jojomartius
Copy link

For some reason, some pictures change there orientation as soon as i add a ?width=xxx. Any idea how to prevent this?

@ulgens
Copy link

ulgens commented Jul 24, 2020

In some weird cases, idk why, image metadata gets corrupted. When that happens, different viewers show the image in different orientation and this resize tool can't handle it. Opening the image in sth like PS and re-exporting it or cleaning the metada solves the problem for a specific file.

@jojomartius
Copy link
Author

Ahhhh, now I understand ;-) I'll try to explain...

@jojomartius
Copy link
Author

jojomartius commented Jul 24, 2020

That happens mainly if you upload stuff from an iOS Device...

The iPhone/iPod/iPad wants to be a real camera in landscape. And if you hold your phone like this, it really feels like a camera, it has the lenses in the upper right corner, thats ok. No matter how you do your photo, it will be delivered like you make it. So if you hold it in landscape, this side is on the top, if you hold it in portrait, this side is the top.

And because it was to be a correct device it puts extra information in the meta data how it was hold while making the picture. It is not intended to be corrected by the orientation, it just says "this was my orientation".

And this script (like many others) try to correct the orientation by the metadata, but thats not needed. So the trick is pretty simple. Just throw away all the metadata when you save the image in the backend and you won't have any issues. Then all pictures portrait, landscape, upside down look good and like you made them.

Coming from php, i did it like this:

` if(@is_array(getimagesize($this->path . $newFileName))){
$img = new \Imagick($this->path . $newFileName);
$orientation = $img->getImageOrientation();

        switch($orientation) {
            case \Imagick::ORIENTATION_BOTTOMRIGHT: 
                $img->rotateimage("#000", 180); // rotate 180 degrees
                break;
    
            case \Imagick::ORIENTATION_RIGHTTOP:
                $img->rotateimage("#000", 90); // rotate 90 degrees CW
                break;
    
            case \Imagick::ORIENTATION_LEFTBOTTOM: 
                $img->rotateimage("#000", -90); // rotate 90 degrees CCW
                break;
        }
    
        // Now that it's auto-rotated, make sure the EXIF data is correct in case the EXIF gets saved with the image!
        $img->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
        $img->stripImage();
        $img->writeImage($this->path . $newFileName);
    }`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants