Menu
Hi all.
I’m trying to generate a “play button” using only php.
Better explained, what I need is to generate a transparent png of an equilateral triangle (turned on it’s side).
I have no idea where to begin. I’ve done some php based opening and resizing of images but never this.
The more you’re comfortable contributing, code wise, the better off I’ll be.
Any takers?
[CODE]imageantialias($image, true);[/CODE]
[code=php]else if ($display == 'img') {
header("Content-type: image/png");
$f = $_GET['f'];
$w = $_GET['w'];
$h = $_GET['h'];
if ($f != null && $f != 'play' && $f != 'pause' && $f != 'eject') {
$t = substr($f, 0, -4).'_'.$w.'x'.$h.'.png';
if (file_exists($t)) header('location: '.$t);
else {
list($wo, $ho) = getimagesize($f);
$ip = imagecreatetruecolor($w, $h);
$img = imagecreatefrompng($f);
imagecopyresampled($ip, $img, 0, 0, 0, 0, $w, $h, $wo, $ho);
imagepng($ip, $t, 9);
imagepng($ip, null, 9);
}
} else {
if ($f == 'play' || $f == 'pause' || $f == 'eject') {$w = $pw; $h = $ph; $c = $cl; $t = 'bg/bg_'.$f.'_'.$c.'_'.$w.'x'.$h.'.png';}
else {
$c = strtolower($_GET['c']);
if ($w == $h) $t = 'bg/bg_'.$c.'.png';
else if ($w < $h) $t = 'bg/bg_hr_'.$c.'.png';
else $t = 'bg/bg_vr_'.$c.'.png';
}
if (file_exists($t)) header('location: '.$t);
else {
if ($f == 'play') {
if ($h % 2 != 0) {$pts = array(0, 0, 0, $h - 1, $w, $h / 2); $pg = 3;}
else {$pts = array(0, 0, 0, $h - 1, $w, $h / 2, $w, $h / 2 - 1); $pg = 4;}
}
else if ($f == 'eject') {
$pts = array(5,0, 0,7, 11,7, 6,0);
$pg = 4;
$bse = array(11,0, $w,11, 11,$h, 0,$h);
}
$img = @imagecreate($w, $h);
sscanf($c, "%2x%2x%2x", $r, $g, $b);
$fc = imagecolorallocate($img, $r, $g, $b);
if ($f == 'play' || $f == 'pause' || $f == 'eject') {
$bg = imagecolorallocate($img, 127, 127, 127);
imagefilledrectangle($img, 0, 0, $w-1, $h-1, $bg);
if ($f == 'play' || $f == 'eject') imagefilledpolygon($img, $pts, $pg, $fc);
if ($f == 'pause' || $f == 'eject') {
imagesetthickness ($img, $w *.25);
if ($f == 'pause') {
$m1 = $w * .3;
$m2 = $w * .7;
imageline ($img, $m1, 0, $m1, $h-1, $fc);
imageline ($img, $m2, 0, $m2, $h-1, $fc);
}
else imageline ($img, 0, $h-2, $w-1, $h-2, $fc);
}
imagecolortransparent($img, $bg);
}
else if ($w != $h) {
$a = imagecolorallocatealpha($img, 0, 0, 0, 127);
if ($w < $h) imagesetpixel($img, 0, 1, $a);
else if ($w > $h) imagesetpixel($img, 1, 0, $a);
}
// imagepng($img, $t, 9);
imagepng($img, null, 9);
}
}
}[/code]
[CODE]if ($f == 'play') {
$wss = $w * 10;
$hss = $h * 10;
$imgss = imagecreatetruecolor($wss, $hss);
$a = imagecolorallocatealpha($imgss, 0, 0, 0, 127);
imagefill($imgss, 0, 0, $a);
$c = imagecolorallocate($imgss, $r, $g, $b);
$pts = array(0,0, 0,$hss-1, $wss-1,$hss/2, $wss-1,$hss/2-1);
imagefilledpolygon($imgss, $pts, 4, $c);
$img = imagecreatetruecolor($w, $h);
imagesavealpha($img, true);
imagefill($img, 0, 0, $a);
imagecopyresampled($img, $imgss, 0, 0, 0, 0, $w, $h, $wss, $hss);
}
else if ($f == 'pause' || $f == 'eject') {
$imgsm = @imagecreate(5, 1);
$c = imagecolorallocate($imgsm, $r, $g, $b);
imagefill($imgsm, 0, 0, $c);
$a = imagecolorallocatealpha($imgsm, 0, 0, 0, 127);
imagesetpixel($imgsm, 0, 0, $a);
imagesetpixel($imgsm, 2, 0, $a);
imagesetpixel($imgsm, 4, 0, $a);
$img = @imagecreate($w, $h);
imagecopyresized($img, $imgsm, 0, 0, 0, 0, $w, $h, 5, 1);
if ($w % 5 != 0) {
$imga = @imagecreate($vcw, $h);
imagecopy($imga, $img, 0, 0, 0, 0, $vcw, $h);
$img = $imga;
}
if ($f == 'eject') {
$ga = 127;
$x = 0;
$cnt = 0;
while ($ga != 0) {
$rgb = imagecolorat($img, $x, 0);
$crs = imagecolorsforindex($img, $rgb);
$ga = $crs['alpha'];
if ($ga != 0) {
$cnt++;
$x++;
}
}
$bc = round($h * .8);
$bs = $h - $bc + $cnt;
$wss = $w * 10;
$hss = ($h - $bs) * 10;
$imgss = imagecreatetruecolor($wss, $hss);
$a = imagecolorallocatealpha($imgss, 0, 0, 0, 127);
imagefill($imgss, 0, 0, $a);
$c = imagecolorallocate($imgss, $r, $g, $b);
$pts = array($wss/2-1,0, 0,$hss-1, $wss-1,$hss-1, $wss/2,0);
imagefilledpolygon($imgss, $pts, 4, $c);
$img = imagecreatetruecolor($w, $h);
imagesavealpha($img, true);
imagefill($img, 0, 0, $a);
imagecopyresampled($img, $imgss, 0, 0, 0, 0, $w, $h - $bs, $wss, $hss);
imagefilledrectangle($img, 0, $bc, $w - 1, $h - 1, $c);
}
}[/CODE]
0.1.9 — BETA 5.27