Skip to content
forked from kus/php-image

Wrapper for PHP's GD Library for easy image manipulation

Notifications You must be signed in to change notification settings

danyal14/php-image

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP Image

What does it do?

Wrapper for PHP's GD Library for easy image manipulation to resize, crop and draw images on top of each other preserving transparency, writing text with stroke and transparency and drawing shapes.

Installation

Place the PHP file on your server and include it in your script or download via composer require: "kus/php-image": "dev-master".

Usage

Example

	$bg = './img/benji.jpg';
	$overlay = './img/paw.png';
	$image = new PHPImage();
	$image->setDimensionsFromImage($bg);
	$image->draw($bg);
	$image->draw($overlay, '50%', '75%');
	$image->rectangle(40, 40, 120, 80, array(0, 0, 0), 0.5);
	$image->setFont('./font/arial.ttf');
	$image->setTextColor(array(255, 255, 255));
	$image->setStrokeWidth(1);
	$image->setStrokeColor(array(0, 0, 0));
	$image->text('Hello World!', array('fontSize' => 12, 'x' => 50, 'y' => 50));
	$image->text('This is a big sentence with width 200px', array(
		'fontSize' => 60, // Desired starting font size
		'x' => 300,
		'y' => 0,
		'width' => 200,
		'height' => 50,
		'alignHorizontal' => 'center',
		'alignVertical' => 'center',
		'debug' => true
	));
	$image->text('This is a big sentence', array(
		'fontSize' => 60, // Desired starting font size
		'x' => 300,
		'y' => 200,
		'width' => 200,
		'height' => 50,
		'alignHorizontal' => 'center',
		'alignVertical' => 'center',
		'debug' => true
	));
	$image->textBox('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', array('width' => 100, 'fontSize' => 8, 'x' => 50, 'y' => 70));
	$image->rectangle(40, 140, 170, 160, array(0, 0, 0), 0.5);
	$image->textBox('Auto wrap and scale font size to multiline text box width and height bounds. Vestibulum venenatis risus scelerisque enim faucibus, ac pretium massa condimentum. Curabitur faucibus mi at convallis viverra. Integer nec finibus ligula, id hendrerit felis.', array(
		'width' => 150,
		'height' => 140,
		'fontSize' => 16, // Desired starting font size
		'x' => 50,
		'y' => 150
	));
	$image->show();

Overlay and text

Chainable

	(new PHPImage('./img/benji.jpg'))->resize(200, 200, 'C', true)->show();

Batch resize with optional crop and upscale

	$image = new PHPImage('./img/benji.jpg');
	$image->batchResize('examples/thumb_%dx%d.jpg', array(
		array(400, 400, true, true),
		array(200, 400, true, true),
		array(400, 200, true, true),
		array(100, 100, true, true),
	));
	$image->resize(100, 100, true, true)->show();

400x400 400x200 200x400 100x100

Multiline text box with auto wrap and auto font scale to fit bounds

	$image = new PHPImage(400, 400);
	$image->rectangle(0, 0, 100, 200, array(0, 0, 0), 0.5);
	$image->setFont('./font/arial.ttf');
	$image->setTextColor(array(255, 255, 255));
	$image->setStrokeWidth(1);
	$image->setStrokeColor(array(0, 0, 0));
	$image->textBox('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam molestie tortor quam, at congue nibh imperdiet dapibus.', array(
		'width' => 100,
		'height' => 100,
		'fontSize' => 16, // Desired starting font size
		'x' => 50,
		'y' => 200
	));
	$image->show();

Multiline auto fit text

Text box auto fit text (variable font size)

	$image = new PHPImage(400, 400);
    $image->setFont('./font/arial.ttf');
    $image->setTextColor(array(255, 255, 255));
    $image->text('This is a big sentence', array(
		'fontSize' => 60, // Desired starting font size
		'x' => 0,
		'y' => 0,
		'width' => 400,
		'height' => 200,
		'alignHorizontal' => 'center',
		'alignVertical' => 'center',
		'debug' => true
	));
	$image->text('BIG', array(
		'fontSize' => 120, // Desired starting font size
		'x' => 0,
		'y' => 200,
		'width' => 400,
		'height' => 200,
		'alignHorizontal' => 'center',
		'alignVertical' => 'center',
		'debug' => true
	));
    $image->show();

Copyright

Copyright (c) 2015 Blake Kus blakek.us

This plugin is dual licenced under MIT and GPL Version 2 licences.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Wrapper for PHP's GD Library for easy image manipulation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%