Re: [PHP] save file from outside url
When I wanted to output the png to file, I just need to plop the global label in front of the $image_filename before I passed it.. Simple mistake, that's what I get for using someone else's script ;-) // output PNG object. global $image_filename; imagePNG($image, $image_filename); "Jason Wong" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > On Monday 09 December 2002 23:44, Jeremiah Breindel wrote: > > Ok. I stripped the needed code out of the image creation script and > > inserted it into my update script. It works great as long as I hard > > code in the filename of the file that is being saved to the server. > > When I pass the image creation function a variable for the filename it > > tells me "invalid filename", although I am echoing it out right before > > and it looks perfect. Any thoughts? > > Could you show the (relevant) parts of your updated code? > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > > /* > Put your brain in gear before starting your mouth in motion. > */ > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] save file from outside url
image output code is close to the bottom *** $image_filename = "../images/tsroll_" . $id . ".png"; //dynamic file name $msg = $rollover; class textPNG { var $font = 'fonts/ARIAL.TTF'; //default font. put in full path. var $msg = "undefined"; // default text to display. var $size = 11; 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 = 14; $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, $image_filename); } } $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)); } $text->draw(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] save file from outside url
On Monday 09 December 2002 23:44, Jeremiah Breindel wrote: > Ok. I stripped the needed code out of the image creation script and > inserted it into my update script. It works great as long as I hard > code in the filename of the file that is being saved to the server. > When I pass the image creation function a variable for the filename it > tells me "invalid filename", although I am echoing it out right before > and it looks perfect. Any thoughts? Could you show the (relevant) parts of your updated code? -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Put your brain in gear before starting your mouth in motion. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] save file from outside url
Ok. I stripped the needed code out of the image creation script and inserted it into my update script. It works great as long as I hard code in the filename of the file that is being saved to the server. When I pass the image creation function a variable for the filename it tells me "invalid filename", although I am echoing it out right before and it looks perfect. Any thoughts? Jason Wong wrote: > > On Sunday 08 December 2002 00:47, Jeremiah Breindel wrote: > > 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"; > > Two things you need to do: > > 1) Plug the value of $rollover_image_url into a browser and satisfy yourself > that the resulting URL does indeed return a valid image, and hence said URL > is valid. > > 2) Plug in a known, static, valid URL (of an image -- actually it can be > anything it doesn't really matter) into your code below, and satisfy yourself > that the your code does work. > > > > > local file on my server using the code below: > > > > > > > > $fc = fopen($image_filename, "wb"); > > > > $file = fopen ($image_url, "rb"); > > > > > > > > if (!$file) { > > > > echo "Unable to open remote file.\n"; > > > > exit; > > > > }else{ > > > > while (!feof ($file)) { > > > >$line = fread ($file, 1028); > > > >fwrite($fc,$line); > > > > } > > > > } > > > > fclose($fc); > > > > fclose($file); > > -- > Jason Wong -> Gremlins Associates -> www.gremlins.biz > Open Source Software Systems Integrators > * Web Design & Hosting * Internet & Intranet Applications Development * > > /* > Chicago law prohibits eating in a place that is on fire. > */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] save file from outside url
On Sunday 08 December 2002 00:47, Jeremiah Breindel wrote: > 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"; Two things you need to do: 1) Plug the value of $rollover_image_url into a browser and satisfy yourself that the resulting URL does indeed return a valid image, and hence said URL is valid. 2) Plug in a known, static, valid URL (of an image -- actually it can be anything it doesn't really matter) into your code below, and satisfy yourself that the your code does work. > > > local file on my server using the code below: > > > > > > $fc = fopen($image_filename, "wb"); > > > $file = fopen ($image_url, "rb"); > > > > > > if (!$file) { > > > echo "Unable to open remote file.\n"; > > > exit; > > > }else{ > > > while (!feof ($file)) { > > >$line = fread ($file, 1028); > > >fwrite($fc,$line); > > > } > > > } > > > fclose($fc); > > > fclose($file); -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* Chicago law prohibits eating in a place that is on fire. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] save file from outside url
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 "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. > */ > 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_gm
Re: [PHP] save file from outside url
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 "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. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php