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.
$im->setImageVirtualPixelMethod(imagick::BACKGROUND);
or
$im->setImageVirtualPixelMethod(imagick::TRANSPARENT);
I looked at http://us2.php.net/imagick but it did not give the actual method options. Where did you see that it should be VIRTUALPIXELMETHOD_BACKGROUND or VIRTUALPIXELMETHOD_TRANSPARENT
"The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime."
So perhaps all the constants are not loaded in your version or by your host?
You could try getImageVirtualPixelMethod and see what integer is returned, then try some other integers with set... and see what you get as a result or by using get...
echo imagick::VIRTUALPIXELMETHOD_TRANSPARENT;
echo $im->getImageVirtualPixelMethod(); // outputs 8
$im->setImageVirtualPixelMethod(imagick::VIRTUALPIXELMETHOD_TRANSPARENT); // sets the VP to what I want (8 in theory)
echo $im->getImageVirtualPixelMethod(); // does not output 8. instead, it outputs 0, or imagick::VIRTUALPIXELMETHOD_UNDEFINED, which I assume points to the default imagick::VIRTUALPIXELMETHOD_EDGE
So, as you see, the first line successfully echos 8 (the integer for the imagick::VIRTUALPIXELMETHOD_TRANSPARENT constant). I then set the VirtualPixelMethod to that same constant, but when I echo getImageVirtualPixelMethod() again, it doesn't echo that constant. This, to me, says something is wrong with the setImageVirtualPixelMethod() method. :\
NOTE to be able to use a Transparent VP the image should have alpha channel enabled.
This is not done automatically. Most operators don't.
Only a couple of composition methods (CopyOpacity, and ChangeMask), and GIF animation methods do ensure an alpha channel is present and enabled as transparency is inherent in the operator.
Distort does not enable transparency as that comes from the use of other settings, that may or may not effect the outcome of the operation. That is Distort does not know anything about virtual pixel handling.
The EWA resampling underneath distort, does know a little about VP, as part of some optimizations involving 'viewing distant horizons'. But for normal resampling even it does not deal with VP.
Virtual Pixel handling is actually done at an even lower level pixel lookup. I myself have added some VP handling methods (For example 'Checkerboard').
WARNING: do not rely on the actual 'number' used for the VP setting as being constant for all versions of IM. That number is not likely to change often, but may change if a new VP setting is added.
Some means of PHP constant export should be provided, and the PHP Magick API should be rebuilt if a newer version of IM is installed.