HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelDevelopmentTutorial Source codeReport an issue
Category
Example

Screen embed

← svgExample   imageGeometryReset →
The Imagick::distortImage function can be used to do the appropriate perspective to take an image, and make it look like it is on a screen in a different image.

Example

function screenEmbed()
{
    $overlay = new \Imagick(realpath("images/dickbutt.jpg"));
    $imagick = new \Imagick(realpath("images/Screeny.png"));

    $overlay->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);

    $width = $overlay->getImageWidth();
    $height = $overlay->getImageHeight();

    $offset = 332.9;

    $points = array(
        0, 0, 364 - $offset, 51,
        $width, 0, 473.4 - $offset, 23,
        0, $height, 433.5 - $offset, 182,
        $width, $height, 523 - $offset, 119.4
    );

    $overlay->modulateImage(97, 100, 0);
    $overlay->distortImage(\Imagick::DISTORTION_PERSPECTIVE, $points, true);

    $imagick->compositeImage($overlay, \Imagick::COMPOSITE_OVER, 364.5 - $offset, 23.5);

    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}