mauris/geopattern

This package is abandoned and no longer maintained. The author suggests using the redeyeventures/geopattern package instead.

Generate beautiful SVG patterns.

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

This is a PHP port of jasonlong/geo_pattern.

Generate beautiful tiling SVG patterns from a string. The string is converted into a SHA and a color and pattern are determined based on the values in the hash. The color is determined by shifting the hue and saturation from a default (or passed in) base color. One of 16 patterns is used (or you can specify one) and the sizing of the pattern elements is also determined by the hash values.

You can use the generated pattern as the background-image for a container. Using the base64 representation of the pattern still results in SVG rendering, so it looks great on retina displays.

See the GitHub Guides site as an example of what this library can do. (GitHub Guides uses the original ruby version).

Installation

Add this line to the require section of your composer.json file:

"redeyeventures/geopattern": "1.2.*"

And then run:

$ composer install

Usage

Make a new pattern:

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

To specify a base background color (with a hue and saturation that adjusts depending on the string):

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

To use a specific background color (w/o any hue or saturation adjustments):

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

To use a specific pattern generator:

$geopattern->setGenerator('sine_waves');

Get the SVG string:

$svg = $geopattern->toSVG();

Get the Base64 encoded string:

$base64 = $geopattern->toBase64();

Get a data URI:

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

Get a data URL:

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

You can use the data URL string to set the background:

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

The setString, setBaseColor, setGenerator methods are chainable. You can also pass an array to the GeoPattern constructor containing the string, baseColor, color, and/or generator values.

If the GeoPattern object is casted as a string, it will provide the SVG string result.

Laravel 4.x

Contributing

GeoPattern provides support for Laravel usage.

Add 'GeoPattern\ServiceProvider', to the list of providers in the app/config/app.php configuration file.

Add 'GeoPattern' => 'GeoPattern\Facades\GeoPattern', in the list of aliases in the app/config/app.php configuration file.

You will then be able to use GeoPattern like this:

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. Fork it ( http://github.com/redeyeventures/geopattern-php/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Original Project

See https://github.com/jasonlong/geo_pattern for more info and links to ports for other languages.

Based on jasonlong/geo_pattern @ ac27b5bb50a8d2061ff63254c915e9ca96a40480.