Skip to content

Question: Is it possible to autoOrient Images? #711

Closed

Description

@kabirbaidhya

Hi, I'm wondering if it's possible to autoOrient images with sharp?

For instance with the gm package it's possible to do this but it needs imagemagick. How do we do similar thing with sharp?

// auto-orient an image
gm('/path/to/img.jpg')
.autoOrient()
.write('/path/to/oriented.jpg', function (err) {
  if (err) ...
});

Activity

  1. lovell commented on Feb 13, 2017

    @lovell
    Owner

    Hello, did you see the rotate operation?

  2. kabirbaidhya commented on Feb 15, 2017

    @kabirbaidhya
    Author

    Okay, seems like it's possible with a little tweak. Thanks.

  3. lovell commented on Feb 15, 2017

    @lovell
    Owner

    "with a little tweak"

    Are you able to expand on this comment? Is there something that could be improved?

    Your example, using sharp instead of gm, would look something like:

    // auto-orient an image
    sharp('/path/to/img.jpg')
      .rotate()
      .toFile('/path/to/oriented.jpg', function (err) {
        if (err) ...
      });
  4. kabirbaidhya commented on Feb 15, 2017

    @kabirbaidhya
    Author

    Yes, the above code did work fine as expected.
    Just the difference was gm would overwrite the original file with the auto-oriented result. And sharp would return new result and we had to do toFile to save it to new file.

    So, we just had to do little tweak to fit our needs but that really wasn't a big deal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions