Xer*_*tez 5 php gd image transform skew
我一直在到处寻找,尝试找到一个使用 GD 库使用 php 来倾斜图像的函数。我读过建议使用 ImageMagick 的线程,但不幸的是我无法访问我的服务器上的该库,所以我被迫使用 GD。我正在寻找可以指定源图像和目标图像,然后为图像的每个角指定 4 组 X 和 Y 坐标的东西。所以像这样的东西是理想的:
bool skewImage(resource $src_im, resource $dst_im, int $x1, int $y1, int $x2, int $y2, int $x3, int $y3, int $x4, int $y4)
Run Code Online (Sandbox Code Playgroud)
如果有人拥有或知道这样或类似的功能那就太棒了,谢谢!
PHP 手册是一个令人惊奇的地方。这个评论几乎涵盖了很多场景。使用“透视”部分。下面的示例稍作修改以使用图像的宽度和高度。
$image = new imagick( "grid.jpg" );
$points = array(
0,0, 80,120, # top left
$image->width,0, 300,10, # top right
0,$image->height, 5,400, # bottom left
$image->width,$image->height, 380,390 # bottum right
);
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethod( imagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImage( Imagick::DISTORTION_PERSPECTIVE, $points, TRUE );
header( "Content-Type: image/jpeg" );
echo $image;
Run Code Online (Sandbox Code Playgroud)