Skip to content

chaoszcat/imagickbutton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Imagick Button

A beautifully PHP rendered button using Imagick extension.

Why

In the email world, creating beautiful buttons is always a pain in the a**. To overcome this, email templates usually uses css buttons with image fallback. This is fine if your template is fixed and with not much variations. But what if you are a developer that need to generate dynamic buttons?

GD/Imagick

That's why I created this script for those who wanted to create dynamic yet beautiful buttons in PHP. The only hard requirement here is Imagick extension. GD is too tedious to do such task. Fret not, two lines and you are done.

Requirements

PHP 5.3 and Imagick extension installed. Installation steps is out of scope here. Google it, should have a lot of resources.

Examples

Orange (Glossy)
ScreenShot

Orange (Matte)
ScreenShot

Blue
ScreenShot

Green
ScreenShot

Quick Start

  • Get the Button.php class file

  • Include the Button.php in your script

      include 'Button.php';
      $button = new Button();
      $button->draw();
    
  • That's it!

Configurations

These are the default properties in the Button class.

private $properties = array(
	'width' => 140,
	'height' => 40,
	'buttonColor' => '#ff6600',     //Button face color
	'fontColor' => '#ffffff',
	'fontSize' => 18,
	'font' => 'arial.ttf',          //font use. Drop your font into the font folder
	'text' => 'Hello World',
	'noText' => false,
	'backgroundColor' => '#ffffff', //Background color. We do not support transparency here
	'corner' => 8,
	'glossy' => true,
	
	/**
	 * Image type. GIF genenerally produces smaller file.
	 * Supported gif/png.
	 */
	'imageType' => 'gif',
	
	/**
	 * Unless specified, these values will be automatically
	 * calculated based on buttonColor
	 */
	'startColor' => null,
	'endColor' => null,
	'strokeColor' => null
);

To set it, simply call the respective properties as a method. For example, a blue button with a customized text:

$button->buttonColor('#36a')
       ->text('Click Here')
       ->draw();

A orange (Default color) button with no glossy effect

$button->glossy(0)
       ->text('Click Here')
       ->draw();

To read $_GET automatically, use readGET. Pass an array of whitelisted $_GET keys in array, or CSV string

$button->readGET(array('width', 'height', 'buttonColor', 'fontColor'))
       ->draw();

To draw into a file instead, call this

$button->draw('path/to/the/file');

About

A beautiful Imagick rendered button for PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages