Skip to content
Favicon service written in Go
Go HTML Makefile Other
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Create FUNDING.yml Oct 19, 2019
besticon Fix 'can't give argument to non-function len' on go 1.14 Mar 18, 2020
colorfinder Add support for ico.Decode() (closes #12) Dec 7, 2016
ico gofmt -s -w ico/ico_test.go Dec 17, 2016
lettericon Limit lettericon size to 256 Oct 31, 2016
scripts Update bash scripts to use set -euxo pipefail Nov 23, 2017
vcr Handle missing URL scheme in base path correctly Oct 25, 2015
vendor dep ensure -update Jul 29, 2019
.codeclimate.yml Add .codeclimate.yml Nov 18, 2016
.gitattributes Don't exlcude all .html files from language stats per se. Apr 7, 2015
.gitignore Add make gotags. Jul 14, 2015
.travis.yml Add go 1.14.(1|2|3) to travis.yml May 28, 2020
Dockerfile Add SERVER_MODE to remaining files Dec 10, 2019
Gopkg.lock dep ensure -update Jul 29, 2019
Gopkg.toml Use go 1.14 Mar 18, 2020
HOST_ONLY_DOMAINS Add quora.com to HOST_ONLY_DOMAINS Oct 24, 2017
LICENSE Update copyright note for 2020 Dec 29, 2019
Makefile Unify all docker make targets Sep 14, 2019
Procfile Switch from --port to PORT Dec 2, 2015
Readme.markdown Add option to change listening address at startup (#41) Feb 5, 2020
VERSION Release v3.11.0 Dec 10, 2019
app.json Add SERVER_MODE to remaining files Dec 10, 2019
docker_run.env Add SERVER_MODE to remaining files Dec 10, 2019
grafana-dashboard.json Add /lettericons and /allicons to Grafana Feb 14, 2019
the-icon-finder.png It's about favicons, really. Aug 29, 2015

Readme.markdown

favicon-service (besticon)

This is a favicon service:

  • Supports favicon.ico and apple-touch-icon.png
  • Simple URL API
  • Fallback icon generation
  • Docker image & single binary download for easy hosting

Try out the demo at https://besticon-demo.herokuapp.com or find out how to deploy your own version right now.

Build Status Go Report Card Donate at PayPal

What's this?

Websites used to have a favicon.ico, or not. With the introduction of the apple-touch-icon.png finding “the icon” for a website became more complicated. This service finds and — if necessary — generates icons for web sites.

API

GET /icon

This endpoint always returns an icon image for the given site — it redirects to an official icon if possible or creates and returns a fallback image if needed.

Parameter Example Description Default
url http://yelp.com required
size 32..50..100 Desired size range (min..perfect..max) If no image of size perfect..max nor perfect..min can be found a fallback icon will be generated. required
formats png,ico Comma-separated list of accepted image formats: png, ico, gif png,ico,gif
fallback_icon_url HTTP image URL If provided, a redirect to this image will be returned in case no suitable icon could be found. This overrides the default fallback image behaviour.
fallback_icon_color ff0000 If provided, letter icons will be colored with the hex value provided, rather than be grey, when no color can be found for any icon.

Examples

Input URL Icon
https://besticon-demo.herokuapp.com/icon?url=yelp.com&size=32..50..120 Icon for yelp.com
https://besticon-demo.herokuapp.com/icon?url=yelp.com&size=64..64..120 Icon for yelp.com
https://besticon-demo.herokuapp.com/icon?url=yelp.com size missing
https://besticon-demo.herokuapp.com/icon?url=httpbin.org/status/404&size=32..64..120 Icon for non-existent page
https://besticon-demo.herokuapp.com/icon?url=httpbin.org/status/404&size=32..64..120&fallback_icon_color=ff0000 Icon for non-existent page
https://besticon-demo.herokuapp.com/icon?url=фминобрнауки.рф&size=32..64..120 Icon with cyrillic letter ф

GET /allicons.json

This endpoint returns all icons for a given site.

Parameter Example Description Default
url http://yelp.com required
formats png,ico Comma-separated list of accepted image formats: png, ico, gif png,ico,gif

Examples

Bugs & limitations

I tried hard to make this useful but please note there are some known limitations:

  • Poor i18n support for letter icons (#13)

Feel free to file other bugs - and offer your help - at https://github.com/mat/besticon/issues.

Hosting

Simple options to host this service are, for example:

Docker

A docker image is available at https://hub.docker.com/r/matthiasluedtke/iconserver/, generated from the Dockerfile in this repo. I try to keep it updated for every release.

Note that this docker image is not used to run https://besticon-demo.herokuapp.com and therefore not well tested.

Monitoring

Prometheus metrics are exposed under /metrics. A Grafana dashboard config based on these metrics can be found in grafana-dashboard.json.

Server Executable

Download binaries

Binaries for some operating systems can be downloaded from https://github.com/mat/besticon/releases/latest

Build your own

If you have Go installed on your system you can use go get to fetch the source code and build the server:

$ go get -u github.com/mat/besticon/...

If you want to build executables for a different target operating system you can add the GOOS and GOARCH environment variables:

$ GOOS=linux GOARCH=amd64 go get -u github.com/mat/besticon/...

Running

To start the server on default port 8080 just do

$ iconserver

To use a different port use

$ PORT=80 iconserver

To listen on a different address (say localhost) use

$ ADDRESS=127.0.0.1 iconserver

Now when you open http://localhost:8080/icons?url=instagram.com you should see something like Screenshot of The Favicon Finder

Configuration

There is not a lot to configure but these environment variables exist

Variable Description Default Value
PORT HTTP server port 8080
CACHE_SIZE_MB Size for the groupcache 32
HTTP_USER_AGENT User-Agent for HTTP requests iPhone user agent string
HTTP_CLIENT_TIMEOUT Timeout used for HTTP requests. Supports units like ms, s, m. 5s
HTTP_MAX_AGE_DURATION Cache duration for all dynamically generated HTTP responses. Supports units like ms, s, m. 720h (30 days)
POPULAR_SITES Comma-separated list of domains used on /popular page
SERVER_MODE Set to download to proxy downloads through besticon or redirect to let browser to download instead. (example at #40) redirect

Libraries etc.

Package Description License
http://github.com/PuerkitoBio/goquery BSD style
http://github.com/andybalholm/cascadia CSS selectors License
http://github.com/golang/groupcache Apache License 2.0
http://github.com/golang/protobuf License
http://github.com/golang/freetype FreeType License
http://golang.org/x/image supplementary image libraries BSD style
http://golang.org/x/net BSD style
http://golang.org/x/text BSD style
Noto Sans font used for the generated icons SIL Open Font License 1.1
The icon License

Contributors

License

MIT License (MIT)

Copyright (c) 2015-2020 Matthias Lüdtke, Hamburg - https://github.com/mat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Donate

If you find this useful and want to donate... you would make my day :-)

Donate at PayPal

You can’t perform that action at this time.