Skip to content

Instantly share code, notes, and snippets.

@willywos
Created December 13, 2012 15:11
Show Gist options
  • Save willywos/4277008 to your computer and use it in GitHub Desktop.
Save willywos/4277008 to your computer and use it in GitHub Desktop.
Websnap example on heroku
#The code in the rake task looks like this:
#lib/tasks/scheduler.rake
desc "Updates the images for winter conditions"
task :update_images => :environment do
puts "Updating Images"
WinterCondition.update_images
puts "Done Updating Images"
end
#app/models/WinterCondition.rb
def self.update_images
url = "http://lb.511ia.org/ialb/winterdriving/routeselect.jsf?view=desmoines"
snap = WebSnap::Snapper.new(url, :format => 'png',
:'scale-h' => nil,
:'scale-w' => nil,
:'crop-h' => 380,
:'crop-w' => 640,
:quality => 100,
:'crop-x' => 260,
:'crop-y' => 265)
wc = WinterCondition.find(1)
wc.image = snap.to_bytes
wc.save!
end
#app/controllers/winter_conditions_controller.rb
def image
@wc = WinterCondition.find(1)
respond_to do |format|
format.png {
send_data @wc.image, :filename => "#{Rails.root}/png/desmoines.png", :type => "image/png", :disposition => 'inline'
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment