Giter Club home page Giter Club logo

Comments (3)

jojomartius avatar jojomartius commented on August 25, 2024 1

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

from image-resizer-service.

ulgens avatar ulgens commented on August 25, 2024

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.

from image-resizer-service.

jojomartius avatar jojomartius commented on August 25, 2024

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);
    }`

from image-resizer-service.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.