📜 ⬆️ ⬇️

Photoshop in PHP

Reduce the image with different libraries and compare the result For many tasks of automatic photo processing, the quality and functionality of the GD library is not suitable. Since the opportunity to access Photoshop from PHP or Perl does not yet exist, we solve the problem using ImageMagick .

It will be about the PHP interface to ImageMagick MagickWand , which in the Fedora repository is called php-magickwand . I want to draw your attention to the fact that the MagickWand API differs from the classic ImageMagick in that it allows you to work with both raster graphics elements and vector graphics elements.

For php, there is another interface implementation for ImageMagick , which is called IMagick , but the functionality of this library, in my opinion, will be inferior to MagickWand .
')

In the first article we will look at examples of several typical tasks for image processing and compare the results with php-gd .




Reduce the picture



Reduce the image with this simple code.
$magick_wand=NewMagickWand(); MagickReadImage($magick_wand,'linux_users.jpg'); $mgck_local=MagickTransformImage($magick_wand, NULL,'x100'); MagickStripImage($mgck_local); MagickEchoImageBlob($mgck_local); 


'x100' means 100 vertically, horizontally how much is obtained,
The second parameter is responsible for the image cropping functions; we do not use them in our example. MagickStripImage removes comments, sometimes noticeably reduces the size of small images.

An experienced web designer knows that by greatly reducing the image for the Web,
so that the picture looked more presentable, it adds a bit of sharpness. Parameters of focusing depends on the size of the picture, well, actually from the artistic taste of the designer. Sharpen MagickWand:

  $magick_wand=NewMagickWand(); MagickReadImage($magick_wand,'linux_users.jpg'); $mgck_local=MagickTransformImage($magick_wand, NULL,'x100'); MagickSharpenImage($mgck_local,1,4); MagickStripImage($mgck_local); MagickEchoImageBlob($mgck_local); 



Now compare the results, do the reduction operation with GD, in the default mode and with 100% quality preservation.

There is more material on watermarks and on PhotoShop effects on MagickWand, this is in store for the next article, unless of course this information was interesting for you.
Processing modePicture
GD mode "by default" ( 2 351 b )
Very small size but loss of quality is already noticeable.
GD 100% quality ( 7,847 b )
The quality is good, GD is doing great!
MagickWand "default" ( 9 695 b )
The quality is good, but the size is a bit bigger!
MagickWand + focusing ( 14 508 b )
Here, the picture no doubt looks better than the options offered!

Source: https://habr.com/ru/post/26555/


All Articles