Shoutbox

[PHP] Dynamic image help - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [PHP] Dynamic image help (/showthread.php?tid=55422)

[PHP] Dynamic image help by Luigi on 01-31-2006 at 06:48 PM

I've nevere scripted in php, but I always wanted to learn, now I decided to start doing something serious: the problem is that I think it's TOO serious for me :P
However, here's what I would like to do:
I would like a php dynamic signature and I searched for some tutorial with google, but I didn't find anything.
I would like to know how to get a text from a file (reading for example line 1 and write it at x,y; then read line 3 and write it at x2,y2) and drawing it over the image, possibly using a specific ttf font (uploaded on the web space, of course).
Thanks in advantege :)


Edit: got imagettftext, this is the command for writing thext, I think :O (Genius Inside :P )


RE: [PHP] Dynamic image help by L. Coyote on 01-31-2006 at 07:42 PM

You can read all about image functions at the PHP manual.

There are many tutorials out there that explain how to do this. A simple search for php "dynamic images" tutorial got me a lot of good articles.


However, I'd suggest you learn the language first. Going for a script like this without knowing the basic language structure is like trying to write a book in Chinese without having studied it.


RE: [PHP] Dynamic image help by Luigi on 01-31-2006 at 07:46 PM

Yes I know it will be very difficult, but I started like this when I decided to learn mIRC scripting, it will take some weeks, but I like the hard way :D
Thanks for the help ;)


RE: [PHP] Dynamic image help by hmaster on 01-31-2006 at 08:10 PM

To read specific lines from a file, you can use something like

code:
$file = file('pathtoyourfile.txt');
$line1 = $fiile[0];
$line3 = $file[2];

Then use imagettftext to add the text in each position. You can specify the font, x and y positions in that tag.

Maybe not.
RE: RE: [PHP] Dynamic image help by Luigi on 01-31-2006 at 08:25 PM

Ok, I'm getting something now :D
It creates the empty blue image, and then loads the png I've made, but then it doesn't write any text.
Here's the code I used:

code:
$white = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$green = imagecolorallocate($im, 0, 255, 0);
$black = imagecolorallocate($im, 0, 0, 0);
// Font
$font == "visitor.ttf";
$text == "Hello World";
// Drawing text
imagettftext($im, 12, 0, 10, 20, $white, $font, $text);
Any idea?
(Edit: Here's the image)

SOLVED: == instead of =, damn mIRC scripting :D
RE: [PHP] Dynamic image help by -dt- on 02-01-2006 at 02:00 AM

quote:
Originally posted by hmaster
To read specific lines from a file, you can use something like

code:
$file = file('pathtoyourfile.txt');
$line1 = $fiile[0];
$line3 = $file[2];

Then use imagettftext to add the text in each position. You can specify the font, x and y positions in that tag.

You'll need fopen wrappers or whatever enabled.
:-/ why do you need fopen wrappers enabled to read from a localfile? .... fopen wrappers are what let you access urls like files. they dont disable local file reading.
RE: [PHP] Dynamic image help by Luigi on 02-01-2006 at 07:47 PM

Thanks to all for the help, I've done something good, but now I'm blocked here.
blah.org/gne.php?number=1.txt
my php read the first line of the file 1.txt (that is the name of an image) and it SHOULD load that image and put it on the file, here's the code I used:

code:
$file = file($_GET[number]);
$ua = imagecreatefrompng($file[0]);
$uswidth = imagesx($ua);
$usheight = imagesy($ua);
imagecopy($im, $ua, 5, 2, 0, 0, $uswidth, $usheight);
(im is already defined)

but it doesn't return any image.
Is this because when it reads the first line, it gets image.png(return)?

And another problem I have, is that it doesn't show any text using the imagettftext, could it be because I'm loading 2 images ($im, and then $ua)?
code:
$font = "/wp-content/visitor.ttf";
$white = imagecolorallocate($im, 255, 255, 255);
imagettftext($im, 10, 0, 55, 5, $white, $font, 'blah blah blah');


Thanks :)
RE: [PHP] Dynamic image help by hmaster on 02-01-2006 at 08:57 PM

quote:
Originally posted by -dt-
:-/ why do you need fopen wrappers enabled to read from a localfile? .... fopen wrappers are what let you access urls like files. they dont disable local file reading.
woops my bad!

quote:
Originally posted by Luigi
Thanks to all for the help, I've done something good, but now I'm blocked here.
blah.org/gne.php?number=1.txt
my php read the first line of the file 1.txt (that is the name of an image) and it SHOULD load that image and put it on the file, here's the code I used:
code:
$file = file($_GET[number]);
$ua = imagecreatefrompng($file[0]);
$uswidth = imagesx($ua);
$usheight = imagesy($ua);
imagecopy($im, $ua, 5, 2, 0, 0, $uswidth, $usheight);
(im is already defined)

but it doesn't return any image.
Is this because when it reads the first line, it gets image.png(return)?

And another problem I have, is that it doesn't show any text using the imagettftext, could it be because I'm loading 2 images ($im, and then $ua)?
code:
$font = "/wp-content/visitor.ttf";
$white = imagecolorallocate($im, 255, 255, 255);
imagettftext($im, 10, 0, 55, 5, $white, $font, 'blah blah blah');


Thanks :)
Try with the apostrophes $_GET['number']

RE: [PHP] Dynamic image help by Luigi on 02-02-2006 at 07:53 PM

Nothing changes :(