2017 © Pedro Peláez
 

library imagemagick-php

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

image

orbitale/imagemagick-php

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  • Friday, February 9, 2018
  • by Pierstoval
  • Repository
  • 1 Watchers
  • 8 Stars
  • 9,035 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 15 Versions
  • 26 % Grown

The README.md

ImageMagickPHP

An ImageMagick "exec" component for PHP apps., (*1)

Installation

Install with Composer, it's the best packages manager you can have :, (*2)

composer require orbitale/imagemagick-php

Requirements

  • PHP 7.2 or higher
  • ImageMagick 7 has to be installed on your server, and the binaries must be executable by the user running the PHP process.

Settings

There are not many settings, but when you instantiate a new Command object, you may specify ImageMagick's executable directory directly in the constructor, for example :, (*3)

use Orbitale\Component\ImageMagick\Command;

// Default directory for many Linux distributions
$command = new Command('/usr/bin/magick');

// Or in Windows, depending of the install directory
$command = new Command('C:\ImageMagick\magick.exe');

// Will try to automatically discover the path of ImageMagick in your system
// Note: it uses Symfony's ExecutableFinder to find it in $PATH
$command = new Command();

The constructor will automatically search for the magick executable, test it, and throw an exception if it's not available., (*4)

⚠️ Make sure your ImageMagick binary is executable., (*5)

Usage

First, we recommend you to note all possible scripts that you can use with ImageMagick in the official docs:, (*6)

These correspond to the "legacy binaries", and you can use them if you are familiar or comfortable with them., (*7)

As of ImageMagick 7, these are not mandatory, but this package is compatible with them., (*8)

Read the comments :, (*9)

require_once 'vendor/autoload.php';

use Orbitale\Component\ImageMagick\Command;

// Create a new command
$command = new Command();

$response = $command
    // The command will search for the "logo.png" file. If it does not exist, it will throw an exception.
    // If it does, it will create a new command with this source image.
    ->convert('logo.png')

    // The "output()" method will append "logo.gif" at the end of the command-line instruction as a filename.
    // This way, we can continue writing our command without appending "logo.gif" ourselves.
    ->output('logo.gif')

    // At this time, the command shall look like this :
    // $ "{ImageMagickPath}convert" "logo.png" "logo.gif"

    // Then we run the command by using "exec()" to get the CommandResponse
    ->run()
;

// Check if the command failed and get the error if needed
if ($response->hasFailed()) {
    throw new Exception('An error occurred:'.$response->getError());
} else {
    // If it has not failed, then we simply send it to the buffer
    header('Content-type: image/gif');
    echo file_get_contents('logo.gif');
}

Resizing an image

require_once 'vendor/autoload.php';

use Orbitale\Component\ImageMagick\Command;

// Create a new command
$command = new Command();

$response = $command

    ->convert('background.jpeg')

    // We'll use the same output as the input, therefore will overwrite the source file after resizing it.
    ->output('background.jpeg')

    // The "resize" method allows you to add a "Geometry" operation.
    // It must fit to the "Geometry" parameters in the ImageMagick official documentation (see links below & phpdoc)
    ->resize('50x50')

    ->run()
;

// Check if the command failed and get the error if needed
if ($response->hasFailed()) {
    throw new Exception('An error occurred:'.$response->getError());
} else {
    // If it has not failed, then we simply send it to the buffer
    header('Content-type: image/gif');
    echo file_get_contents('logo.gif');
}

Currently supported options:

There are a lot of command-line options, and each have its own validation system., (*10)

This is why a "few" ones are implemented now, to make sure validation is possible for each of them., (*11)

Note: If an option is not implemented in the Command class, you can create an issue or make a Pull Request that implements the new option!, (*12)

Feel free to ask/create an issue if you need more!, (*13)

Some aliases that do magic for you:

  • $command->text(): This method uses multiple options added to the -annotate one to generate a text block. You must specify its position and size, but you can specify color and the font file used., (*14)

  • $command->ellipse(): (check source code for the heavy prototype!) This method uses the -stroke, -fill and -draw options to create an ellipse/circle/disc on your picture. Note: I recommend to check both the source code and the documentation to be sure of what you are doing., (*15)

Useful links

The Versions

09/02 2018

dev-master

9999999-dev https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

09/02 2018

v2.0.1

2.0.1.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

19/01 2018

v2.0.0

2.0.0.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

19/01 2018

1.x-dev

1.9999999.9999999.9999999-dev https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

19/01 2018

v1.6.1

1.6.1.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

10/02 2017

v1.6.0

1.6.0.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

02/02 2017

v1.5.0

1.5.0.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

31/01 2017

v1.4.2

1.4.2.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

converter image gd imagick imagemagick

09/06 2016

dev-im7

dev-im7 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

converter image gd imagick imagemagick

15/04 2016

v1.4.1

1.4.1.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

converter image gd imagick imagemagick

08/03 2016

v1.4.0

1.4.0.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

converter image gd imagick imagemagick

03/09 2015

v1.3.0

1.3.0.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

converter image gd imagick imagemagick

07/04 2015

v1.2.0

1.2.0.0 https://github.com/Orbitale/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

03/03 2015

v1.1.0

1.1.0.0 https://github.com/Pierstoval/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick

26/02 2015

v1.0.0

1.0.0.0 https://github.com/Pierstoval/ImageMagickPHP

A system that allows creating commands to send to the exec() function to use ImageMagick's powerful features.

  Sources   Download

MIT

The Requires

 

The Development Requires

converter image gd imagick imagemagick