mauris/geopattern

此包已被弃用且不再维护。作者建议使用redeyeventures/geopattern包。

生成美丽的SVG图案。

1.0.3 2014-04-18 07:49 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:34:20 UTC


README

这是jasonlong/geo_pattern的PHP端口。

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

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

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

安装

将此行添加到您的composer.json文件的require部分

"redeyeventures/geopattern": "1.2.*"

然后运行

$ composer install

使用

创建新的图案

$geopattern = new GeoPattern\GeoPattern();
$geopattern->setString('Make me a SVGandiwch now.');

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

$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字符串结果。

Laravel 4.x

贡献

GeoPattern提供了对Laravel使用的支持。

'GeoPattern\ServiceProvider',添加到app/config/app.php配置文件中providers列表。

app/config/app.php配置文件中aliases列表中添加'GeoPattern' => 'GeoPattern\Facades\GeoPattern',

然后您将能够像这样使用GeoPattern

GeoPattern::setString('Make me a SVGandiwch now.');
GeoPattern::setBaseColor('#FFCC00');

$response = Response::make(GeoPattern::toSVG(), 200);
$response->header(
    'content-type',
    'image/svg+xml'
);
return $response;
  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。