(1). Create a new picture, width 500px, height 300px, black, PNG format picture
$img =new Imagick (); $img->newimage (500,300, ' black ', ' png ')
(2). Overlay of pictures;
Let's say we take the $img in Example 1 as the background, and this time we overlay the second picture onto the picture; Choose a spurs GDP portfolio;
Know that the path of picture two is assumed to be $imagesrc= "/home/xxxx/spurs.png";
The first step is to instantiate this image
$imgtwo = new Imagick ($IMAGESRC);
Because it is to be superimposed, we need to set the size of the two graphs, first we want to live the size of the first picture (PS: Here we can also specify the size).
$height = $img->getimageheight ();//Get Picture 1 height $width= $img->getimagewidth ();//Get Picture 1 width
The second step is to resize the picture
$imgtwo->resizeimage ($width, $height, imagick::filter_lanczos,1);
Resizeimage parameter Description
BOOL Imagick::resizeimage (int $columns, int $rows, int $filter, float $blur [, bool $bestfit = false])
Parameter explanation:
Columns width of picture
Rows Picture Height
Filter filter for filtering images with Gaussian filte depending on the situation
Blur blur=1 for Blur, Blur =-1 for sharpening
Part Three, overlay pictures
Use Compositeimage ();
BOOL Imagick::compositeimage (Imagick $composite _object, int $composite, int $x, int $y [, int $channel = Imagick::cha Nnel_all])
Parameter description:
Composite_object: The Imagick object for the merged picture
Composite: A merge operation that defines an action constant. For details, see the list of merge action constants
X: The horizontal axis of the top left position (0,0) relative to the image vertex
Y: Ordinate of relative top left position (0,0) of the image vertex
Channel: Turns on tunnel mode by passing in a channel constant. To support multiple channels, you can combine multiple channel constants by using binary operations.
PS: Here is the picture two overlay to the picture one
$img->compositeimage ($imgtwo, $image->getimagecompose (), 0,0)
The image is generated as follows:
At last
1. We can view the image directly on the webpage, but add a header message;
Header ("Content-type:image/png"); Echo $img;
2. The image can be generated in the specified directory;
Generated in the current year directory as img.png$file= "./img.png"; $img->writeimage ($file), which will generate a picture img.png in the present directory;
(3). Configure text on the picture
Need to use Imagickdraw class;
The first step instantiates the Imagickdraw class:
$draw =new Imagickdraw ();
Set Font Color
$draw->setfillcolor (New Imagickpixel (' White '));
Set Font size
$draw->setfontsize (' 25 ');
Set font
$draw->setfont (". /fonts/arial.ttf ");
Set font orientation
$draw->settextalignment (imagick::align_right);
Ps:
Imagick::align_right towards the right.
Imagick::align_left Left
Imagick::align_center Middle
Set the font encoding format
$draw->settextencoding ("Utf-8")
Draw the text
$draw->annotation (200,200, ' GDP ');
Draw on the bottom plate;
$img->drawimage ($draw);
The greatest combination of GDP in NBA history
(4). Cropping a picture
Duncan retired this summer, and the GDP portfolio was a problem solver. We can only remove Duncan.
$img->cropimage (300, 300, 0, 20);
The first parameter is the width of the picture
The second one is the height
X-axis position of picture clipping
Picture clipping y-axis position
And then we're going to create a rounded corner
$img->roundcorners (60, 60);
And then there's less Duncan now the Spurs and plus a Leonard
PS: Here I re-write the text, become a GP;