PHP code example of byjg / imageutil

1. Go to this page and download the library: Download byjg/imageutil 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/ */

    

byjg / imageutil example snippets



// From the file system
$img = new ImageUtil('path_to_image.png');

// From an URL
$img2 = new ImageUtil('http://somesite/someimage.jpg');

// From an existing resource image
$resourceImg = imagecreatetruecolor(200, 300);
$img3 = new ImageUtil($resourceImg);

// Or empty image
$img4 = ImageUtil::empty(200, 300, new Color(255, 255, 255));


$img = new ImageUtil('wheel.png');
$img->flip(Flip::Vertical)->resize(120, null)->save('wheel.jpg');


$img = new ImageUtil('wheel.png');
$img->rotate(45);


$img = new ImageUtil('wheel.png');
$img->resize(640, 480);


$img = new ImageUtil('wheel.png');
$img->resizeSquare(200);


$img = new ImageUtil('wheel.png');
$img->resizeAspectRatio(200, 150)


$img = new ImageUtil('wheel.png');
$stamp = new ImageUtil('https://www.mysite.com/logo.png');
$img->stampImage($stamp, StampPosition::BottomRight);


$img = new ImageUtil('wheel.png');
$img->writeText('Sample', 0, 70, 45, 'Arial');


$img = new ImageUtil('wheel.png');
$img->crop(250,200,400,250);


$img = new ImageUtil('wheel.png');
$img->makeTransparent(new Color(255, 255, 255));


$img->restore();


$img->destroy();


$img->save('filename.gif')


// Get the image dimension
$witdh = $img->getWidth();
$height = $img->getHeight();

// Get the image resource
$resource = $img->getImage();