सामग्री पर जाएँ
Favicon.is

इंटीग्रेशन उदाहरण

Favicon.is हर उस जगह काम करता है जहाँ आप इमेज URL इस्तेमाल कर सकते हैं। अपना स्टैक चुनें और स्निपेट कॉपी करें।

HTML

सबसे आसान तरीका: <img> टैग को API की ओर पॉइंट करें। लेआउट शिफ़्ट से बचने के लिए width और height जोड़ें।

HTML
<img src="https://favicon.is/github.com" width="32" height="32" alt="GitHub" loading="lazy">

<!-- High resolution for retina screens -->
<img src="https://favicon.is/github.com?larger=true" width="64" height="64" alt="GitHub">

Markdown

README फ़ाइलों, डॉक्स और नोट्स में साइट आइकन दिखाएँ।

Markdown
![GitHub](https://favicon.is/github.com?size=32) [GitHub](https://github.com)

CSS

आइकन को बैकग्राउंड इमेज के रूप में इस्तेमाल करें, जैसे बाहरी लिंक के बगल में।

CSS
a[href^="https://github.com"]::before {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.35em;
  vertical-align: -0.125em;
  background: url("https://favicon.is/github.com?size=32") center / contain no-repeat;
}

JavaScript

रनटाइम पर पेज के हर बाहरी लिंक में आइकन जोड़ें।

JavaScript
document.querySelectorAll('a[href^="http"]').forEach((link) => {
  const { hostname } = new URL(link.href);
  const icon = document.createElement('img');
  icon.src = `https://favicon.is/${hostname}?size=32`;
  icon.width = icon.height = 16;
  icon.alt = '';
  icon.loading = 'lazy';
  icon.style.marginRight = '0.35em';
  link.prepend(icon);
});

React

एक छोटा, दोबारा इस्तेमाल होने वाला कंपोनेंट, जो इमेज लोड न होने पर फ़ॉलबैक दिखाता है।

React
export function Favicon({ domain, size = 16 }) {
  return (
    <img
      src={`https://favicon.is/${domain}?size=${size * 2}`}
      width={size}
      height={size}
      alt=""
      loading="lazy"
      onError={(event) => {
        event.currentTarget.src = 'https://favicon.is/default-favicon.svg';
      }}
    />
  );
}

// <Favicon domain="github.com" />

Vue

वही कंपोनेंट, Vue सिंगल-फ़ाइल कंपोनेंट के रूप में।

Vue
<script setup>
defineProps({
  domain: { type: String, required: true },
  size: { type: Number, default: 16 },
});
</script>

<template>
  <img
    :src="`https://favicon.is/${domain}?size=${size * 2}`"
    :width="size"
    :height="size"
    alt=""
    loading="lazy"
  />
</template>

Python

स्क्रिप्ट से आइकन डाउनलोड करें, जैसे बुकमार्क पेज बनाने के लिए।

Python
import pathlib
import urllib.request

domains = ["github.com", "wikipedia.org", "python.org"]
out = pathlib.Path("icons")
out.mkdir(exist_ok=True)

for domain in domains:
    with urllib.request.urlopen(f"https://favicon.is/{domain}?larger=true") as response:
        ext = {"image/png": "png", "image/x-icon": "ico", "image/svg+xml": "svg"}.get(
            response.headers.get_content_type(), "img"
        )
        (out / f"{domain}.{ext}").write_bytes(response.read())
        print(domain, response.headers["X-Source"])

PHP

सर्वर-साइड टेम्पलेट में आइकन रेंडर करें।

PHP
<?php
$domain = parse_url($link, PHP_URL_HOST);
$src = 'https://favicon.is/' . rawurlencode($domain) . '?size=32';
?>
<img src="<?= htmlspecialchars($src) ?>" width="16" height="16" alt="">

Go

आइकन फ़ेच करें और उसे डिस्क पर सेव करें।

Go
package main

import (
	"io"
	"net/http"
	"os"
)

func main() {
	resp, err := http.Get("https://favicon.is/go.dev?larger=true")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	file, err := os.Create("go.dev.png")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	if _, err := io.Copy(file, resp.Body); err != nil {
		panic(err)
	}
}

cURL

कमांड लाइन से रिस्पॉन्स हेडर जाँचें।

cURL
# Inspect the response headers
curl -I https://favicon.is/github.com

# Save a 64 px icon
curl -o github.png "https://favicon.is/github.com?size=64"