1

I am just starting to learn PHP's Imagick library and I am needing to warp an image around a cyclinder. I have been using the following examples:

http://www.phpimagick.com/Imagick/rotateImage

To successfully rotate/scale/extent etc. the image but cannot see how I can wrap it round a cylinder.

I can see there is a way of doing so with Cylindrical Displacement in the docs:

convert rose: -background black -gravity south -splice 0x8 \
      \( +clone -sparse-color barycentric '0,0 black 69,0 white' \) \
      \( +clone -function arcsin 0.5 \) \
      \( -clone 1 -level 25%,75% \
             -function polynomial -4,4,0 -gamma 2 \
             +level 50%,0 \) \
      -delete 1 -swap 0,1  miff:- |\
 composite - -virtual-pixel black  -displace 17x7  rose_cylinder.png

This just doesn't make much sense to me when I've been using code such as:

$img = new Imagick($the_img_path);
// to resize
$img->resizeImage($_w, $_h, imagick::FILTER_LANCZOS, 1, false);
// to crop
$img->cropImage($crop_w, $crop_h, $crop_x, $crop_y);
double-beep
  • 5,031
  • 17
  • 33
  • 41
odd_duck
  • 3,941
  • 7
  • 43
  • 85

1 Answers1

0

PHP Imagick provides mostly all functions from console util. You have just to find appropriate analogs from function list:

http://php.net/manual/en/book.imagick.php

So for sparse you have to use Imagick::sparseColorImage. To apply a function: Imagick::functionImage. And so on.

You code will be similar to:

$original = new Imagick('rose');
$original->setBackgroundColor('black');
$original->setGravity('south')
$original->spliceImage(...);

$clone = clone $original;
$clone->functionImage(...);

...
Ostin
  • 1,511
  • 1
  • 12
  • 25
  • So do i place `convert rose: -back....` inside functionImage() so it would be: `$img->functionImage(convert rose: -back....);`? – odd_duck Jan 25 '16 at 15:41
  • Nope. Every argument in example command is a operation that would be performed with a source image: -background black // setBackground -gravity south // setGravity Then you have operations grouped in brackets. Each group stars with clone so it operates copied source – Ostin Jan 26 '16 at 12:24