need php help

need php help

Posted by: listenlight
Posted on: 2006-06-25 14:38:00

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?

Re: need php help

Posted by: silkrooster
Posted on: 2006-06-25 15:35:00

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

Re: need php help

Posted by: listenlight
Posted on: 2006-06-25 16:05:00

<?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( "<link rel="icon" href="".$favipng."" type="image/x-icon" /><br /><link rel="shortcut icon" href="".$favipng."" type="image/x-icon" /><br />");

echo ( "<title> testing </title>" );
?>

</head>
<body>
testing random favicon function . . .<br />
<?php
echo get_resource_type($favipng);
?>


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

thanks :) ---are there [code] markups here?

Re: need php help

Posted by: silkrooster
Posted on: 2006-06-25 21:25:00

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

Re: need php help

Posted by: silkrooster
Posted on: 2006-06-25 21:45:00

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.


<html>
<head>
<title>Testing png</title>
</head>
<?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");
?>
<body>
testing random favicon function . . .<br />
<img src = "test.png" >
</body>
</html>

Silk

Edited by silkrooster on 06/25/06 09:47 PM (server time).

Re: need php help

Posted by: listenlight
Posted on: 2006-06-26 00:57:00

awesome, i will try that :-)

Tags: php helpimagefaviconhttpsnippetpngtriesrandomreferencebrowser