1--TEST--
2Test Tutorial, edgeExtend
3--SKIPIF--
4<?php
5$imageMagickRequiredVersion=0x675;
6require_once(dirname(__FILE__) . '/skipif.inc');
7?>
8--FILE--
9<?php
10
11$virtualPixelType = 5;
12
13function edgeExtend($virtualPixelType) {
14    $imagick = new \Imagick();
15    $imagick->newPseudoImage(640, 480, "magick:logo");
16    $imagick->setImageVirtualPixelMethod($virtualPixelType);
17
18    $imagick->scaleimage(400, 300, true);
19
20    $imagick->setbackgroundcolor('pink');
21
22    $desiredWidth = 600;
23    $originalWidth = $imagick->getImageWidth();
24
25    //Make the image be the desired width.
26    $imagick->sampleimage($desiredWidth, $imagick->getImageHeight());
27
28    //Now scale, rotate, translate (aka affine project) it
29    //to be how you want
30    $points = array(//The x scaling factor is 0.5 when the desired width is double
31        //the source width
32        ($originalWidth / $desiredWidth), 0, //Don't scale vertically
33        0, 1, //Offset the image so that it's in the centre
34        ($desiredWidth - $originalWidth) / 2, 0);
35
36    $imagick->distortImage(\Imagick::DISTORTION_AFFINEPROJECTION, $points, false);
37
38    $bytes = $imagick->getImageBlob();
39    if (strlen($bytes) <= 0) { echo "Failed to generate image.";}
40
41//Fyi it may be easier to think of the affine transform by
42//how it works for a rotation:
43//$affineRotate = array(
44//    "sx" => cos($angle),
45//    "sy" => cos($angle),
46//    "rx" => sin($angle),
47//    "ry" => -sin($angle),
48//    "tx" => 0,
49//    "ty" => 0,
50//);
51}
52
53edgeExtend($virtualPixelType) ;
54echo "Ok";
55?>
56--EXPECTF--
57Ok