GD problems:

GD problems:

am 05.10.2007 07:49:10 von jimbo

What I want to do.
1. create a new image with specific background color.
2. add text and/or png images w/transparent background in any order
3. change background img/color at anytime
3. save and output to browser
I pretty much understand all the synyax but haven't a clue as to
procedure
and flags

1. $im = imagecreatetruecolor(450,250);
imagecolorallocate($im, 0xDD, 0xDD, 0xFF)
result is black background (above color is set. it is displayed for a
fraction of a second and then overwritten with black. It works with
imagecreate() but then I have an indexed img which I don't believe can
do
what I want.

$im = imagecreatetruecolor(450,250);
imagealphablending($im, false);
imagefill($im, 0, 0, imagecolorallocatealpha($im, 0xDD, 0xDD, 0xFF,
0));
imagesavealpha($im, true);
gives desired result but I don't know why :>}
2. I can add text or image to the above but there are problems. I'm
not sure
if what I'm doing is correct or if there's a better way. I've seen
examples
using imagettfbbox with imagesavealpha true. Any help?
3. Don't have a clue. Since the background seems to be the alpha
channel I
will try messing with the alphacolor
4. No Problem
What I am trying.
javascript
funtion renderImage() {//
var x = 1, y = 1; // test.php sets them if left off the call
var url = "test.php?mode=pic&srcfile=0.png&x=" + x + "&y=" + y;
document.images['outPic'].src = url;
}
function renderText() {
// same as above
var myText = 'Hello World';
var url = "test.php?mode=text&srcfile=newpic.png&text=" + myText;
document.images['outPic'].src = url;
}

html


test.php
function convToDec($sum) {
switch($sum) {
case "f": return 15;
case "e": return 14;
case "d": return 13;
case "c": return 12;
case "b": return 11;
case "a": return 10;
default: return intval($sum);
}
}
function hexToDec($str) {
$dec = convToDec(substr($str, 0, 1)) * 16;
$dec= $dec + convToDec(substr($str, 1 ,1));
return $dec;
}
isset($_GET['mode'])? $mode = $_GET['mode']: die('ERROR: No mode
specified.');
$path = $_SERVER['ORIG_PATH_TRANSLATED'];
$filepath = substr($path, 0, strrpos($path,'\\')+1);

if ($mode == 'new') {
$im = imagecreatetruecolor(450,250);
imagealphablending($im, false);
imagefill($im, 0, 0, imagecolorallocatealpha($im, 0xDD, 0xDD,
0xFF, 0));
imagesavealpha($im, true);
$src = $filepath . 'newpic.png';
imagepng($im, $src);
imagedestroy($im);
}
else {
isset($_GET['col'])? $color = $_GET['col']: $color = '000000';
$r = hextodec(substr($color, 0, 2));
g = hextodec(substr($color, 2, 2));
$b = hextodec(substr($color, 4, 2));
isset($_GET['srcfile'])? $file = $_GET['srcfile']: die('ERROR: No
source
image specified.');
isset($_GET['x'])? $x = $_GET['x']: $x = 0;
isset($_GET['y'])? $y = $_GET['y']: $y = 0;
isset($_GET['fn'])? $font = $_GET['fn']: $font = 'c:\windows\fonts
\arial.ttf';
isset($_GET['fnsz'])? $fnsz = $_GET['fnsz']: $fnsz = 13;
$src = $filepath . $file;
if (!file_exists($src)) {
die('ERROR: Source image does not exist.');
}
$dest = $filepath . 'newpic.png';
}
if ($mode == 'text') {
isset($_GET['text'])? $text = $_GET['text']: die('ERROR: No text
specified.');
$im = imagecreatefrompng($src);
$textcolor = imagecolorallocate($im, $r, $g, $b);
imagettftext($im,$fnsz,0,$x,$y+$fnsz,$textcolor,$font,$text) ;
imagesavealpha($im, true);
imagepng($im, $dest);
}

if ($mode == 'pic') {
$im = ImageCreateFromPNG($dest);
ImageAlphaBlending($im, true);
$overlay = ImageCreateFromPNG($src);
$logoW = ImageSX($overlay);
$logoH = ImageSY($overlay);
ImageCopy($im, $overlay, $x, $y, 0, 0, $logoW, $logoH);
header('Content-type: image/png');
ImagePng($im, $dest); // output to browser
ImageDestroy($overlay);
}
//error_reporting(E_ALL);
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Any help would be appreciated. TIA
Jim