Skip to content

Instantly share code, notes, and snippets.

@shunirr
Created July 7, 2014 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shunirr/ef13cfcf8779086c4421 to your computer and use it in GitHub Desktop.
Save shunirr/ef13cfcf8779086c4421 to your computer and use it in GitHub Desktop.
#!/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