Git Product home page Git Product logo

androidrotateimage's Introduction

Android Image Rotate

There's a annoying, yet somewhat rare issue when taking photos with certain Andorid devices, where the orientation information is not properlly identified by Titanium, causing a photo taken in portrait format to be returned as landscape.

This module, was developed by Justin Toth and shared on Jira with the intention of helping people fix this annoying issue, and help Apccelerator in getting this finally fixed.

The source code is exactly the same as the Jira ticket. I simply compiled it and provided it in binary format, ready to use.

Usage

Besides rotating the image, the library scales the image to the specified width, and compresses it to the specified percentage. This is particulary useful, since Android camera images can be huge and could potentially make your device run out-of-memory.

function rotateAndResize (media, width, quality) {
    var utilsModule = require('com.alcoapps.imageutility');
 
    // Create file to store photo.
    var dataDirectory = Ti.Filesystem.getApplicationDataDirectory();
    var fileName = String.format('Company_Photo_%s.jpg', moment().format('YYYY-MM-DD-HH-mm-ss-SSS-ZZ'));
    var file = Ti.Filesystem.getFile(dataDirectory, fileName);
    var fileNativePath = file.nativePath;
 
    // Write media to file.
    file.write(media);
    file = null;
 
    // Rotate photo in file, resize, and adjust quality.
    utilsModule.rotateResizeImage(fileNativePath, width || 640, quality || 80);
 
    // Get new and improved media out of file.
    media = Ti.Filesystem.getFile(fileNativePath);
 
    return media;
}

License

I didn't write this code, and there was no license specified, so I'm releasing it as MIT, pending feedback from the author.

androidrotateimage's People

Contributors

ricardoalcocer avatar skypanther avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

androidrotateimage's Issues

SDK 7.0GA Support

Would you have time to update this module for the latest 7.0GA SDK support?

Does not work with Ti 6.0.0.GA

Hi,

I am trying to add this module in my project but it does not load. I have Ti 6.0.0.GA and this imageutility supports Ti 6.0.0.v2 which is not available in Axway Appcelerator Studio SDK release list. I have attached the sdk list screen shot for reference.

Any assistance will be appreciated.

Many thanks.

screen shot 2018-01-11 at 12 45 13 pm

This doesn't work on Android 6.0.0 with ti5.4.0

Took the picture in portrait mode, previewer shows image rotated, i click the check / approve icon and the image returned is in landscape.

Logs:
[INFO] : I/com.company.utils: (main) [1,8247] In rotateResizeImage
[INFO] : I/com.company.utils: (main) [0,8247] Detected orientation: 0
[INFO] : I/com.company.utils: (main) [0,8247] Determined rotation: 0
[INFO] : I/com.company.utils: (main) [0,8247] Original image size: 480x480
[INFO] : I/com.company.utils: (main) [0,8247] Sample size: 1
[INFO] : I/com.company.utils: (main) [3,8250] Sampled image size: 480x480
[INFO] : I/com.company.utils: (main) [4,8254] Scaled image size: 640x640
[INFO] : I/com.company.utils: (main) [0,8254] Deleted old file
[INFO] : I/com.company.utils: (main) [0,8254] Created new file
[INFO] : I/com.company.utils: (main) [10,8264] Copied rotated, resized image to new file

Tested on a Google Nexus 5 (1080x1920)

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.