Favicon service written in Go

Overview

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, jpg gif,ico,jpg,png,svg
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, jpg png,ico,gif,jpg

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

To enable CORS headers you need to set CORS_ENABLED=true. Optionally, you can set additional environment variables which will be passed as options to the rs/cors middleware.

$ CORS_ENABLED=true 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
ADDRESS HTTP server listen address 0.0.0.0
CACHE_SIZE_MB Size for the groupcache, set to 0 to disable 32
CORS_ENABLED Enables the rs/cors middleware false
CORS_ALLOWED_HEADERS Comma-separated, passed to middleware
CORS_ALLOWED_METHODS Comma-separated, passed to middleware
CORS_ALLOWED_ORIGINS Comma-separated, passed to middleware
CORS_ALLOW_CREDENTIALS Boolean, passed to middleware
CORS_DEBUG Boolean, passed to middleware
HOST_ONLY_DOMAINS *
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)
HTTP_USER_AGENT User-Agent used for HTTP requests iPhone user agent string
POPULAR_SITES Comma-separated list of domains used on /popular page some random web sites
PORT HTTP server port 8080
SERVER_MODE Set to download to proxy downloads through besticon or redirect to let browser to download instead. (example at #40) redirect

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

Comments
  • WIP Adding proxying support

    WIP Adding proxying support

    Sometimes this service needs to be hidden behind friendly lines and not exposing the exact URL for the favicon resource that was requested. Sometimes you get mixed results when your own service runs https but the favicon is supposed to be downloaded from http - causing everything to break and emit errors.

    Running the server with DOWNLOAD_MODE=proxy makes the server download and forward the resource to the user.

    opened by karl-ravn 8
  • Add fallback_icon_color query parameter to API.

    Add fallback_icon_color query parameter to API.

    If provided in the query parameters, this will use a hash of the URL passed in to color the letter icon used. The color is used when there is no icon of the requested size, and no "main color" could be found in smaller icons.

    The idea is that this will prevent so many icons being grey when a large icon size is requested.

    opened by mmkal 6
  • Never 404

    Never 404

    Hey, thanks for the awesome project! One thing that I've run into with favicons is that I always want to show an icon, so rendering 404 doesn't help me. Initially I assumed fallback_image_url would do the trick, but it only worked if the size doesn't match. So I made a change, and now I'm PR'ing it here to start a discussion.

    What's your take on this? It could also be hidden behind a flag, to always just fall back to the letter icons if no icon can be parsed.

    opened by erkie 4
  • Allow more configuration of the besticon package

    Allow more configuration of the besticon package

    This adds a new Besticon struct from which all the other methods are called. This allows removing all global variables and constants and replacing them by functional options. This makes it easier to configure all options with e.g. different named environment variables.

    This is a breaking change since it changes how all methods need to be called.

    Something which is not in this PR but may be useful is to remove the IconFinder and change it to be a FetchIcons method on the Besticon struct which takes functional options as well.

    See: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

    opened by koesie10 2
  • Disable pprof by default

    Disable pprof by default

    pprof was always enabled and could not be disabled without compiling different source code. This disables pprof by default by using a different ServeMux for serving all endpoints, and only delegating to the default HTTP ServeMux when pprof is explicitly enabled.

    opened by koesie10 1
  • svg lettericons

    svg lettericons

    The server can generate SVG lettericons. Only enabled if ?formats= includes svg. Most of the action is in RenderSVG. Also tweaks to IconPath to support SVG. For example, an SVG lettericon path doesn't include the size in the filename.

    One thing to note. The A-Z lettericons look great (see below), but ф is a bit low. Right now we have dy="0.10em" hardcoded in the SVG template. Not sure if it would be possible/worthwhile to customize based on the letter. I could also imagine using Freetype to measure the Arial glyph height... The traco 1M doesn't include any IDN domains, unfortunately.

    image

    opened by gurgeous 1
  • jpg support and tests

    jpg support and tests

    Added support for jpg images, and some tests. I used archive.org for the full test since it has a jpg icon. VS Code re-formatted the markdown a bit, hopefully that isn't a problem.

    opened by gurgeous 1
  • correct logic in perfect..min size search

    correct logic in perfect..min size search

    I believe I found the error in your logic for determining the correct min size. You have a comment there that describes what you wanted, but the logic did not match.

    The current code does not compare against the max or perfect range when searching for the biggest icon that is > min. Since the icons are sorted in descending order for this iterator, you will always get the largest icon from the list (which is the first one in the for loop). This confirms the behavior I am seeing in #28.

    Note: I am not a go developer and I was not able to run and test this code. I do, however, know how to read boolean logic 😃 . Please double check my work and syntax (I just copy/pasted and tweaked from the above logic).

    resolves #28

    opened by kspearrin 1
  • Allow changing Prometheus metrics path

    Allow changing Prometheus metrics path

    This adds an environment variable METRICS_PATH to change the path at which the Prometheus metrics are exposed. It can also be set to disable to fully disable the Prometheus metrics.

    opened by koesie10 0
  • Upgrade build tooling to Go 1.17

    Upgrade build tooling to Go 1.17

    I haven't fully updated the Travis file since I couldn't find it being used anywhere. Would you be interested in a follow-up PR to remove all unused files (e.g. it seems like the scripts and HOST_ONLY_DOMAINS are also unused)?

    opened by koesie10 0
  • use arrays for tests

    use arrays for tests

    I moved the tests into arrays so they are all handled in the same way. This is prep for adding a bunch more tests from the top1000. For each icon, I check the url, size and format. I also made it so that the VCR path is inferred from the URL host.

    opened by gurgeous 0
Releases(v3.13.0)
Owner
Matthias Lüdtke
I love building software @xing. Go, iOS, Ruby. Previously seen at @dynport and @crealytics
Matthias Lüdtke
A pair programming service using operational transforms

Leaps is a service for collaboratively editing your local files over a web UI, using operational transforms to ensure zero-collision synchronization a

Ashley Jeffs 729 Sep 27, 2022
Simple ANSi to PNG converter written in pure Go

AnsiGo Description AnsiGo is a simple ANSi to PNG converter written in pure Go. It converts files containing ANSi sequences (.ANS) into PNG images. Fo

Frederic Cambus 51 May 17, 2022
Super fast static photo and video gallery generator (written in Go and HTML/CSS/native JS)

fastgallery Fast static photo and video gallery generator Super fast (written in Go and C, concurrent, uses fastest image/video libraries, 4-8 times f

Toni Melisma 25 Aug 12, 2022
Storage and image processing server written in Go

Mort An S3-compatible image processing server written in Go. Still in active development. Features HTTP server Resize, Rotate, SmartCrop Convert (JPEG

Marcin Kaciuba 459 Aug 12, 2022
An image resizing server written in Go

picfit picfit is a reusable Go server to manipulate images (resize, thumbnail, etc.). It will act as a proxy on your storage engine and will be served

Florent Messa 1.7k Sep 26, 2022
A path tracer written in Go.

pt: a golang path tracer This is a CPU-only, unidirectional path tracing engine written in Go. It has lots of features and a simple API. Features Supp

Michael Fogleman 2k Sep 26, 2022
Pixelizer is an efficient image pixelizer written in go

Pixelizer is an image pixelizer written in go. It allows very simple and intuitive CLI pixelization. Installation To install Pixelizer, you

Rewan_ 104 Jul 2, 2022
Gorched is terminal based game written in Go inspired by "The Mother of all games" Scorched Earth

Gorched Gorched is terminal based game written in Go inspired by "The Mother of all games" Scorched Earth. How the game looks like depends on your ter

Ján Čabala 332 Sep 20, 2022
GameBoy Color emulator written in golang.

?? Worldwide 日本語のドキュメントはこちら GameBoyColor emulator written in golang. This emulator can play almost all ROMs work without problems and has many feature

Akatsuki 570 Sep 20, 2022
Dendrite is a second-generation Matrix homeserver written in Go!

Dendrite Dendrite is a second-generation Matrix homeserver written in Go. It intends to provide an efficient, reliable and scalable alternative to Syn

matrix.org 3.9k Sep 22, 2022
Quake 2 Level Renderer written in Go and OpenGL

go-quake2 Quake 2 Map Renderer written in Go and OpenGL. Features Loads any BSP file from Quake 2 Free roam around the environment Renders only a smal

Samuel Yuan 24 Jul 19, 2022
A captcha library written in golang

gocaptcha 一个简单的Go语言实现的验证码 图片实例 简介 基于Golang实现的图片验证码生成库,可以实现随机字母个数,随机直线,随机噪点等。可以设置任意多字体,每个验证码随机选一种字体展示。 实例 使用: go get github.com/lifei6671/gocaptcha/

Minho 172 Sep 4, 2022
A simple API written in Go that creates badges in SVG format, based on the requested route.

A simple API written in Go that creates badges in SVG format, based on the requested route. Those graphics can be used to style README.md files, or to add tags to webpages.

Toby 3 Jul 2, 2021
ColorX is a library to determine the most prominent color in an image written in golang

ColorX is a library to determine the most prominent color in an image. ColorX doesn't use any sort of complex algorithms to calculate the prominent color, it simply loops over the image pixels and returns the color that occurs the most.

Hesham Abourgheba 1 Nov 11, 2021
Pbm - Package ppm implements a Portable Bit Map (PBM) image decoder and encoder written in Go

Package pbm import "github.com/slashformotion/pbm" Package pbm implements a Portable Bit Map (PBM) image decoder and encoder. The supported image col

slashformotion 0 Jan 5, 2022
Generate a favicon.ico from a short string

icostring Generate a file in the ICO format from a short string of either 16 or 64 characters ('a'..'p', 'q' and 't') + an optional hex encoded color

Alexander F. Rødseth 4 Dec 24, 2021
Rpcx-framework - An RPC microservices framework based on rpcx, simple and easy to use, ultra fast and efficient, powerful, service discovery, service governance, service layering, version control, routing label registration.

RPCX Framework An RPC microservices framework based on rpcx. Features: simple and easy to use, ultra fast and efficient, powerful, service discovery,

ZYallers 1 Jan 5, 2022
Service that calls uzma24/project1 service, takes input from .txt file and prints JSON output returned from the service.

Service that calls uzma24/project1 service, takes input from .txt file and prints JSON output returned from the service. Program can take large input files.

null 0 Feb 6, 2022
AppsFlyer 497 Sep 26, 2022
Open Service Mesh (OSM) is a lightweight, extensible, cloud native service mesh that allows users to uniformly manage, secure, and get out-of-the-box observability features for highly dynamic microservice environments.

Open Service Mesh (OSM) Open Service Mesh (OSM) is a lightweight, extensible, Cloud Native service mesh that allows users to uniformly manage, secure,

Open Service Mesh 2.5k Sep 19, 2022