• This repository has been archived on 30/Jan/2024
  • Stars
    star
    534
  • Rank 83,095 (Top 2 %)
  • Language
    Go
  • License
    GNU General Publi...
  • Created almost 8 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HTTP server with API for capturing screenshots of websites

url2img

url2img is HTTP server with API for capturing screenshots of websites.

Example (command line):

$ curl -s http://localhost:55888/?url=google.com > google.jpg

Example (web browser):

http://localhost:55888/?url=google.com&output=html

API

Name Type Default Description
url string Target URL (required), http(s):// prefix is optional
output string raw Output format (raw, base64, html)
format string jpg Image format (jpg, png)
ua string User-Agent string
quality int 85 Image quality
delay int 0 Delay screenshot after page is loaded (milliseconds)
width int 1600 Viewport width
height int 1200 Viewport height
zoom float 1.0 Zoom factor
full bool false Capture full page height

Usage

Usage of url2img:

  -bind-addr string
        Bind address (default ":55888")
  -cache-dir string
        Path to cache directory, if empty caching is disabled
  -htpasswd-file string
        Path to htpasswd file, if empty auth is disabled
  -log-file string
        Path to log file, if empty logs to stdout
  -max-age int
        Cache maximum age (seconds) (default 86400)
  -read-timeout int
        Read timeout (seconds) (default 5)
  -write-timeout int
        Write timeout (seconds) (default 15)

Auth

