Created
February 16, 2018 23:04
-
-
Save alexbaldwin/32644965cd47e40ed2f982823c2f0e0b to your computer and use it in GitHub Desktop.
Post images from the ready folder
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
require 'fastimage' | |
require 'shellwords' | |
require 'tty-command' | |
require 'mini_exiftool' | |
require 'dotenv/load' | |
cmd = TTY::Command.new | |
# Wait up to 2 hours before posting | |
sleep (0..7200).to_a.sample | |
posts = Dir.entries("#{__dir__}/inbox").select {|f| f.include? 'jpg' } | |
p posts.count | |
post = posts.first | |
puts post | |
post_location = Shellwords.escape("#{__dir__}/inbox/#{post}") | |
puts post_location | |
# Get the title | |
photo = MiniExiftool.new(post_location) | |
note = photo.title.to_s || " " | |
puts note | |
puts post_location | |
size = FastImage.new(post_location).size | |
puts size | |
if (size[0] - size[1]).abs < 10 | |
p "Square #{size}" | |
cmd.run("smartcrop --width 1080 --height 1080 #{post_location} #{__dir__}/final.jpg") | |
elsif size[0] > size [1] | |
p "Horizontal #{size}" | |
cmd.run("smartcrop --width 1080 --height 570 #{post_location} #{__dir__}/final.jpg") | |
else | |
p "Vertical #{size}" | |
cmd.run("smartcrop --width 864 --height 1080 #{post_location} #{__dir__}/final.jpg") | |
end | |
# Delete the final image | |
cmd.run("rm #{post_location}") | |
emojis = ['🏠'] | |
title = "" | |
title << emojis.sample + ' ' + note + ' #tinyhome #instagood #beautiful #instadaily #nature #cabin #modern #design #lifestyle #home #inspiration #architecture #building #architecturelovers #vsco #vscoedit #interior #dwell #woods #forest #geometric #architectureporn #igers' | |
puts title | |
cmd.run("php #{File.expand_path("..", __dir__)}/uploadPhoto.php #{ENV['INSTAGRAM_USERNAME']} #{ENV['INSTAGRAM_PASSWORD']} #{__dir__}/final.jpg \"#{title}\"") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment