Giter Site home page Giter Site logo

dantsu / php-image-editor Goto Github PK

View Code? Open in Web Editor NEW
31.0 1.0 8.0 572 KB

PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options !

License: MIT License

PHP 100.00%
php php7 php-library image image-editor image-editing gd composer composer-package composer-library image-manipulation

php-image-editor's Introduction

Packagist Latest Stable Version GitHub license

PHP Image Editor

PHP library to easily edit image with GD extension. Resize, crop, merge, draw, and many more options !

✨ Supporting

⭐ Star this repository to support this project. You will contribute to increase the visibility of this library 🙂

Installation

Install this library easily with composer :

composer require dantsu/php-image-editor

How to use

Example 1

Create a empty image, draw on it and display it :

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();

Sample 1

Example 2

Apply a watermark on a photo and save it :

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);

Sample 2

Documentation

See DantSu\PHPImageEditor\Image documentation class for more details.

Contributing

Please fork this repository and contribute back using pull requests.

Any contributions, large or small, major features, bug fixes, are welcomed and appreciated but will be thoroughly reviewed.

php-image-editor's People

Contributors

dantsu avatar daurensky avatar davetha avatar roelofjan-elsinga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

php-image-editor's Issues

I am having trouble installing this with composer

I am getting these exceptions while installing them

Package dantsu/php-image-editor has requirements incompatible with your PHP version, PHP extensions and Composer version:

  • dantsu/php-image-editor 1.0.3 requires php ^7.0 which does not match your installed version 8.1.4.
  • dantsu/php-image-editor 1.0.3 requires ext-gd * but it is not present.

Help how can I solve these

Text does not wrap

Hello. Is it possible to somehow wrap the text if it does not fit within the width of the image?

I try to do so:

      $image = Image::newCanvas(640, 1000)
            ->writeText('Extra large text Extra large text', public_path('fonts/app/ANTQUAB.TTF'), 40, '#FFFFFF', Image::ALIGN_CENTER, Image::ALIGN_MIDDLE)
            ->saveJPG(public_path('default_poster.jpg', 90);

And I get an image in which the text does not fit in the picture. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.