If server is started with -htpasswd-file it will be protected with HTTP Basic Auth. Supports MD5, SHA1 and BCrypt (https://github.com/abbot/go-http-auth).

Examples:

$ htpasswd -c .htpasswd username
$ url2img -htpasswd-file .htpasswd

$ curl -I 'http://localhost:55888/?url=google.com'

HTTP/1.1 401 Unauthorized
Content-Type: text/plain; charset=utf-8
Www-Authenticate: Basic realm="url2img/1.0"
X-Content-Type-Options: nosniff
Date: Wed, 09 Nov 2016 17:50:33 GMT
Content-Length: 17

$ curl -u username:password -s http://localhost:55888/?url=google.com > google.jpg
$ curl -s http://username:password@localhost:55888/?url=google.com > google.jpg
$ curl --netrc-file my-password-file http://localhost:55888/?url=google.com > google.jpg

Cache

If server is started with -cache-dir it will cache HTTP responses to disk according to RFC7234 (https://github.com/lox/httpcache). You can use -max-age to control maximum age of cache file, default is 86400 seconds (1 day).

Example:

$ curl -I 'http://localhost:55888/?url=https://reddit.com'

HTTP/1.1 200 OK
Accept-Ranges: bytes
Age: 21
Cache-Control: public,max-age=86400
Content-Length: 21107
Content-Type: image/jpeg
Last-Modified: Wed, 09 Nov 2016 18:25:26 GMT
Proxy-Date: Wed, 09 Nov 2016 17:25:26 GMT
Server: url2img/1.0
Via: 1.1 httpcache
X-Cache: HIT
Date: Wed, 09 Nov 2016 17:25:47 GMT

If you want uncached response you can request it via Cache-Control header:

$ curl -H 'Cache-Control: no-cache' 'http://localhost:55888/?url=https://reddit.com'

Or you can send POST request with json body, POST requests are never cached:

$ curl -X POST -d '{"url": "https://reddit.com", "format": "png"}' http://localhost:55888

Reload

To reload server (e.g. when .htpasswd is changed or log file is rotated) send SIGHUP signal to process. If you use one of the provided init scripts just do a reload.

Download

Binary is compiled fully static with musl toolchain. It should work on all systems without any additional dependencies. Systemd and OpenRC init scripts are included in dist/.

Alternative: run in Docker container

An alternative is to run everything in a container. Change to the dist/docker directory and:

# Build container: `docker build -t url2img .`
# Then run container: `docker run -p 55888:55888 url2img`

Output should be like this:

$ docker run -p 55888:55888 url2img
running server on port 55888

Compile

Install Qt bindings (https://github.com/therecipe/qt) with WebKit (see https://github.com/therecipe/qt/wiki/Installing-QtWebKit-Module).

Install url2img to $GOPATH/bin:

$ go get -d github.com/gen2brain/url2img
$ go generate github.com/gen2brain/url2img/url2img
$ qtminimal linux $GOPATH/src/github.com/gen2brain/url2img/url2img
$ go install -tags minimal github.com/gen2brain/url2img/cmd/url2img

License

url2img is free/libre software released under the terms of the GNU GPL license, see the 'COPYING' file for details.

More Repositories

1

raylib-go

Go bindings for raylib, a simple and easy-to-use library to enjoy videogames programming.
C
1,528
star
2

beeep

Go cross-platform library for sending desktop notifications, alerts and beeps
Go
1,428
star
3

cam2ip

Turn any webcam into an IP camera
Go
868
star
4

go-fitz

Golang wrapper for the MuPDF Fitz library
C
396
star
5

dlgs

Go cross-platform library for displaying dialogs and input boxes
Go
383
star
6

malgo

Mini audio library
C
285
star
7

go-unarr

Go bindings for unarr (decompression library for RAR, TAR, ZIP and 7z archives)
Go
280
star
8

iup-go

Cross-platform UI library with native controls
Go
273
star
9

x264-go

Go bindings for x264
Go
211
star
10

goiv

Small and simple image viewer written in pure Go.
Go
201
star
11

cbconvert

CBconvert is a Comic Book converter
Go
190
star
12

shm

System V shared memory functions in pure Go.
Go
126
star
13

mpeg

MPEG-1 Video decoder, MP2 Audio decoder and MPEG-PS Demuxer in pure Go
Go
124
star
14

bukanir

Bukanir streams movies and TV shows from bittorrent magnet links
Java
84
star
15

aac-go

Go bindings for vo-aacenc
Go
58
star
16

gsmgo

GSMGo is SMS HTTP server with REST API
Go
50
star
17

keepalived_exporter

Keepalived Prometheus Exporter
Go
44
star
18

go-sdl2-android-example

Go-SDL2 example running on Android
Java
32
star
19

vov

VoV is a high score game for Android
Go
30
star
20

jpegli

Go encoder/decoder for JPEG based on jpegli
Go
29
star
21

volti

Volti is GTK+ application for controlling audio volume from system tray/notification area
Python
28
star
22

pyhtmleditor

PyQt WYSIWYG HTML Editor
Python
26
star
23

go-mpv

Go bindings for libmpv
Go
26
star
24

acra-go

Backend for Application Crash Reports for Android (ACRA)
Go
24
star
25

avif

AVIF image encoder/decoder
Go
24
star
26

jpegxl

JPEG XL image encoder/decoder
Go
16
star
27

flite-go

Go bindings for Flite (festival-lite)
Go
14
star
28

webp

WebP image encoder/decoder
Go
11
star
29

crtaci

"Crtaći" searches YouTube, DailyMotion and Vimeo for good old cartoons
Go
10
star
30

vidextr

Simple video extractor for YouTube, DailyMotion and Vimeo in Go.
Go
10
star
31

heic

HEIC image decoder
Go
9
star
32

comic-utils

Comic book archive utils
Python
6
star
33

oss

oss provides access to OSS (Open Sound System) audio interface
Go
6
star
34

svg

SVG icon decoder
Go
6
star
35

jxl

Go decoder for JPEG XL image format
C
4
star
36

mpeg-examples

Examples for mpeg library
Go
4
star
37

framebuffer

Fork of removed repo github.com/jteeuwen/framebuffer
Go
4
star
38

go-smpeg2

Golang bindings for the smpeg2 - SDL2 MPEG Player Library
Go
4
star
39

prang

A violent point-and-shoot game for android
C
2
star
40

bgradio

Qt/libVLC online radio streaming player that runs in system tray
Python
2
star
41

vim

My Vim config
Vim Script
1
star
42

base64

Fork of goost.org/encoding/base64
Go
1
star
43

umtsmon

Qt4 port of umtsmon
C++
1
star
44

libtorrent-go

SWIG Go bindings for libtorrent-rasterbar
C++
1
star