Need php help

software development

#1

hi, I’m new to all of this, but I’m learning php bit by bit. actually I’ve only written one snippet to randomize some text color on page refresh: http://listenlight.net/hello.php

So I’m trying to use php imagecreate functions, so I can make a favicon.png, also random, but I don’t know how it works. It seems to make the image, but I don’t know how to reference it… get_resource_type($image) returns only “gd”, but it tries to display the image in the browser, so evidently my strange echo( "<link …) string isn’t working, but where it should say “favicon.png” it says “Resource id #1”, so I guess I’m half way there. Am I?


#2

Perhaps you could post your php code, so we could look at it. It sounds like you are referencing the pointer to the file, rather than the file it self.
Silk


#3
<?php function randomFavicon() { $img = imagecreatetruecolor(16, 16); /* Create a blank image */ $bgc = imagecolorallocate($img, rand(1,160), rand(1,160),rand(1,160)); $ec = imagecolorallocate($img, rand(1,160), rand(1,160),rand(1,160)); imagefilledellipse($img, 8, 8, 12, 16, $ec); //header("Content-type: image/png"); imagepng($img); return $img; } ?> <?php $favipng = randomFavicon(); echo( "

"); echo ( " testing " ); ?> testing random favicon function . . .
<?php echo get_resource_type($favipng); ?>

[link]http://listenlight.net/createpng.php[/link] to see the page / source

thanks :slight_smile: —are there [code] markups here?


#4

Well, I just uploaded it to my test bed, and I am getting a black square with a different color circle in the middle each time I refresh the page. So apparently it is working fine. My test bed is using DH’s php ver. 4 with CGI.
Silk


#5

I think I may have figured it out, your png image is being sent directly to the browser instead of being saved to the server.
try
imagepng($img, “filename.png”)
Then in your link you can use filename.png instead of the $favicon

What through me off was the image was displaying but no text or title. So a little rewriting should fix you up.

Here is a quick example that should help get you on the right track.

Testing png <?php $img = imagecreatetruecolor(16, 16); /* Create a blank image */ $bgc = imagecolorallocate($img, rand(1,160), rand(1,160),rand(1,160)); $ec = imagecolorallocate($img, rand(1,160), rand(1,160),rand(1,160)); imagefilledellipse($img, 8, 8, 12, 16, $ec); imagepng($img, "test.png"); ?> testing random favicon function . . .

Silk


#6

awesome, i will try that :slight_smile: