Skip to content

Instantly share code, notes, and snippets.

@twolfson
Last active June 7, 2022 23:45
Show Gist options
  • Save twolfson/988fd6fa312ee0283906da16f509dbff to your computer and use it in GitHub Desktop.
Save twolfson/988fd6fa312ee0283906da16f509dbff to your computer and use it in GitHub Desktop.
Capturing retina screenshots on a non-retina device via Xvfb

We are bootstrapping a startup and don't own any retina devices to capture high resolution screenshots. Thankfully, this is possible via Xvfb.

Convenience Node.js script here: https://gist.github.com/twolfson/4f7e7ec7d6969173d6a095f86e2d47c8

Here's how to get started manually:

  • Launch an Xvfb instance with retina-scale DPI
    • Xvfb :99 -screen 0 3840x2160x24 -dpi 240
    • We'll be using :99 as our $DISPLAY but any unused value will do
    • Note that we are using 2x our expected resolution for dimensions (1920x1080 * 2 -> 3840x2160)
  • Launch our browser inside of Xvfb
  • Export our Xvfb via ImageMagick
    • import -window root out.png
    • We cannot export contents via Selenium as they get downscaled to 1x =(
    • We can target the window specifically as well via
      • xwininfo -root -children
        • Lists child windows
        • Find something that looks like a large window
          • 0x200023 "Mozilla Firefox": ("Navigator" "Firefox") 3456x1944+0+0 +0+0
      • Export that window via ImageMagick
        • import -window 0x200023 out.png

Attribution:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment