Warp Image around cylinder

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
odd_duck
Posts: 8
Joined: 2016-02-19T03:28:23-07:00
Authentication code: 1151

Warp Image around cylinder

Post by odd_duck »

I am just starting to learn PHP's Imagick library and I am needing to warp an image around a cyclinder mug - similar to this:

Image

Getting started with Imagick 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:

http://www.imagemagick.org/Usage/mappin ... e_cylinder

Like so:

Code: Select all

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
 
However this just doesn't make much sense to me when i've been using code such as:

Code: Select all

$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);
Can anyone help in how I can achieve this using the second way of coding or if there is a way of converting it across?
I'm completely stuck on this.

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Warp Image around cylinder

Post by snibgo »

Coffee mugs, even simple cylindrical mugs, are quite complex. See my pages on cylinders and coffee mugs:
http://im.snibgo.com/cylinder.htm
http://im.snibgo.com/coffmug.htm

The first page is for non-perspective transformations. The second is for proper 3-D perspective. My scripts are for Windows BAT, which is readily translatable to other shells.

Fred has a bash script: http://www.fmwconcepts.com/imagemagick/ ... /index.php

Sorry, I don't use IMagick or PHP, and can't help you translate to those systems. You can simply create an ImageMagick command, and "exec" it from PHP.
snibgo's IM pages: im.snibgo.com
Post Reply