免费!免费!这些开源图标太全了~~~

职场   其他   2024-12-26 11:28   福建  

平时我们在开发项目的时候,经常会用到一些品牌的图标,去网上找吧,费时费力,有时候找出来的又很大,需要用专门工具处理成我们想要的格式。

今天就给大家介绍一个免费的开源图标大全 simple-icons
simple-icons 在 GitHub 上已经收获了 21.4k+ 的 Star 了:

simple-icons 是一个开源项目,提供了一个包含所有常见品牌图标的 SVG 图标库,涵盖了各种流行的服务和平台,如 GitHub、Twitter、Google、Ali、Baidu、Facebook、Slack 等。
simple-icons 图标以 SVG 格式提供,可以轻松地嵌入到 Web 页面或移动应用中。
simple-icons  为开发者、设计师和所有人提供一个简单易用的资源库,帮助唯美可以快速找到并使用各种品牌的官方图标

我们可以在上面搜索 github 的图标,把鼠标移动到该图标上就可以复制 svg 图标代码:

搜索 ali ,可以列出相关的品牌图标:

simple-icons 提供的图标是 SVG 格式,所以我们可以自由调整大小、颜色和样式,而不会失去图标的清晰度,通过 CSS 或其他样式,可以方便地对图标进行自定义。
simple-icons 完全是开源的,任何人都可以自由使用、修改和分发这些图标。 

开源地址:https://github.com/simple-icons/simple-icons

官方地址:https://simpleicons.org/


安装使用

我们可以直接从 simpleicons.org 下载 SVG 格式,只需点击您想要的图标的下载按钮,就会下载对应图标的 png 文件:

也可以通过可以通过  jsDelivr 或 unpkg 提供 CDN 链接:

<img height="32" width="32" src="https://cdn.jsdelivr.net/npm/simple-icons@v14/icons/[ICON SLUG].svg" /><img height="32" width="32" src="https://unpkg.com/simple-icons@v14/icons/[ICON SLUG].svg" />

其中 [ICON_SLUG] 替换为您想要使用的图标的 slug,例如:

<img height="32" width="32" src="https://cdn.jsdelivr.net/npm/simple-icons@v14/icons/simpleicons.svg" /><img height="32" width="32" src="https://unpkg.com/simple-icons@v14/icons/simpleicons.svg" />

我们还提设置颜色:

<img height="32" width="32" src="https://cdn.simpleicons.org/[ICON SLUG]" /><img height="32" width="32" src="https://cdn.simpleicons.org/[ICON SLUG]/[COLOR]" /><img height="32" width="32" src="https://cdn.simpleicons.org/[ICON SLUG]/[COLOR]/[DARK_MODE_COLOR]" />

其中 [COLOR] 是可选的,可以替换为您想要使用的图标的十六进制颜色或 CSS 关键字。

颜色默认为 simpleicons.org 网站上显示的图标的 HEX 颜色。

[DARK_MODE_COLOR] 用于深色模式。

当指定值时,将使用 CSS prefers-color-scheme。例如:

<img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/gray" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/hotpink" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/0cf" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/0cf9" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/00ccff" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/00ccff99" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/orange/pink" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/_/eee" /><img height="32" width="32" src="https://cdn.simpleicons.org/simpleicons/eee/_" />

我们可以使用 viewbox=auto 参数来获得自动大小的视图框:

<img height="20" src="https://cdn.simpleicons.org/github?viewbox=auto" /><img height="20" src="https://cdn.simpleicons.org/simpleicons?viewbox=auto" /><img height="20" src="https://cdn.simpleicons.org/awesomelists?viewbox=auto" />

我们也可以通过 npm 安装使用图标:

npm install simple-icons

建议使用打包器,如 webpack,以移除未使用的图标代码:

// 通过其 slug 导入特定图标:// import { si[ICON_SLUG] } from 'simple-icons'
// 例如:// 使用 import/esm 以允许 tree shakingimport {siSimpleicons} from 'simple-icons';// 或者使用 require/cjsconst {siSimpleicons} = require('simple-icons');

以上代码返回一个图标对象:

console.log(siSimpleicons);
/*{ title: 'Simple Icons', slug: 'simpleicons', hex: '111111', source: 'https://simpleicons.org/', svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">...</svg>', path: 'M12 12v-1.5c-2.484 ...', guidelines: 'https://simpleicons.org/styleguide', license: { type: '...', url: 'https://example.com/' }}
NOTE: the `guidelines` entry will be `undefined` if we do not yet have guidelines for the icon.NOTE: the `license` entry will be `undefined` if we do not yet have license data for the icon.*/

如果您需要遍历所有图标,可以使用:

import * as icons from 'simple-icons';br

TypeScript 使用:

import type {SimpleIcon} from 'simple-icons';

PHP 使用可以通过 Packagist 包获得:

composer require simple-icons/simple-icons

安装后就可以开始使用了:

<?php// 通过其 slug 导入特定图标:echo file_get_contents('path/to/package/icons/[ICON_SLUG].svg');
// 例如:echo file_get_contents('path/to/package/icons/simpleicons.svg');
// <svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">...</svg> ?>



菜鸟教程
学的不仅是技术,更是梦想!
 最新文章