开发者

Trying to skew an image with PHP's GD Library

I've been looking everywhere to try and find a function to skew an image with php using the GD library. I've read threads where ImageMagick has been suggested but I unfortunately don't have access to that library on my server so I'm forced to use GD. I'm looking for something where I can specify the source image and destination image and then 4 sets of X and Y coordinates for each corner of the image. So something like this would be ideal:

bool skewImage(resource $src_im, resource $dst_im, int $x1, int $y1, int $x2, int $y2, int $x3, int $y3, int $x4, int $y4)

If anyone has or knows of a function like this or similar that would be aw开发者_StackOverflow中文版esome, thanks!


The PHP manual is an amazing place. This comment pretty much covers a lot of scenarios. Use the 'Perspective' section. Below example is slightly modified to use the width and height from the image.

$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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