5

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 awesome, thanks!

Ben Grant
  • 305
  • 6
  • 18
XeroBytez
  • 51
  • 1
  • 3
  • Exact duplicate of [How would I skew an image with GD Library?](http://stackoverflow.com/questions/1650358/how-would-i-skew-an-image-with-gd-library). It also happens to be the #1 result in Google for `gd skew`. – Charles Mar 20 '11 at 20:11
  • 2
    I read that thread and the answers provided are not quite what I'm looking for. That function will only skew one side or the other, similar but not the same. – XeroBytez Mar 21 '11 at 11:47

1 Answers1

1

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;
dakdad
  • 2,947
  • 2
  • 22
  • 21