PHP code example of dantsu / php-image-editor
1. Go to this page and download the library: Download dantsu/php-image-editor library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dantsu / php-image-editor example snippets
use \DantSu\PHPImageEditor\Image;
\header('Content-type: image/png');
$image = Image::newCanvas(500, 500)
->drawRectangle(0, 0, 500, 500, '#444')
->drawRectangle(0, 350, 500, 500, '#FF8800')
->writeText('I got the power !', __DIR__ . '/resources/font.ttf', 40, '#FFFFFF', Image::ALIGN_CENTER, 310)
->drawCircle(25, 100, 100, '#FF8800')
->drawCircle(25, 100, 95, '#000000FF')
->drawCircle(475, 100, 100, '#FF8800')
->drawCircle(475, 100, 95, '#000000FF');
for($i = 0; $i <= 360; $i+=30) {
$image
->drawArrowWithAngle(250, 200, $i, 80, 2, '#FF8800')
->drawArrowWithAngle(250, 200, ($i + 15), 50, 2, '#FF8800');
}
$image
->crop(450, 300, Image::ALIGN_CENTER, Image::ALIGN_MIDDLE)
->displayPNG();
use \DantSu\PHPImageEditor\Image;
Image::fromPath(__DIR__ . '/resources/photo.jpg')
->downscaleAndCrop(1920, 1080, Image::ALIGN_CENTER, Image::ALIGN_BOTTOM)
->pasteOn(
Image::fromPath(__DIR__ . '/resources/watermark.png')->downscaleProportion(300, 300),
Image::ALIGN_RIGHT,
Image::ALIGN_TOP
)
->saveJPG(__DIR__ . '/my-image.jpg', 70);
cmd
composer