snobu / php-imagick-webapps

ImageMagick on App Service (Windows)
8 stars 2 forks source link
appservice azure imagemagick imagemagick-wrapper php-imagick windows

WARNING:

The stuff below is now 2+ years old, no clue if anything still works that way. I highly recommend you look at a Docker image instead that has the imagemagick dependencies (via apt install php-imagick or something along these lines).

How to get php_imagick up and running on Azure App Service with Windows web workers

DISCLAIMER:
If this totally and permanently bricks your site, don't blame me.

READ THIS FIRST:

At this point we strongly encourage looking at Web Apps for Containers for ImageMagick based workloads. If for one reason or another you can't use that, read on.

Extension and ImageMagick

Find suitable PHP extension and ImageMagick library dll's from

https://mlocati.github.io/articles/php-windows-imagick.html

UPDATE for PHP 7.4, VC15, x64, Non Thread Safe (NTS)

Tested working:

Follow the PHP 7.0 guide, just match the right binaries.

UPDATE for PHP 7.2, VC15, x64, Non Thread Safe (NTS)

Tested working:

Follow the PHP 7.0 guide, just match the right binaries.

UPDATE for PHP 7.0, VC14, x86, Non Thread Safe (NTS)

This is what you should have now:

image

image

We take a dependency here on ImageMagick-6.9.3-7-Q16-x86-dll.exe. Download and extract (always get the one ending in -x86-dll.exe) - http://ftp.icm.edu.pl/packages/ImageMagick/binaries/ImageMagick-6.9.3-7-Q16-x86-dll.exe (i'm using extract loosely here because you actually have to INSTALL that InstallShield package on your machine to get to the DLLs. InstallShield has no in-place extract. Small price to pay though.)

<?php
  /* Create a new imagick object */
  $im = new Imagick();
  /* Create new image. This will be used as fill pattern */
  $im->newPseudoImage(200, 200, "plasma:fractal");
  /* Create imagickdraw object */
  $draw = new ImagickDraw();
  /* Start a new pattern called "gradient" */
  $draw->pushPattern('gradient', 0, 0, 200, 200);
  /* Composite the gradient on the pattern */
  $draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 200, 200, $im);
  /* Close the pattern */
  $draw->popPattern();
  /* Use the pattern called "gradient" as the fill */
  $draw->setFillPatternURL('#gradient');
  /* Set font size */
  $draw->setFontSize(36);
  /* Annotate some text */
  $draw->annotation(20, 50, "What do you mean this works and we still have daylight left???!!?");
  /* Create a new canvas object and a white image */
  $canvas = new Imagick();
  $canvas->newImage(1200, 70, "black");
  /* Draw the ImagickDraw on to the canvas */
  $canvas->drawImage($draw);
  /* 1px black border around the image */
  $canvas->borderImage('black', 1, 1);
  /* Set the format to PNG */
  $canvas->setImageFormat('png');

  /* Output the image */
  header("Content-Type: image/png");
  echo $canvas;
?>

Result:

image

NOTE: phpinfo() should now report a bunch of formats being supported:

image

For PHP 5.6, VC11, x86, Non Thread Safe

Follow the PHP 7.0 guide, just match the right binaries.

Tested working:

TO DO: