Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Favicon service written in Go

License

NotificationsYou must be signed in to change notification settings

mat/besticon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a favicon service:

  • Supportsfavicon.ico andapple-touch-icon.png
  • Simple URL API
  • Fallback icon generation
  • Docker image & single binary download foreasy hosting

Try out the demo athttps://besticon-demo.herokuapp.com or find out how todeploy your own version right now.

Build StatusGo Report CardDonate at PayPal

What's this?

Websites used to have afavicon.ico, or not. With the introduction of theapple-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.

ParameterExampleDescriptionDefault
urlhttp://yelp.comrequired
size32..50..100Desired 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
formatspng,icoComma-separated list of accepted image formats: png, ico, gif, jpggif,ico,jpg,png,svg
fallback_icon_urlHTTP image URLIf 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_colorff0000If 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 URLIcon
https://besticon-demo.herokuapp.com/icon?url=yelp.com&size=32..50..120Icon for yelp.com
https://besticon-demo.herokuapp.com/icon?url=yelp.com&size=64..64..120Icon for yelp.com
https://besticon-demo.herokuapp.com/icon?url=yelp.comsize missing
https://besticon-demo.herokuapp.com/icon?url=httpbin.org/status/404&size=32..64..120Icon for non-existent page
https://besticon-demo.herokuapp.com/icon?url=httpbin.org/status/404&size=32..64..120&fallback_icon_color=ff0000Icon for non-existent page
https://besticon-demo.herokuapp.com/icon?url=фминобрнауки.рф&size=32..64..120Icon with cyrillic letter ф

GET /allicons.json

This endpoint returns all icons for a given site.

ParameterExampleDescriptionDefault
urlhttp://yelp.comrequired
formatspng,icoComma-separated list of accepted image formats: png, ico, gif, jpgpng,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 - athttps://github.com/mat/besticon/issues.

Hosting

Simple options to host this service are, for example:

Docker

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

Note that this docker image is not used to runhttps://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 ingrafana-dashboard.json.

Server Executable

Download binaries

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

Build your own

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

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

If you want to build executables for a different target operating system you can add theGOOS andGOARCH environment variables:

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

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 setCORS_ENABLED=true. Optionally, you can setadditional environment variables which will be passed as options to thers/cors middleware.

$ CORS_ENABLED=true iconserver

Now when you openhttp://localhost:8080/icons?url=instagram.com you should see something likeScreenshot of The Favicon Finder

Configuration

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

VariableDescriptionDefault Value
ADDRESSHTTP server listen address0.0.0.0
CACHE_SIZE_MBSize for thegroupcache, set to 0 to disable32
CORS_ENABLEDEnables thers/cors middlewarefalse
CORS_ALLOWED_HEADERSComma-separated, passed to middleware
CORS_ALLOWED_METHODSComma-separated, passed to middleware
CORS_ALLOWED_ORIGINSComma-separated, passed to middleware
CORS_ALLOW_CREDENTIALSBoolean, passed to middleware
CORS_DEBUGBoolean, passed to middleware
DISABLE_BROWSE_PAGESBoolean, if true, the server will not serve any of the HTML pagesfalse
HOST_ONLY_DOMAINS*
HTTP_CLIENT_TIMEOUTTimeout used for HTTP requests. Supports units like ms, s, m.5s
HTTP_MAX_AGE_DURATIONCache duration for all dynamically generated HTTP responses. Supports units like ms, s, m.720h(30 days)
HTTP_USER_AGENTUser-Agent used for HTTP requestsiPhone user agent string
METRICS_PATHPath at which the Prometheus metrics are served. Set todisable to disable Prometheus metrics/metrics
POPULAR_SITESComma-separated list of domains used on /popular pagesome random web sites
PORTHTTP server port8080
SERVER_MODESet todownload to proxy downloads through besticon orredirect to let browser to download instead. (example at#40)redirect

Contributors

License

MIT License (MIT)

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

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE.

Donate

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

Donate at PayPal


[8]ページ先頭

©2009-2025 Movatter.jp