ImageMagick to rotate an image

Discussion in 'Perl Misc' started by Jason C, Nov 14, 2013.

  1. Jason C

    Jason C Guest

    I understand that I can use convert() in ImageMagick to rotate an uploaded picture. The question, though, is how to automatically determine when the picture NEEDS to be rotated?

    I know that I can set up a button for the user to manually click if they want to rotate the picture, but is there a way to do it without asking? I've seen it done on bigger sites, but I don't know if it's a simple command that already exists, or if it's a big system that they've bought.
     
    Jason C, Nov 14, 2013
    #1
    1. Advertising

  2. On 2013-11-14 03:49, Ben Morrow <> wrote:
    > Quoth Jason C <>:
    >> I understand that I can use convert() in ImageMagick to rotate an
    >> uploaded picture. The question, though, is how to automatically
    >> determine when the picture NEEDS to be rotated?

    [...]
    > I believe this is usually done by reading the EXIF data, assuming the
    > camera put any there. (Why the camera does this rather than simply
    > rotating the picture I don't know.) This is not something I know much
    > about, but Image::ExifTool looks like a... rather complete
    > implementation. Probably you want the 'Orientation' tag;


    Rotation or Orientation, yes. Apparently both are in use.

    Here is what I use:

    use Image::ExifTool qw(ImageInfo);
    ...
    my $info = ImageInfo($filename);
    my $rot = $info->{'Rotation'} || $info->{'Orientation'};
    my ($angle) = $rot =~ m/Rotate (\d+) CW/;
    return $angle;

    hp


    --
    _ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
    |_|_) | | Man feilt solange an seinen Text um, bis
    | | | | die Satzbestandteile des Satzes nicht mehr
    __/ | http://www.hjp.at/ | zusammenpaƟt. -- Ralph Babel
     
    Peter J. Holzer, Nov 14, 2013
    #2
    1. Advertising

  3. Jason C

    Jason C Guest

    On Thursday, November 14, 2013 2:24:44 AM UTC-5, Peter J. Holzer wrote:

    > Rotation or Orientation, yes. Apparently both are in use.
    >
    >
    >
    > Here is what I use:
    >
    >
    >
    > use Image::ExifTool qw(ImageInfo);
    >
    > ...
    >
    > my $info = ImageInfo($filename);
    >
    > my $rot = $info->{'Rotation'} || $info->{'Orientation'};
    >
    > my ($angle) = $rot =~ m/Rotate (\d+) CW/;
    >
    > return $angle;
    >
    >
    >
    > hp


    Thanks, guys (both Peter and Ben). I think this will help a lot.
     
    Jason C, Nov 15, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper

    How to rotate image upon upload?

    Showjumper, Feb 13, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    631
    Showjumper
    Feb 16, 2004
  2. RC
    Replies:
    1
    Views:
    888
    Bjoern Hoehrmann
    Aug 3, 2006
  3. IanJSparks
    Replies:
    0
    Views:
    1,164
    IanJSparks
    Jan 10, 2008
  4. Tim Harig
    Replies:
    4
    Views:
    910
    Michel Claveau - MVP
    Jun 8, 2009
  5. Josef Moellers
    Replies:
    11
    Views:
    357
    zentara
    Nov 5, 2008
Loading...

Share This Page