redeyeventures/geopattern

生成美丽的SVG图案。

v1.1.2 2021-03-16 09:52 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:52:54 UTC


README

Latest Version Latest unstable Version

这是 jasonlong/geo_pattern 的 PHP 版本。

从字符串生成美丽的平铺SVG图案。该字符串被转换为SHA,并根据哈希值中的值确定颜色和图案。颜色是通过从默认颜色(或传入的颜色)中调整色调和饱和度来确定的。使用16种图案之一(或指定一个),图案元素的尺寸也由哈希值确定。

您可以将生成的图案用作容器的 background-image。使用图案的 base64 表示形式仍然会生成SVG渲染,因此在视网膜显示屏上看起来很棒。

请参阅 GitHub Guides 网站,了解此库能做什么。(GitHub Guides 使用原始的 Ruby 版本)。

安装

在您的根项目中运行此命令

composer require redeyeventures/geopattern

安装(不使用 composer)

从 GitHub 下载或克隆 src 目录。

src 文件夹重命名为 GeoPattern,并将其放置在您的应用程序可以访问的位置。

将此行添加到您的代码中

require_once('path/to/folder/geopattern_loader.php');

然后您可以按照下面的使用说明进行操作。

使用方法

创建一个新的图案

$geopattern = new \RedeyeVentures\GeoPattern\GeoPattern();
$geopattern->setString('Mastering Markdown');

指定基本背景颜色(色调和饱和度根据字符串进行调整)

$geopattern->setBaseColor('#ffcc00');

使用特定的背景颜色(不进行任何色调或饱和度调整)

$geopattern->setColor('#ffcc00');

使用特定的 图案生成器

$geopattern->setGenerator('sine_waves');

获取SVG字符串

$svg = $geopattern->toSVG();

获取Base64编码的字符串

$base64 = $geopattern->toBase64();

获取数据URI

$dataURI = $geopattern->toDataURI(); #data:image/svg+xml;base64,...

获取数据URL

$dataURL = $geopattern->toDataURL(); #url("data:image/svg+xml;base64,...")

您可以使用数据URL字符串来设置背景

<div style="background-image: {$dataURL)"></div>

setStringsetBaseColorsetGenerator 方法是可链的。您还可以向 GeoPattern 构造函数传递包含 stringbaseColorcolor 和/或 generator 值的数组。

如果将 GeoPattern 对象转换为字符串,它将提供 SVG 字符串。

贡献

  1. 分叉它( http://github.com/redeyeventures/geopattern-php/fork
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 提交您的更改(git commit -am 'Add some feature'
  4. 将更改推送到分支(git push origin my-new-feature
  5. 创建新的 Pull Request

原始项目

有关更多信息和其他语言的端口链接,请参阅 https://github.com/jasonlong/geo_pattern

基于 jasonlong/geo_pattern @ ac27b5bb50a8d2061ff63254c915e9ca96a40480。