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.
Place the PHP file on your server and include it in your script or download via composer require: "kus/php-image": "dev-master"
.
$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();
(new PHPImage('./img/benji.jpg'))->resize(200, 200, 'C', true)->show();
$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();
$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();
$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 (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.