> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] Behalf Of MikeA
> Sent: January 17, 2005 17:31
> To: [email protected]
> Subject: [PHP-WIN] Output Image from Db to Browser
>
>
> I am trying to output a JPG image to the browser without
> creating a file. I have tried several
> things but nothing seems to work. I sure could use a whole
> lot of help right now! LOL Going crazy
> trying to figure this out. But I know there are PHP gurus
> out there that will have the answer in 2
> seconds. Hopefully I'll be at that level someday too!
>
> The image comes from a MySQL Blob. The closest I get is a
> string of garbage on the browser display.
> I cannot get it to display a pictures.
>
> Suggestions, comments, help, almost anything is appreciated.
> PLEASE help me! Project due in a week.
>
> Thanks in advance.
>
> Mike
>
>
> if( mysql_num_rows($result) == 1 )
> {
> //header('Content-type: image/*');
> $fileContent = mysql_result($result,0); //,$blobfield);
> echo $fileContent;
>
> //$theimage = imagecreatefromstring ($fileContent);
>
> //echo imagejpeg ( $theimage);
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Here is how I'm doing it in a Call Flow setting.
---------------------------------
<?php
// -- program to dynamically create call flows from DB calls.
// -- The jpeg created here has to be within it's own frame\window with it's
own header.
// -- maybe a iframe.
//variables passed into script
//$txt = 'sometext'
//$shapetype = 'eclipse'
//$shapetype = 'polygon'
//$shapetype = 'rectangle'
if ($txt == ''){
$txt = "A Simple Text string \n A Simple Text string \n A Simple
string A Simple Text string A Simple Text string A Simple Text string A Simple
Text string A Simple Text string A Simple Text string A Simple Text string ";
}else if (substr($txt, 0,6) == '<html>'){
print stripslashes($txt);
die();
}
switch($shapetype){
case'eclipse':
$xshape_buffer = 25;
$yshape_buffer = 25;
break;
case'rectangle':
$xshape_buffer = 30;
$yshape_buffer = 50;
break;
case'polygon':
$xshape_buffer = 25;
$yshape_buffer = 25;
break;
}
// declare variables
$fontType = 5;
$fontPixelWidth = imagefontwidth($fontType);
$fontPixelHeight = imagefontheight($fontType);
$line_width = 50;
$txt_len = strlen($txt);
//------------------------
$arr_txtStart = preg_split("/\s\b/", $txt, -1, PREG_SPLIT_NO_EMPTY);
$num_lines = count($arr_txt);
$s = '';
$arr_txt=array();
$i=0;
foreach($arr_txtStart as $word){
$len_s = strlen($s);
$len_word = strlen($word) + 1; //add 1 for spaceadded
if(preg_match("/\r/i", $word )){
// print "1-$i-$word1<br>";
$s = $s." ".$word;
$arr_txt[$i] = trim($s);
$s = '';
$i++;
}else if (($len_s + $len_word)<$line_width){
// print "2-$i-$word<br>";
$s = $s." ".$word;
}else{
// print "3-$i-$word<br>";
$arr_txt[$i] = trim($s);
$s = $word;
$i++;
}
}
$arr_txt[$i] = $s; //add the remaining text to the array
$num_lines = count($arr_txt);
// create a shape width set to $line_width plus ?? pixels as a buffer
$xsize = ($fontPixelWidth * $line_width) + $xshape_buffer;
$ysize = (($fontPixelHeight) * $num_lines) + $yshape_buffer;
//print "x- $xsize y- $ysize";
//die();
if ($xsize < 475){
$xsize = 475;
}
if ($ysize < 170){
$ysize = 170;
}
//array_push($arr_txt, "x_size $xsize | y_size $ysize | str len".strlen($txt) );
//------------------------------------
$im = imagecreate ($xsize, $ysize) or die ("Cannot Initialize new GD image
stream");
//$im = imagecreate(450, 150) or die ("Cannot Initialize new GD image stream");
//header ("Content-type: image/jpeg");
//$background_color = imagecolorallocate ($im, 229,255,150); //yellow
//$background_color = imagecolorallocate ($im, 255,255,255); //white
$background_color = imagecolorallocate ($im, 0,0,0); //black
$poly_color = imagecolorallocate ($im, 0, 150, 100); //green
$text_color = imagecolorallocate ($im, 255,255,255); //white
//declare point values for the polygon
$p[0] = $xsize/2;
$p[1] = 0;
$p[2] = $xsize;
$p[3] = $ysize/2;
$p[4] = $xsize/2;
$p[5] = $ysize;
$p[6] = 0;
$p[7] = $ysize/2;
if ($shapetype == "polygon"){
imagefilledpolygon($im, $p, 4, $poly_color);
}else if($shapetype == "rectangle"){
imagefilledrectangle ($im, 5, 5, ($xsize-5), ($ysize-5), $poly_color);
}else if($shapetype == "eclipse"){
$poly_color = imagecolorallocate ($im, 246, 133, 137); //pink
imagefilledellipse ($im, ($xsize/2), ($ysize/2), ($xsize), ($ysize),
$poly_color);
}else{
die("No Flow ID Selected");
}
// --------------------------- string formatting
-------------------------------------
//find the rough middle of the string
if (strlen($txt) <= $line_width){
$middle = (($xsize/2) - ($fontPixelWidth * (strlen($txt)/2)));
}else {
$middle = ($xsize/2) - ($fontPixelWidth * ($line_width/2));
}
if ($shapetype == "polygon"){
//$poly_color = imagecolorallocate ($im, 255, 255, 255);
//$text_color = imagecolorallocate ($im, 0,0,0);
imagecolortransparent($im, $text_color);
imagerectangle ($im, 0, 0, ($xsize), ($ysize), $poly_color);
$nl=(($ysize/2)-(($num_lines/2)*$fontPixelHeight));
}elseif ($shapetype == "eclipse"){
if ($txt_len > 1000){
$poly_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagecolortransparent($im, $text_color);
imagerectangle ($im, 0, 0, ($xsize), ($ysize), $poly_color);
}
$nl=(($ysize/2)-(($num_lines/2)*$fontPixelHeight));
array_push($arr_txt, "");
array_push($arr_txt, "");
$sp = ($xsize/2) - ($fontPixelWidth * 5);
$newsp = ($sp - $middle)/$fontPixelWidth;
for ($r=1;$r < $newsp;$r++){
$spacer .= ' ';
}
//print "$sp | $newsp | $middle |$spacer|";
array_push($arr_txt, "$spacer End of Flow");
}elseif ($shapetype == "rectangle"){
$nl=(($ysize/2)-(($num_lines/2)*$fontPixelHeight));
}
for ($i=0;$i < (count($arr_txt));$i++){
imagestring ($im, $fontType, ($middle), ($nl),
trim(stripslashes($arr_txt[$i])), $text_color);
$nl += 12;
}
//sequence number in top left corner of flow
imagestring ($im, 0, (5), (5), $seqnum, $text_color);
//$seqnum
//$tmpfilename = 'temp'.(md5(uniqid("", TRUE))).'.jpg';
//print $tmpfilename;
//die();
header ("Content-type: image/jpeg");
ImageJPEG($im, "", 70);
imagedestroy($im);
?>
-------------------------------------------
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php