Attempting to distort image using PHP GD library

I searched everywhere to try to find a function to distort the image using php using the GD library. I read the topics where ImageMagick was suggested, but I unfortunately do not have access to this library on my server, so I have to use GD. I am 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 knows or knows any feature like this or similar that would be awesome, thanks!

+4
source share
1 answer

The PHP manual is an amazing place. This comment covers a lot of scenarios to a large extent. Use the "Perspective" section. The example below is slightly modified to use the width and height of 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; 
+1
source

Source: https://habr.com/ru/post/1344483/


All Articles