Page 1 of 1

Image Controls - Distorting image

Posted: Tue Sep 11, 2007 5:49 pm
by elinews
Could anyone tell me how to distort an image using image controls to give it a 3d perspective like the pic below?

Thanks in advance!

Image

Posted: Tue Sep 11, 2007 5:51 pm
by feyd
Not fun. You will have to do the 3D math yourself.

Posted: Tue Sep 11, 2007 5:59 pm
by elinews
feyd wrote:Not fun. You will have to do the 3D math yourself.
I'm fine with that. I just don't even know where to begin. I've never used image controls before.

Posted: Tue Sep 11, 2007 6:07 pm
by Ollie Saunders
I'm fine with that.
I wouldn't be. If you can write that sort of stuff with any ease you wouldn't be calling them "controls". Check out PEAR I believe there is a package especially designed for this kind of stuff, it has 3D in the title, shouldn't be hard to find.

Posted: Tue Sep 11, 2007 6:13 pm
by feyd
http://www.geocities.com/SiliconValley/2151/math3d.html talks about rotations. In the quick glance I took of it, it did not specify if the math was for the 2D projection of the rotation however. Although the math to convert them isn't all that complicated. You will probably need subpixel calculation however.

Posted: Tue Sep 11, 2007 6:22 pm
by mrkite
Using a lot of math and brain hurting, you can use the -fx flags in imagemagick's convert to do it.

http://www.imagemagick.org/Usage/script ... _transform

There's a perl script to output the proper fx values.

Posted: Wed Sep 12, 2007 3:32 am
by onion2k
It can be faked using imagecopyresampled, but the result isn't really that good...

Code: Select all

<?php

    //Fake perspective transform

    $source = imagecreatefromjpeg("image.jpg");
    $width = imagesx($source);
    $height = imagesy($source);

    $destination = imagecreatetruecolor($width,$height);
    $white = imagecolorallocate($destination,255,255,255);
    imagefill($destination,0,0,$white);

    for ($x = 0; $x<$width; $x++) {

        imagecopyresampled($destination,$source,$x,($height/4)-(($height/$width)*$x/4),$x,0,1,($height/2)+(($height/$width)*$x/2),1,$height);

    }

    header("Content-type: image/jpeg");
    imagejpeg($destination);

?>

Posted: Wed Sep 12, 2007 3:03 pm
by elinews
onion2k wrote:It can be faked using imagecopyresampled, but the result isn't really that good...

Code: Select all

<?php

    //Fake perspective transform

    $source = imagecreatefromjpeg("image.jpg");
    $width = imagesx($source);
    $height = imagesy($source);

    $destination = imagecreatetruecolor($width,$height);
    $white = imagecolorallocate($destination,255,255,255);
    imagefill($destination,0,0,$white);

    for ($x = 0; $x<$width; $x++) {

        imagecopyresampled($destination,$source,$x,($height/4)-(($height/$width)*$x/4),$x,0,1,($height/2)+(($height/$width)*$x/2),1,$height);

    }

    header("Content-type: image/jpeg");
    imagejpeg($destination);

?>
thanks onion you're a life saver.

Do you know where/how I can download and install php imagecontrols on my apache server?

Posted: Wed Sep 12, 2007 5:39 pm
by superdezign
elinews wrote:Do you know where/how I can download and install php imagecontrols on my apache server?
What image controls are you referring to? I've never heard of image controls before.

The GD library can do basically anything that you are after with images, though you may run across times where you'll need to know more in-depth mathematics to accomplish what you are after. You can usually find examples, it's just a matter of knowing what to search for (which is a pain). You usually won't find examples in PHP, but C++ and Delphi always seem to have examples for image creation and manipulation.