Introduction to Imagick in PHP

In this article we see what it is, where it comes from and how we can use this native PHP extension.

Imagick is a native PHP extension for creating and modifying images using the ImageMagic API.

Before continuing, I think it is necessary to know a little about this API that makes Imagick work.

ImageMagic is software for creating, editing, and compositing bitmap images. It allows you to read, convert and write images in a wide variety of formats. From PNG, JPEG or GIF to PDF, PhotoCD and so on to more than a hundred formats.

Now that we know what ImageMagic is, we are going to see what we need to be able to work with Imagick.

Requirements and installation

Depending on the operating system that we have installed on our server or computer, we have a series of binaries and requirements.

If we are going to install it on Windows, we only have to download the binaries that we can find in . Also, it does not require a compiler for its installation.

If, on the contrary, we are going to install it on a web server with Linux, at least we have to know that it has to have PHP >=5,1,3 and ImageMagick >= 6,2,4 installed. In addition, for its installation you must have the PECL extension installed. If you don’t know how to do it, you can consult the official PHP documentation about the . Finally, you have to install one of the packages shown at the following URL:

Once we have everything installed, we can start working with images in PHP thanks to Imagick.

See also  Crop and resize an image with Photoshop

predefined constants

There are a number of predefined constants that we can use in our codes. There are quite a few, so we are going to mention some of the most used and at the end we will give the link where to find the entire list.

Constants COLOR_*

They are those that help us to work with the most used colors, such as black, blue, red, etc. Its syntax is the following:

  • COLOR_BLACK
  • COLOR_RED
  • …etc.

DISPOSE Constants

They are those that give us information about the arrangement of the images. Some examples are:

  • DISPOSE_UNDEFINED: Undefined disposition type
  • DISPOSE_BACKGROUND: Background layout
  • DISPOSE_PREVIOUS: Previous disposition

Composition Operator Constants

They are all that help us compose our images. They are the longest list, so we will only put a few.

  • COMPOSITE_CLEAR: Makes the target image transparent
  • COMPOSITE_COLORDODGE: Brightens the target image to reflect the source image
  • COMPOSITE_SRC: Source is copied to destination

MONTAGEMODE Constants

They are used to define the mounting mode.

  • MONTAGEMODE_FRAME
  • MONTAGEMODE_UNFRAME
  • MONTAGEMODE_CONCATENATE

STYLE constants

Are the constants related to the style

  • STYLE_NORMAL
  • STYLE_ITALIC
  • STYLE_OBLIQUE
  • STYLE_ANY

… And so on with a fairly extensive list that you can

conclusion

As you can see, its implementation is simple and gives us a very wide range of possibilities when working with images in PHP. That is why I think it is important to start working with this extension and get the most out of it.

In the following article we will see how to do some

Loading Facebook Comments ...
Loading Disqus Comments ...