Imagick:cropImage ()函数是PHP的内置函数,用于提取图像区域。
使用方法:
int imagick :3360 crop image $ width,$height,$x,$y )
参数:此函数接受上述四个参数,如下所述。
$width:此参数用于指定裁剪图像的宽度。
$height:此参数用于指定裁剪图像的高度。
$x:此参数用于指定左上角裁剪图像的x坐标。
$y:此参数用于指定左上角裁剪图像的y坐标。
返回值:成功时返回True。
以下示例程序用于说明PHP的Imagick:cropImage ()函数。
原始图像:
样本1:
//require _ once (path/vendor/autoload.PHP );
//创建an imagick object
$image=new Imagick (
' https://media.geeksforgeeks.org/WP-content/uploads/geeksforgeeks-13.png ' );
//Imagick function to crop Image
$ image-crop image (390,100,0,0 );
header (内容类型: image/jpg );
//Display the image
echo $image-getImageBlob (;
?
输出:
原始图像:
样本2:
$ string=' computerscienceportalforgeeks!' ;
//creatingnewimageofabovestring
//和添加颜色和背景
$im=new Imagick (;
$draw=new ImagickDraw (;
//Fill the color in image
$ draw-set fill color (newimagickpixel (' green ' );
//Set the text font size
$draw-setfontsize(50;
$ metrix=$ im-queryfontmetrics ($ draw,$string );
$绘制-注释(0,40,$字符串);
$ im-new image ($ metrix [ ' text width ' ],$metrix['textHeight'] ),
newimagickpixel('white ' );
//Draw the image
$im-drawimage($draw;
//set the image格式
$im-setimageformat('png );
//Imagick function to crop Image
$ im-crop image (420,120,0,0 );
header (内容类型: image/jpg );
//Display the image
echo $im-getImageBlob (;
?
输出: