PDA

View Full Version : Dynamic Sig or Image


72dpi
01-06-2006, 06:28 AM
Hi All,

here is a hack to make a dynamic signature (Using the GD Library).
You will need a .png image for the background, and a font of choice.
Please also note that i have simplified the path to all reside in the same directory.
If you want them to reside in others, just change the paths like:

$string2 = "http://www.your.com/images/dude.png"; // name of background image

Here is the code to make your dynamic sig:

Save this code as create_sig.php

<?php
header("Content-type: image/png");
$string1 = $_GET['text'];
$string2 = "dude.png"; // name of image
$im****= imagecreatefrompng($string2); // we create the image from our string2 variable
$text = imagecolorallocate($im, 0, 0, 0);**//Text Color**** RGB Values

// * note, i am using the font hooge_055.ttf
imagefttext ($im, 6, 0, 5, 20, $text, "hooge_055.ttf", $string1 , array());
// 6=Font Size**0=Angle**5=Dist from left** 20=Dist from top
imagepng($im); //Draws the image
imagedestroy($im);**//Finish the image.
?>


Now, from your template you can call it like:
<img src="create_sig.php?text=<?php echo $thecategory['name']; ?>" alt="<?php echo $urlcategoryname ?>" />

This is a totally simplified variant of an image countdown i am using on my wedding website, where I have the "days until", and a random background image. This simplified version shown here is from
http://php.mirrors.ilisys.com.au/manual/en/ref.image.php , where I have just uploaded my extended version (if they allow it =)

I will be modifying this to show a pixel dude welcoming visitors into the website. Then when you login, he will say your name, with random comments, wearing random clothes etc.

If anyone also knows how to add this to the login panel, PLEASE post up here, i think many people would love to add something like this. <-- Unless I am o the only dork here (No comments please =)

have fun&#33;

Terminator1138
01-06-2006, 05:26 PM
Basically, get me if I&#39;m wrong, this allows a person to add an image to say a signature in a forum etc, that is pulled from a dynamic site?

Similar to say this site?
http://www.danasoft.com/

HeavyEddie
01-06-2006, 10:50 PM
Wow, is it possible to modify it so it would display the title of the latest news article?

Although we haven&#39;t implemented our blog yet, it would be cool to have this display the title of someone&#39;s latest blog too.

72dpi
01-07-2006, 01:14 AM
Hi Terminator,

Well, kinda similar, but I have just implemented it to create a new "Banner Graphic". Say for example, I am in the home section. Well, i don&#39;t want your eveyday "Home" title to be written as a <h1> or a <span="heading"> type of way.
I designed my website to have nice header graphics, so when you go to Image gallery, or Contact us, there is a graphic, with my font of choice in my graphic style. This was the only thing stopping me from putting my wedding website on to subdreamer. I didn&#39;t want to have to make each graphic a "Custom Plugin". So, i created a php page called "create.php". this now creates a beautiful header graphic, instead of the usual: <?php echo &#036;thecategory[&#39;name&#39;]; ?>

You can easily try this on the wave1.php skin on subdreamer light.
I will try & release a skin soon that uses this functionality, as well as a header graphic that changes according to which section you are in.

Heavy Eddie, it would be very simle to do what you want. the only thing you would need to do would be put an if-else statement on the image, so :

&#60;img src=&#34;create_sig.php?text=&#60;?php if**&#40;&#036;thecategory&#91;&#39;name&#39;&#93; == &#34;&#34;&#41;**{ echo &#34;No Article Title&#34;; } else {echo &#036;thecategory&#91;&#39;name&#39;&#93;; }
?&#62;&#34; alt=&#34;&#60;?php echo &#036;thecategory&#91;&#39;name&#39;&#93;; ?&#62;&#34; /&#62;
<-- This needs checking, but gives you the basic idea. you need to find out the variable name for your title. Hopefully one of the crew here might give us a definitive list of variable name to use?

(I think I need to take this discussion to subdreamer.org)

Any thoughts?

HeavyEddie
01-07-2006, 01:36 AM
Hmmm... I thought this was subdreamer.org :)

I&#39;m going to be able to use this for sure. I&#39;ve been struggling with how exactly I want my page headers to look. This opens the doors very wide.

I do have a couple of other questions then...
Will this be resource intensive? If so, is there a way to cache the image?

Is there a way to use this as a straight PHP with a db call to gather the user name and their last post from the forum or blog? I think folks would love to use part of their latest blog as a sig anywhere. Sorry if I got a little off the SD topic :)

72dpi
01-07-2006, 01:58 AM
Hi heavy, not sure about the dbcall bit, but definately could be a cached item. This would perhaps need a bit of design to implement a "clear cache" system.
Read more about chaching these images here:
http://www.design-ireland.net (http://www.design-ireland.net/index.php?http%3A//www.design-ireland.net/graphics/imagery-16.php)
and :
http://www.alistapart.com/d/dynatext/heading.php.txt
I will try & implement this tonight.


I dont think it is that intensive if you have just 1 instance of using the image creation, but yeah, def worth playing with.


Have a play, post ur results up please&#33;

PS, yeah, i was half asleep when i wrote, i thought i was on .com, not .org heh heh

Terminator1138
01-07-2006, 05:38 AM
I would like to see it in action to give me a visual if possible...might work for an idea

72dpi
01-07-2006, 08:16 AM
http://www.72dpi.net.au/wedding2

this is currently under development, as i am converting my php site onto subdreamer.
i nearly have it the way I want, next up is the dynamic header images.

Please note the section names (images) are created dynamically. i am trying to make the script work to cache/create them as we speak.

if anyone knows a perfect way to do this, please email up, or i will keep trying =)

HeavyEddie
01-07-2006, 12:59 PM
<div class='quotetop'>QUOTE(Terminator1138 &#064; Jan 7 2006, 12&#58;38 AM) 2705</div>
I would like to see it in action to give me a visual if possible...might work for an idea
[/b]

If you mean a visual of the sig item with a blog entry, this is my initial thought. Giving folks at your site a little diddy like this would be pretty cool.

[attachmentid=231]

HeavyEddie
01-07-2006, 02:51 PM
As for the title image...
I&#39;ve almost got it working but it doesn&#39;t seem to be pulling the title properly.

This...
&#60;img src=&#34;create_sig.php?text=&#60;?php echo &#036;thecategory&#91;&#39;name&#39;&#93;; ?&#62;&#34; alt=&#34;&#60;?php echo &#036;urlcategoryname ?&#62;&#34; /&#62;
Produces a blank image

However, if I hardcode the text it will work. For instance, this produces "Dude" in the image...
&#60;img src=&#34;create_sig.php?text=&#60;?php echo &#34;Dude&#34;; ?&#62;&#34; alt=&#34;&#60;?php echo &#036;urlcategoryname ?&#62;&#34; /&#62;

IGGY
01-08-2006, 02:01 AM
I got it to work to welcome users to the site:

http://home.iggycorp.com

72dpi
01-08-2006, 10:23 AM
Thats cool iggy. Thats what i want to do next.

Does it change when the user logs in to welcome their username?

Heavy Eddie, i would assume that the name is not showing up as the variable username may not be dclared on the page. I have subdreamer pro (and this method does not work), yet on my wedding site, it works. I think may have something to do with the mod rewrite or friendly url&#39;s?

Anyhow, i would love a definitve variables list. ANy pro&#39;s out there care to share the variable names & what they refer to?,

Also, i wil try & get this cache problem sorted (if image exists show saved, else create new one).

IGGY
01-08-2006, 06:33 PM
<div class='quotetop'>QUOTE(72dpi &#064; Jan 8 2006, 02&#58;23 AM) 2735</div>
Thats cool iggy. Thats what i want to do next.

Does it change when the user logs in to welcome their username?

[/b]

Yeah, when the user logs in it says, "Welcome back username&#33;".

I&#39;m working on getting it to display other info like, You need to register, or your wong username or pass word.

What I couldn&#39;t figure out though is how do you get separate lines out of this. maybe 2 lines or wraping text?

72dpi
01-09-2006, 12:04 AM
hey iggy,
Well here is some ideas:

&#60;?php
echo nl2br&#40;&#34;foo isn&#39;t&#092;n bar&#34;&#41;;
?&#62;
Produces:
foo isn&#39;t&#60;br /&#62;
bar
From: http://au2.php.net/nl2br

or:
&#60;?php
&#036;text = &#34;The quick brown fox jumped over the lazy dog.&#34;;
&#036;newtext = wordwrap&#40;&#036;text, 20, &#34;&#60;br /&#62;&#092;n&#34;&#41;;
echo &#036;newtext;
?&#62;

Produces:
The quick brown fox&#60;br /&#62;
jumped over the lazy&#60;br /&#62;
dog.

from: http://au3.php.net/wordwrap


Is that what you mean?
Also, head over to http://www.phpfreaks & sign up to know all about php. is a great site. & php.net is an invaluable resource for coders.

Hope you post your code matey&#33; ;)

72dpi
01-09-2006, 12:39 AM
Hi Iggy, are us using similar to this?

&#60;?php

&#036;welcometext = &#34;Hey duder, you really should login if you want to view the website, OK?&#34;;
&#036;welcomenewtext = wordwrap&#40;&#036;welcometext, 20, &#34;&#60;br /&#62;&#092;n&#34;&#41;;

if&#40;&#036;usersystem&#41;
**{
****if&#40;&#036;userinfo&#91;&#39;loggedin&#39;&#93;&#41;
****{
********echo &#39;hello &#39;. &#036;userinfo&#91;&#39;username&#39;&#93;&#59;
**** }
**** else
**** {
****echo &#036;welcomenewtext;
**** }
** }
?&#62;

If not, hope someone can see benefits of using this...

IGGY
01-09-2006, 03:01 AM
Yeah, I&#39;m actually using something very similar.

I&#39;m using this but with the global stuff

if&#40;&#036;usersystem&#41;
**{
****if&#40;&#036;userinfo&#91;&#39;loggedin&#39;&#93;&#41;
****{
********echo &#39;hello &#39;. &#036;userinfo&#91;&#39;username&#39;&#93;;
**** }
**** else
**** {
****echo &#036;welcomenewtext;
**** }
** }

global &#036;DB, &#036;userinfo, &#036;usersystem, &#036;regpath;

I&#39;m not actually sure if I need those or not.

By the way I sent you PM

HeavyEddie
01-10-2006, 07:45 PM
As an exercise in learning how to build a plugin and get something I want... I&#39;ve been playing with turning this into a plugin. I&#39;m almost there, but I&#39;m not sure how to get around my problem.

When I run this as a plugin it looks like it tries to create the image but it comes out as garbage. I assume this has something to do with the fact that SD has a header open for html not a binary. (because that is what it says) How can I make this work?

Code and an example of output below.

&#60;?php

if&#40;&#33;defined&#40;&#39;IN_SUBDREAMER&#39;&#41;&#41;
****die&#40;&#39;Hacking attempt&#33;&#39;&#41;;


// Get the category name... not so hard when you take it from the breadcrumb plugin &#58;&#41;
global &#036;DB;
&#036;cat = &#036;DB-&#62;query_first&#40;&#34;SELECT parentid, name FROM &#34; . TABLE_PREFIX . &#34;categories WHERE categoryid=&#39;&#036;categoryid&#39;&#34;&#41;;


// Get the plugin settings... again, taken from breadcrumb
&#036;getsettings**= &#036;DB-&#62;query&#40;&#34;SELECT title, value FROM &#34; . TABLE_PREFIX . &#34;pluginsettings WHERE pluginid = 901 ORDER BY displayorder&#34;&#41;;
while&#40;&#036;setting = &#036;DB-&#62;fetch_array&#40;&#036;getsettings&#41;&#41;
****{
**********&#036;settings&#91;&#036;setting&#91;&#39;title&#39;&#93;&#93; = &#036;setting&#91;&#39;value&#39;&#93;;
****}

// Generate the graphic... this part from 72dpi with a few little changes by me
header&#40;&#34;Content-type&#58; image/png&#34;&#41;;
&#036;string2 = &#34;title.png&#34;; // name of image
&#036;im****= imagecreatefrompng&#40;&#036;settings&#91;&#39;Default Image&#39;&#93;&#41;; // we create the image from our the plugin variable
&#036;text1 = imagecolorallocate&#40;&#036;im, 129, 129, 129&#41;;**//Text Color**** RGB Values
&#036;text2 = imagecolorallocate&#40;&#036;im, 255, 255, 255&#41;;**//Text Color**** RGB Values

// * note, i am using the font arialbd.ttf
imagefttext &#40;&#036;im, 18, 0, 27, 40, &#036;text1, &#34;arialbd.ttf&#34;, &#036;cat&#91;&#39;name&#39;&#93; , array&#40;&#41;&#41;;
imagefttext &#40;&#036;im, 18, 0, 25, 38, &#036;text2, &#34;arialbd.ttf&#34;, &#036;cat&#91;&#39;name&#39;&#93; , array&#40;&#41;&#41;;
// 6=Font Size**0=Angle**5=Dist from left** 20=Dist from top
imagepng&#40;&#036;im&#41;; //Draws the image
imagedestroy&#40;&#036;im&#41;;**//Finish the image.
?&#62;


This is the errors that come back...
Warning&#58; Cannot modify header information - headers already sent by &#40;output started at /home/xxxx/public_html/xxxx/skins/geochums/geochums3.php&#58;3&#41; in /home/xxxx/public_html/xxxx/plugins/p901_graphic_title/titlepic.php on line 23

Warning&#58; imagefttext&#40;&#41;&#58; Could not find/open font in /home/xxxx/public_html/xxxx/plugins/p901_graphic_title/titlepic.php on line 30

Warning&#58; imagefttext&#40;&#41;&#58; Could not find/open font in /home/xxxx/public_html/xxxx/plugins/p901_graphic_title/titlepic.php on line 31

LARGE AMOUNT OF GARBAGE NEXT

IGGY
01-10-2006, 08:24 PM
I actually tried making a plugin out of this too. I had it 90% done, but it woul&#39;d work for some reason as well. So I abandoned it.

HeavyEddie
01-10-2006, 09:28 PM
I&#39;m getting close... I can feel it :) I think the URL below may be the answer.
http://us3.php.net/manual/en/function.ob-start.php

HeavyEddie
01-12-2006, 01:54 AM
Any ideas on this folks? I&#39;ve gone ahead and attached my plugin in it&#39;s current state. It is sooooooo close. I only need to figure out how to convert the color from hex to RGB. Oh yeah... this little issue with not actually generating a graphic too :)

I&#39;m confident it has to deal with the header (http://us3.php.net/manual/en/function.header.php). The information from the PHP Manual says...
Note: As of PHP 4, you can use output buffering to get around this problem, with the overhead of all of your output to the browser being buffered in the server until you send it. You can do this by calling ob_start() and ob_end_flush() in your script, or setting the output_buffering configuration directive on in your php.ini or server configuration files.[/b]
Looking at the information on ob_start() (http://us3.php.net/manual/en/function.ob-start.php) and ob_end_flush() (http://us3.php.net/manual/en/function.ob-end-flush.php) hasn&#39;t help much either.

Hey pros&#33; Can throw a newb a bone :)

HeavyEddie
01-16-2006, 12:16 AM
Hey guys, I got the graphic title to work... I put the plugin here (http://www.subdreamer.org/forum/index.php?showtopic=517).