Page 1 of 2

drawing news from my site onto a png

Posted: Wed Sep 22, 2004 6:37 pm
by Mini-Me
Alright, I've got the image part working (YAY!).

http://www.minime001.net/test2.php

Code: Select all

<?php
  $img = imagecreatefrompng("test.PNG");
  $white = imagecolorallocate($img, 255,255,255);
  $text = "testing2";
  imagefttext($img, 8, 0, 2, 25, $white, 'fonts/tahoma.ttf', $text, array());
  header('Content-type: image/png');
  imagepng($img);
  imagedestroy($img);
?>
But what I need now is how I could make up a simple (secure) form that would write news to both my index page and this file. I realize how I could initialize the variables and everything, but what I need to know is where they would be submitted to and how they would be read. Could I write them to an xml file? that sounds like the easiest thing to do (if that's possible).

Posted: Wed Sep 22, 2004 7:11 pm
by Breckenridge
Are you using a database to store your data?

Posted: Wed Sep 22, 2004 7:32 pm
by Mini-Me
well, no, but I can if I need to.

Posted: Wed Sep 22, 2004 7:33 pm
by John Cartwright
We'll, it would be the easiest way..

Posted: Fri Sep 24, 2004 10:05 am
by Mini-Me
Ok, yeah, but then how would I do that?

Btw, I got the news to show up on both via a text file:
Image
http://www.minime001.net/news.txt

Code: Select all

<?PHP
$img = imagecreatefrompng("news.PNG");
$newstext = file('news.txt');
$white = imagecolorallocate($img, 255,255,255);
$howfar = 25;

foreach ($newstext as  $line)
{
  $line = trim($line);
  if (substr($line, 0, 4) == "<h3>" )
  {
    // Found Date
    $line = strip_tags($line);
    $currentdate = $line;
  }
  else
  {
    $line = strip_tags($line);
    if (strlen($line) > 3)
    {
      //Found Info
      imagefttext($img, 8, 0, 2, $howfar, $white, 'fonts/tahoma.ttf', $currentdate . ' ' . $line, array());
      $howfar += 15;
    }
  }
}
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>
But it's blurry. And runs off the screen. I don't see that I could do anything about it running off the screen except by shortening the news, but could I somehow convert to a numerical date instead of the month spelled out for that (MM/DD/YY)? If not, I guess I'd have to use separate txt files for both my page and the pic. And in that case, I definitly want a submit thing that would write to both of them. So how would I do all this?
Oh, and the blurry part. Can I make it just write a font like normal text (no blur, only white pixels) or something?

Posted: Fri Sep 24, 2004 12:35 pm
by feyd
you're the one controlling the date information. you can change the format. Here's a hint, use a database.

Posted: Fri Sep 24, 2004 12:41 pm
by vigge89
feyd wrote:you're the one controlling the date information. you can change the format. Here's a hint, use a database.
.... in which you store the unixtime of the post. When you fetch the data, do a

Code: Select all

<?php
$time = date ("d m, Y", $result['time']);
?>
to format the time...

Posted: Fri Sep 24, 2004 1:04 pm
by Mini-Me
Here's a hint, use a database.
I could be wrong, but I'm pretty sure you're not the first one to tell me that. I'm also pretty sure you didn't read this part of my last post:
Ok, yeah, but then how would I do that?
I know how to set up a database, but that's as far as my knowledge goes. So, let me restate all my problems so everyone's on the same page:

• Can I make the text not blurry?
• What do I do with a database? (Completely clueless here. I understand I need one, but nothing else.)
• How can I have a form that will submit the data (How do I write it and what do I write it to?)

Posted: Fri Sep 24, 2004 1:22 pm
by feyd
I'm not here to give full answers. I'm here to guide people, and get them to think on their own.
Can I make the text not blurry?
how is the posted image, blurry? I don't see anything blurry. I see some aliasing on the italised text, it looks perfectly fine otherwise.
What do I do with a database? (Completely clueless here. I understand I need one, but nothing else.)
you store the information you want in this image(s) in seperate fields for the date, and any other categoric type information.
How can I have a form that will submit the data (How do I write it and what do I write it to?)
You create a form processor that validates and stores the information into the database for your image function to retrieve. Alternately, if this is the only place the image gets update information from, you can have this script do the actual creation of the image, so that the server creates once, but uses many times. caching so to speak.

Posted: Fri Sep 24, 2004 1:45 pm
by Mini-Me
I don't expect you to give me a long post of code or anything. I just don't understand a lot of this, and therefore need help with it so I can figure out what to do. ;)

aliasing, yeah. that's what I meant. But you think it looks ok that way? okay, I guess.

when you say I can store the information in fields, .. well... so what's a field? ^^;

"form processor...." yeah, I knew I had to do something like that, I just don't know how to do any of it. How would I validate it? (And when you say validate, you do mean to make sure I'm the only one submitting, etc, right?) How would I have a script create an image that isn't recreated when it's viewed? You mean like I could make a completely separate png that, after created, would function completely separate from the script?

Posted: Fri Sep 24, 2004 2:13 pm
by feyd
aliasing, yeah. that's what I meant. But you think it looks ok that way? okay, I guess.
if the font rendering function supports anti-aliasing, I'd use it. However, the font itself may not support it all that well. If you're feeling a bit eager to learn some graphics stuff, you can search the net for an edge based anti-aliasing routine and attempt to convert it to php. Unless there's a function in the image's I'm not especially aware of. You can have the image functions resample the image, by making it 2 or more times larger, then resample it, which should partly anti-alias it down a bit.
when you say I can store the information in fields, .. well... so what's a field? ^^;
fields = columns. Seperated types, for example, a datetime or int for the date, a varchar for the text to actually drop
"form processor...." yeah, I knew I had to do something like that, I just don't know how to do any of it. How would I validate it?
we've had the pleasure of talking about form validation about 20,000 times. [devnet]+form +valid*[/devnet]
And when you say validate, you do mean to make sure I'm the only one submitting, etc, right?
That's a piece of it. The validation is more to verify that the data being submitted is correct for your set up.
How would I have a script create an image that isn't recreated when it's viewed? You mean like I could make a completely separate png that, after created, would function completely separate from the script?
you save the image to the server's file system, so you can just link to it normally. You may need to have the proper cache settings though. But it does save your server from having to render it for every page query. ... something to think about.

Posted: Fri Sep 24, 2004 2:49 pm
by Mini-Me
alright. I'm starting to see how this'll all come together.

But before I can do anything, I need to get started. I can create a database and a user for it via my control panel for my site (which I usually don't like using). But what do I do after that? I can now (sorta) see how to submit a password to a database, but how would I read it? what would go inside the database? um... what exactly is a database? ^^; I've tried to google a tut about databases, but haven't found anything so far. You know of one I could read?

Posted: Fri Sep 24, 2004 3:31 pm
by John Cartwright
to access your database you can use phpmyadmin

Posted: Fri Sep 24, 2004 4:32 pm
by Mini-Me
aha, found a place where it says fields. For that, I put in 2, right? So what do I do then (where's a newb faq!? T_T )?

Posted: Fri Sep 24, 2004 6:13 pm
by feyd
http://www.oreilly.com/catalog/javadtab ... r/ch02.pdf may help you out a bit.
there have been many many many threads regarding how to set up tables and database design..