Thanks for responing Jason!

There is other code in there for updating some database entries and
producing a confirmation page, but I had them working perfectly before I
added the image code below.  Only when acessing the outside script and
saving to file did it start doing the odd things.  I didn't write the image
creation script, only hard coded in some values for font and bg colors in
it.  I have attached that script at the bottom of this, away from everything
else.  Maybe a header problem from that script?  Any idea what 427 is from?
Thanks for all your help!

The $image_url is like this - "$rollover_image_url =
"http://www.anysite.com//pngmake.php?msg="; . $rollover .
"&rot=0&size=12&font=fonts/ARIAL.TTF";

"Jason Wong" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> On Saturday 07 December 2002 05:12, Jeremiah Breindel wrote:
> > I am trying to save a dynamically generated image on an outside server
to a
> > local file on my server using the code below:
> >
> >  $fc = fopen($image_filename, "wb");
> >  $file = fopen ($image_url, "rb");
> >
> >  if (!$file) {
> >   echo "<p>Unable to open remote file.\n";
> >   exit;
> >  }else{
> >   while (!feof ($file)) {
> >    $line = fread ($file, 1028);
> >    fwrite($fc,$line);
> >   }
> >  }
> >  fclose($fc);
> >         fclose($file);
> >
> >
> > $image_filename is a locally referred to file, such as
> > "../images/file1.png" and $image_url is an absolute address, such as
> > "http://www.whatever.com/imagecreate.php";.
> >
> > Instead of saving when I run the script through a browser, the image
> > displays within the browser, and the script creates a file containing
only
> > "427" on the server.  Any ideas why or what I can do to correct this?
>
> Hmm, I don't see how the above code can make the remote image *display*
your
> browser. The code itself looks OK, are there some parts of the code that
you
> haven't shown us?
>
> If the above is indeed your complete code, then what is your $image_url?
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
> /*
> Things will be bright in P.M.  A cop will shine a light in your face.
> */
>

<?
/*
To draw the PNG - call this script with a URL like the following:

pngmake.php3?msg=testing+class&rot=15&size=48&font=fonts/ARIAL.TTF
*/


class textPNG {
    var $font = 'fonts/ARIAL.TTF'; //default font. put in full path.
    var $msg = "undefined"; // default text to display.
    var $size = 24;
    var $rot = 0; // rotation in degrees.
    var $pad = 0; // padding.
    var $transparent = 1; // transparency set to on.
    var $red = 0; // white text...
    var $grn = 0;
    var $blu = 0;
    var $bg_red = 255; // on black background.
    var $bg_grn = 255;
    var $bg_blu = 255;

function draw() {
    $width = 499;
    $height = 39;
    $offset_x = 0;
    $offset_y = 0;
    $bounds = array();
    $image = "";

    //$this->msg = date ("h:i:s");

    // determine font height.
    $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W");
    if ($this->rot < 0) {
        $font_height = abs($bounds[7]-$bounds[1]);
    } else if ($this->rot > 0) {
        $font_height = abs($bounds[1]-$bounds[7]);
    } else {
        $font_height = abs($bounds[7]-$bounds[1]);
    }

    // determine bounding box.
    $bounds = ImageTTFBBox($this->size, $this->rot, $this->font,
$this->msg);
    if ($this->rot < 0) {
//        $width = abs($bounds[4]-$bounds[0]);
//        $height = abs($bounds[3]-$bounds[7]);
        $offset_y = $font_height;
        $offset_x = 0;

    } else if ($this->rot > 0) {
//        $width = abs($bounds[2]-$bounds[6]);
//        $height = abs($bounds[1]-$bounds[5]);
        $offset_y = abs($bounds[7]-$bounds[5])+$font_height;
        $offset_x = abs($bounds[0]-$bounds[6]);

    } else {
//        $width = abs($bounds[4]-$bounds[6]);
//        $height = abs($bounds[7]-$bounds[1]);
        $offset_y = $font_height;;
        $offset_x = 0;
    }

    $image = imagecreate($width+($this->pad*2)+1,$height+($this->pad*2)+1);

    $background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn,
$this->bg_blu);
    $foreground = ImageColorAllocate($image, $this->red, $this->grn,
$this->blu);

    if ($this->transparent) ImageColorTransparent($image, $background);
    ImageInterlace($image, false);

    // render it.
    ImageTTFText($image, $this->size, $this->rot, $offset_x+$this->pad,
$offset_y+$this->pad, $foreground, $this->font, $this->msg);

    // output PNG object.
    imagePNG($image);
}
}

$text = new textPNG; // instantiate new textPNG class.

if (isset($msg)) $text->msg = $msg; // text to display
if (isset($font)) $text->font = $font; // font to use (include directory if
needed).
if (isset($size)) $text->size = $size; // size in points
if (isset($rot)) $text->rot = $rot; // rotation
if (isset($pad)) $text->pad = $pad; // padding in pixels around text.
if (isset($tr)) $text->transparent = $tr; // transparency flag (boolean).
if (isset($clr)) { // text colour
  $text->red = hexdec(substr($clr, 0, 2));
  $text->grn = hexdec(substr($clr, 2, 2));
  $text->blu = hexdec(substr($clr, 4, 2));
}
if (isset($bg)) { // background colour
  $text->bg_red = hexdec(substr($bg, 0, 2));
  $text->bg_grn = hexdec(substr($bg, 2, 2));
  $text->bg_blu = hexdec(substr($bg, 4, 2));
}



// make up some expiry information. say, 60 secs to ive.
$now = mktime (date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
$expires = mktime (date("H"),date("i"),date("s") + 60
,date("m"),date("d"),date("Y")); // add 60 secs.
$expires_gmt = gmdate('D, d M Y H:i:s', $expires).' GMT';
$last_modified_gmt  = gmdate('D, d M Y H:i:s', $now).' GMT';

header('Content-type:image/png');
header('Expires: '.$expires_gmt);
header('last-modified: '.$last_modified_gmt);

$text->draw();
?>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to