vitalie/webshot

Target a div when take screenshot

Rubioli opened this issue · 1 comments

Great gem.

Im using the gem in my own application and taking screenshots from some pages inside application. Im not interested to take a screenshot of the whole page but only a targeted div.

Is it possible to Target a div when taking screen shot?

PS: Im not using MiniMagic and creating the screenshot in my model

Here is my code

class Post < ActiveRecord::Base
# In my Post model
after_save :save_screeshot 
def save_screeshot
    Dir.mkdir "public/screenshots/#{self.id}"
    ws = Webshot::Screenshot.instance

  # Customize thumbnail
    ws.capture "http://google.com/", "public/screenshots/#{self.id}/screenshot.png", width: 600, height: 315, quality: 100
  end

end

way too late to answer, anyone in future wondering the same thing, you can pass selector to ws.capture
e.g:

ws.capture "http://google.com/", "public/screenshots/#{self.id}/screenshot.png", selector: '.class-name'

though this gem always passes full: true parameter to phantomJS's save_screenshot method, and atleast from phantomJS v2.1.1, it ignores the selector parameter if full: true is given.

I have made a PR #31 to resolve this issue