Probably the best tool for manipulating images would be ImageMagick. If you take a look at the documentation there are extensive examples that show how to use the
-distort feature which I believe is what you're looking for.
Command line to perform the conversion:
$ convert checks.png -filter point
-virtual-pixel tile -mattecolor DodgerBlue
-distort Perspective '0,0 20,60 90,0 70,63 0,90 5,83 90,90 85,88'
There are 2 other methods for doing the sampling to get the resulting image looking better. Specifically "Grid Super Sampling" & "Elliptical Weighted Area
(EWA) Resampling". The latter is the default.
How do I calculate the coordinates?
There are 2 resources for getting a grasp of how to generate the series of coordinates to
convert. The first is the one I gave above. The second is this SO Q&A titled: Understanding Perspective Projection Distortion ImageMagick, specifically @KurtPfeifle's answer.
The coordinates are as follows:
Sx1,Sy1 Dx1,Dy1 Sx2,Sy2 Dx2,Dy2 Sx3,Sy3 Dx3,Dy3 ... Sxn,Syn Dxn,Dyn
- x is used to represent an X coordinate.
- y is used to represent an Y coordinate.
- 1, 2, 3, ... n is used to represent the 1st, 2nd, 3rd, ... nth pixel.
- S is used here for the source pixel.
- D is used here for the destination pixel.