Skip to content

Instantly share code, notes, and snippets.

@mikka2061
Created October 27, 2017 17:42
Show Gist options
  • Save mikka2061/c43c9692f5369b66f43c0cc9640f01ed to your computer and use it in GitHub Desktop.
Save mikka2061/c43c9692f5369b66f43c0cc9640f01ed to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'listen'
require 'skeptick'
require 'pp'
include Skeptick
uploads_dir = "/u/files/"
originals = "uploads/"
sizes = {
"small" => {
"location" => "small/",
"size" => "300x"
},
"medium" => {
"location" => "med/",
"size" => "600x"
},
"web" => {
"location" => "web/",
"size" => "900x"
}
}
listener = Listen.to(uploads_dir+originals) do |added|
sizes.each { |size,data|
if (added[0] != nil)
addfile = File.basename(added[0])
from = uploads_dir+originals+addfile
to = uploads_dir+data["location"]+addfile
make = convert(from, to: to) do
set :scale, data["size"]
end
make.run
end
}
end
listener.start # not blocking
sleep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment