Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Image Rotation by image magic

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 500
    Comment on it

    Creating image rotation using Image magic by command line.

    Some time image taken from iphone when uploaded on the website gets rotated .We can easily find that the image is rotated and can rotate is back by using the following code.

    $rotableImage = array('jpg', 'jpeg', 'JPEG', 'JPG');
            if(in_array($fileParts['extension'], $rotableImage)){
                $exif = @exif_read_data($tempFile, 0, true);
                if(@$exif['IFD0']['Orientation']!='')
                {
                    switch ($exif['IFD0']['Orientation'])
                    {
                            case 3:
                            $cmd="convert $tempFile  -rotate 180  $tempFile";
                            exec($cmd);
                            break;
                            case 8:
                            $cmd="convert $tempFile  -rotate 90  $tempFile";
                            exec($cmd);
                            break;
                            case 6:
                            $cmd="convert $tempFile  -rotate 90  $tempFile";
                            exec($cmd);
                            break;
                    }
                } 
            } 
    

    If you see closely it is only for JPEG or JPG. We can use this code for only for JPEG and TIFF images as they only have header in which "Orientation" is available which tell us the image is rotated and for rest of the image type "exif_read_data" will return error .

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: