Create beautiful generative background images from a string. Based on jasonlong/geo_pattern

Overview

GeoPattern Build Status

Latest Version Latest unstable Version

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

Run this command in your root project:

composer require redeyeventures/geopattern

Installation (without composer)

Download or clone the src directory from GitHub.

Rename the src folder to GeoPattern and put it somewhere your app can access it from.

Add this line to your code:

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

You can then follow the usage instructions below.

Usage

Make a new pattern:

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

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:

">

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 cast as a string, it will provide the SVG string.

Contributing

  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.

Comments
  • Add option to specify exact color

    Add option to specify exact color

    The baseColor option only specifies a relative color that is then shifted in hue and saturation. This adds a new color option that gets passed straight through without further processing.

    ref: jasonlong/geo_pattern#31

    opened by retlehs 5
  • 1.2.x Update for GeoPattern

    1.2.x Update for GeoPattern

    As discussed in #5, this is the pull request to merge the updates from my fork. The following summarizes the changes made:

    • used GeoPattern as the main namespace
    • removed the geopattern_loader.php loader
    • updated the library to PSR-2 & PSR-4 compliant
    • Added Laravel Service Provider and Facade (library still usable without using Laravel)
    • moved test into the test folder.
      • This means that test needs to be run using the command phpunit -c test instead.
    • removed PHPUnit 3.7 from the require-dev in composer.json. Please use composer global require phpunit/phpunit=4.3.* to get phpunit installed.
    • Added PHP 5.3, 5.4, 5.5, 5.6 for Travis-CI Testing
    • added PHP CS checking in Travis-CI (found in test/phpcs.xml)

    Future Improvements (not in this pull request):

    • Additional tests required. The current test only tests the SVG class, and methods coverage only at a staggering 51.72%.
    • Reduce LOC on GeoPattern class. 1200+ lines of code is horrendous. I saw a lot of repeated code, maybe we can abstract them better.
    opened by mauris 0
  • How to change size or zoom of SVG?

    How to change size or zoom of SVG?

    I would like the pattern to appear larger in the image. I am converting the SVG to a PNG but when increasing the size of SVG with Intervention it loses its quality.

    opened by syclone 0
  • Allow user to get HSL values for generated base colour

    Allow user to get HSL values for generated base colour

    Moves the colour generation into its own function that is public.

    This lets the user (me) get the colour that geo pattern decided to use for the background and use it elsewhere. For my uses I wanted links on the page to match the colour of the pattern for the page title.

    opened by Arcath 1
  • Syntax error after adding first time

    Syntax error after adding first time

    Hi,

    Thanks for your efforts, it looks awesome!

    I added the library without composer exactly as mentioned in readme. Hovewer i got this error, here is the stack:

    Parse error: syntax error, unexpected '[' in /lib/GeoPattern/GeoPattern/SVGElements/Circle.php on line 9 Call Stack: 0.0016 802496 1. {main}() /www/store/mustafa/index.php:0 0.0017 803008 2. require_once('/lib/GeoPattern/geopattern_loader.php')

    Do you think it is my fault or a bug?

    opened by diki 6
Releases(v1.1.2)
Owner
Redeye Group
We build cool stuff.
Redeye Group
Create images with embedded text using advanced typography

Image with Text This class makes it super easy to render images with multiple, independently styled text blocks. You can control each text block's ali

New Media Campaigns 144 Sep 7, 2022
ImageWorkshop is a PHP5.3+ library that helps you to manage images based on GD library

================================ ImageWorkshop class ================================ Summary and features Really flexible and easy-to-use PHP class t

Clément Guillemain 853 Dec 27, 2022
GifCreator is a PHP class that creates animated GIF from multiple images

================================ GifCreator ================================ GifCreator is a PHP class to create animated GIF from multiple images For

Clément Guillemain 320 Dec 15, 2022
Easily convert images with Glide

Easily convert images with Glide This package provides an easy to use class to manipulate images. Under the hood it leverages Glide to perform the man

Spatie 374 Dec 30, 2022
A PHP GD + TwitterOAuth demo to dynamically generate Twitter header images and upload them via the API.

A PHP GD + TwitterOAuth demo to dynamically generate Twitter header images and upload them via the API. This enables you to build cool little tricks, like showing your latest followers or sponsors, latest content creted, a qrcode to something, a progress bar for some goal, and whathever you can think of.

Erika Heidi 172 Jan 5, 2023
Optimize your images on the fly with Glide for Laravel.

Glide for Laravel Optimize your images on the fly with Glide for Laravel. Support us Like our work? You can support us by purchasing one of our produc

Flowframe 53 Oct 17, 2022
Upload SVG images in Magento 2.x

Upload SVG images in Magento 2.x This extension for Magento 2 allows uploading SVG images in the following sections: wysiwyg editor in static blocks a

Magegadgets 6 Dec 23, 2022
PHP library to resize, scale and crop images.

PHP library to resize, scale and crop images.

Gumlet 1.1k Jan 3, 2023
Inline Images Protocol implementation for PHP.

Imgecho Echo the image on iTerm App using Inline Images Protocol. Installation Use Composer to install. composer require mileschou/imgecho Usage Use

MilesChou 4 May 30, 2022
The Tinify API allows you to compress and optimize WebP, JPEG and PNG images.

The Tinify API allows you to compress and optimize WebP, JPEG and PNG images. It is designed as a REST service. The client libraries in various languages make it very easy to interact with the Tinify API.

Devscast 10 May 13, 2022
The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API

Gregwar's Image class The Gregwar\Image class purpose is to provide a simple object-oriented images handling and caching API. Installation With compos

Grégoire Passault 958 Dec 29, 2022
Simple, fast and secure archive for images

Slim Image Archive Simple*, fast and secure archive for images: Create multiple categories with multiple albums with multiple images! Manage multiple

KS 24 Oct 23, 2021
The image server plugin allows you to add responsive images via config without extra elements

Grav image server plugin adds picture tag with loading, responsive, high density images

catchIT 7 Dec 30, 2022
Contao extension to provide the possibility of defining alternative images to be used on different output devices.

Contao Image Alternatives This extensions expands the capabilities of using responsive images with art direction in Contao. You will have the possibil

inspiredminds 6 May 30, 2022
Laravel Favicon - Create dynamic favicons based on your environment settings.

Laravel Favicon Create dynamic favicons based on your environment settings. Laravel Package Development If you want to learn how to create reusable PH

Beyond Code 320 Dec 12, 2022
Create material deisgn avatars for users just like Google Messager. It may not be unique but looks better than Identicon or Gravatar.

Material-Design-Avatars Create material deisgn avatars for users just like Google Messager. It may not be unique but looks better than Identicon or Gr

Canbin Lin 268 Sep 14, 2022
Wonderfully easy on-demand image manipulation library with an HTTP based API.

Glide Glide is a wonderfully easy on-demand image manipulation library written in PHP. Its straightforward API is exposed via HTTP, similar to cloud i

The League of Extraordinary Packages 2.4k Dec 19, 2022
Another web based photo gallery

Phyxo Simply share your images. Requirements This project use severals librairies that need at least PHP 7.3.0 This project uses a database and suppor

Nicolas 16 Oct 13, 2022
php-gd based image templates

gdaisy A highly experimental image templating system based on PHP-GD to dynamically generate image banners and covers. Installation 1. Require erikahe

Erika Heidi 67 Nov 22, 2022