stack twitter tryhackme rss linkedin cross

Wilco van Esch

Skip to main content

Search results

    Configuring the wkhtmltoimage path for IMGKit on Windows

    If you'd like to use IMGKit, you'll also have to install wkhtmltopdf, which includes wkhtmltoimage - a command line tool to generate images from an HTML page.

    From IMGKit's documentation:

    If you're on Windows or you installed wkhtmltoimage by hand to a location other than /usr/local/bin you will need to tell IMGKit where the binary is.

    If you're using Rails, you can define this in config/initializers/imgkit.rb If you're not using Rails, you can use the same definition where you're requiring imgkit.

    IMGKit.configure do |config|
      config.wkhtmltoimage = '/path/to/wkhtmltoimage'

    In Windows, that path has to include the filename and extension. If you don't add it, you'll receive a NoExecutableError or a "Permission Denied" error.

    Example path:

    C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltoimage.exe

    You can test the configuration in irb like this:

    irb(main):003:0> html = ""
    => ""
    irb(main):004:0> kit =, :quality => 50)
    => #<IMGKit:0x00000002fa0120
    @source="">, @stylesheets=[],
    @javascripts=[], @options={:height=>0, :quality=>50}>

    If it doesn't work, try adding the path to your PATH environment variable.

    If it still doesn't work, you can amend the path in the gem's configuration file directly.

    # C:\Ruby##-x64\lib\ruby\gems\#.#.#\
    def wkhtmltoimage
      @wkhtmltoimage ||= begin
        path = (using_bundler? ? `bundle exec which wkhtmltoimage`
        : `which wkhtmltoimage`).chomp
        path =
        'C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltoimage.exe'
        if path.strip.empty?
    # Fallback