Created
July 7, 2014 05:16
-
-
Save shunirr/ef13cfcf8779086c4421 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'json' | |
def rotate(up) | |
if up > 800 | |
return 90 | |
elsif up > 140 | |
return 180 | |
elsif up < -198 | |
return 270 | |
elsif up < 60 | |
return 0 | |
end | |
return 0 | |
end | |
Dir.glob("*.json").each do |json| | |
jpeg = json.gsub('.json', '.jpg') | |
next unless File.exist? jpeg | |
j = JSON.parse(open(json).read) | |
up = j['acc_data']['samples'][0][1].to_i | |
system('convert', jpeg, '-rotate', rotate(up).to_s, "#{jpeg.gsub('.jpg', '-2.jpg')}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment