Tutorials by DJ Mike

<td> <input type="submit" value="Go"> </td>


More WebTV Links


Perspective Distort is an effect at Imagemagick that allows you to distort an image into trapezoids and other quadrilaterals. Among other things,you can use it to make a stone wall look like it has been rotated around you are looking at it from an angle.

For this lession, I will take an image of the Trifid Nebula and make it into a box. To do that, I will make five versions of the image; four trapezoids and one smaller version.

The first thing I do is sketch out the outline on paper and figure out where the corners will be so all the parts will line up correctly in the end.


Take your starting image to Imagemagick. If it is not already a gif, output it as one and save it for steps to come. Now go to Resize and resize it to fit in the middle rectangle of your sketch and output it as a gif. Click the thumbnail. Use your Go To key to get the URL and save it. Using your Recent key, go back to a step where the image is still big, then click the tab for View. Set Method to Reset; Paint Type to Matte; Fill color to none and click the image. This results in a transparent image the same size as the original. Now go to Composite and composite the small image with Gravity set to Center (assuming that you want the end to be centered like I do for this example). Output and save.

Get the URL for the large GIF that you saved and enter it into Imagemagick. Click the F/X tab. Select Perspective Distort. Set Virtual Pixel Method to Transparent, background color to none and fill color to none.

Perspective Distort requires eight cooridinates. The first four are the corners of the start quadrilateral, the next four are the cornors of the end quadriateral. For this example, the start quadrilateral will always be the whole starting image but it doesn't have to be. If the starting corners are in the inside of the start image, the lines of perspective extend to the edge of the image. The order of the cornors is not important but to avoid confusion, you should pick an order and stick to it.

It is so easy to enter the wrong cooridinates that I work them out on a full screen instead of the tiny box at Imagemagick and I save them in case I have to come back to them later. Imagemagick ignores spaces and line breaks so you can use them to make it easier to read your entry.


0,0, 500,0, 0,372, 500,372,
0,0, 125,93, 0,372, 125,279


The order I used was: top,left, top,right, bottom,left, bottom,right. On the bottom row, the cooridinates for top,left and bottom,left remain unchanged; the top,right corner is moved to 125,92 and the bottom,right corner is moved to 125,279

Output as a GIF. Important! When you output, make sure that the background is really transparent. If you started with a JPEG, Imagemagick will make it look like the background is transparent when it is really black. Later on, when you try and layer all the pieces together, the black background will cover the bottom layers. Before you save the image, note the background color of the thumbnail. If it is black, click the View tab, set Method to Floodfill; Paint Type to matte; Fill Color to none and click the black background area. Output and save.

For the right quadrilateral, I repeat the last step but move the top,left corner to 375,93 and the bottom,left corner to 375,279


0,0, 500,0, 0,372,  500,372,
375,93, 500,0, 375,279, 500,372


For the top quadrilateral, I move the bottom,left corner to 125,93 and the bottom,right corner to 375,93


0,0,  500,0, 0,372, 500,372,
0,0,  500,0, 125,93, 375,93


For the top quadrilateral, I move the top,left corner to 125,279 and the top,right corner to 375,279


0,0, 500,0, 0,372, 500,372,
125,279, 375,279, 0,372, 500,372
   

If you did everything correctly so far, all the pieces will fit together like a puzzle without resizing, making backgrounds transparent or needing to move them around. Take any of the quadrilaterals that you made and one by one, composite the others onto it.



Created by DJ Mike from Santa Barbara

DJ Mike


Dance Away Santa Barbara's Home Page
<a href="http://www.statcounter.com/" target="_blank"> <img src="http://c5.statcounter.com/counter.php?sc_project=1321035&java=0&security=da2193dc" alt="counter free hit invisible" border="0" /></a>