Guidelines: Using PHP and GD library
I have ordinary pictures (png|gif|jpeg) and want to cut out triangles. To facilitate lets assume we want to cut images in 4 parts, each triangle starting from the center. You got it?
Painting triangles with GD goes like this:
<?php
//create a white canvas
$im = @imagecreate(500, 500) or die("Cannot Initialize new GD image stream");
imagecolorallocate($im, 255, 255, 255);
//triangle
$t1 = rand(0,400);
$t2 = rand(0,400);
$t3 = rand(10,100);
$t4 = rand(10,100);
$points = array(
$t1, $t2,
($t1+$t3), $t2,
$t1, ($t2+$t4)
);
$trcol = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
imagefilledpolygon($im, $points, 3, $trcol);
//make png and clean up
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
now we Actually want to CUT a triangle from an already existing picture. I only know how to cut out a rectangle from an existing picture like this:
<?php
// Create image instances
$src = imagecreatefromgif('php.gif');
$dest = imagecreatetruecolor(80, 40);
// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>
PHP GD imagecopy bool imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
So how do we combine these two approaches to do what is intented?