1. Go to this page and download the library: Download easygithdev/easygd 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/ */
<img src=" echo (new Image())->load($stream)->src()
(new Image())->load($stream)->save('php.png');
(new Image())->load($stream)->save('php.png')->show();
(new Image())->load($stream)->save('php.png')
->setType(IMAGETYPE_GIF)->save('php.gif')
->setType(IMAGETYPE_JPEG)->save('php.jpg');
$dimension = (new Dimension())->create(300, 300);
// Create a color with hexadecimal code
$color = (new Color())->create('#83d01e');
// OR create a color from a preset
$color = (new Color())->create(Color::Yellow);
// OR create a preseted color
$color = Color::Yellow();
$position = (new Position())->create(200, 125);
$text = (new Text())->create('Hello World');
(new Image())->create($dimension, $color)->show();
(new Image)->create((new Dimension)->create(300, 300), Color::Blue())
->addText(
(new Text())->create('Hello World')
->setColor(Color::Silver())
->setSize(3)
->setPosition((new Position)->create(200, 125))
)->show();
(new Image())->create((new Dimension())->create(200, 200))->addText(
(new Text())->create('gd library')
->setSize(5)
->setColor(Color::White())
->setDrawtype(Text::TEXT_DRAW_VERTICAL)
->setPosition((new Position())->create(40, 100))
)->show();
(new Image)->create((new Dimension())->create(300, 300), Color::White())->addText(
(new Text())->create('Alpha Color')
->setColor(
(new Color())->create('#FF0000')->setAlpha(95)
)
->setSize(5)
->setPosition((new Position())->create(55, 35))
)
->show();
(new Image())->load($stream)->setType(IMG_JPEG)->save('iptc.jpg');
$fileSrc = __DIR__ . '/iptc.jpg';
$fileDst = __DIR__ . '/iptc2.jpg';
$iptc = (new Iptc())->create($fileSrc, null);
$iptc->addTag(Iptc::IPTC_CITY, 'CHEVERNY')
->addTag(Iptc::IPTC_COUNTRY, 'FRANCE')
->addTag(Iptc::IPTC_CREATED_DATE, '2012-03-01')
->addTag(Iptc::IPTC_CATEGORY, 'JOURNEY');
if ($iptc->write($fileDst) === false) {
throw new Exception('Error to write IPTC');
}
echo '<pre>', (new Image())->load($fileDst)->getInfos(), '</pre>';
(new Image)->load($stream)
->resizeByPercent(0.5)
->show();
(new Image)->load($stream)
->resizeByWidth(50)
->show();
(new Image)->load($stream)
->resizeByHeight(30)
->show();
(new Image)->load($stream)
->resizeAuto((new Dimension())->create(300, 200))
->show();
(new Image)->load($stream)
->thumbnail(140, Color::Silver())
->show();
(new Image)->load($stream)
->crop((new Position)->create(20, 13), (new Dimension())->create(80, 40))
->show();
(new Image)->load($stream)
->rotate(90)
->show();
$logo = (new Image)->load('http://www.php.net/images/logos/php-med-trans-light.gif')
->resizeByPercent(0.6);
(new Image)->load('http://static.php.net/www.php.net/images/logos/php-med-trans.png')
->inlay($logo, (new Position)->create(30, 20), 100)
->show();
$text = (new Text)->create('Copyright (C) 2020 Your Name')
->setFontType(Text::TEXT_FONT_TRUETYPE)
->setFontfile(Text::TEXT_UNIX_FONT_PATH . '/truetype/dejavu/DejaVuSans.ttf')
->setSize(5)
->setColor(Color::White())
->setPosition((new Position())->create(40, 190));
$path = __DIR__ . '/images/original/';
foreach (new ImageFilterIterator(new DirectoryIterator($path)) as $file) {
if (($image = (new Image)->load($file->getPathname())) === false) {
continue;
}
$thumb1 = $image->thumbnail(100)->src();
$thumb2 = $image->thumbnail(200)->addText($text)->src();
$thumb3 = $image->thumbnail(400)->src();