A wrapper collection for GD library in PHP. Defines a set of methods for flip, crop, resize, stamp and others easily.
composer require "byjg/imageutil"
<?php
// 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));
Mirrors the given image in the desired way.i
<?php
$img = new ImageUtil('wheel.png');
$img->flip(Flip::Vertical)->resize(120, null)->save('wheel.jpg');
Rotates the image to any direction using the given angle.
<?php
$img = new ImageUtil('wheel.png');
$img->rotate(45);
Resize the image to an new size. Size can be specified in the arguments.
<?php
$img = new ImageUtil('wheel.png');
$img->resize(640, 480);
Resize the image into a square format and maintain the aspect ratio. The spaces left are filled with the RGB color provided.
<?php
$img = new ImageUtil('wheel.png');
$img->resizeSquare(200);
Resize the image but the aspect ratio is respected. The spaces left are filled with the RGB color provided.
<?php
$img = new ImageUtil('wheel.png');
$img->resizeAspectRatio(200, 150)
Stamp an image in the current image.
<?php
$img = new ImageUtil('wheel.png');
$stamp = new ImageUtil('https://www.mysite.com/logo.png');
$img->stampImage($stamp, StampPosition::BottomRight);
Writes a text on the image.
<?php
$img = new ImageUtil('wheel.png');
$img->writeText('Sample', 0, 70, 45, 'Arial');
Crops the given image from the ($from_x,$from_y) point to the ($to_x,$to_y) point.
<?php
$img = new ImageUtil('wheel.png');
$img->crop(250,200,400,250);
Make the image transparent. The transparent color must be provided.
<?php
$img = new ImageUtil('wheel.png');
$img->makeTransparent(new Color(255, 255, 255));
<?php
$img->restore();
<?php
$img->destroy();
<?php
$img->save('filename.gif')
<?php
// Get the image dimension
$witdh = $img->getWidth();
$height = $img->getHeight();
// Get the image resource
$resource = $img->getImage();
flowchart TD
byjg/imageutil --> ext-gd