Post: Creating a dynamic signature image
07-28-2011, 04:53 PM #1
<Jimbo>
</Jimbo>
(adsbygoogle = window.adsbygoogle || []).push({});
Recently I've been using this really simple PHP script that will take text from an array (multiple quotes) and then 'render' the php document, so the browser thinks that it is a PNG image, allowing for an image with different text to be displayed every time the page is refreshed. (Check my sig) Smile

All you have to do is create a php file, (for this example, we shall call it 'dynamicsig.php'Winky Winky.

dynamicsig.php
    <?php
// Path to our font you wish to use, Note you will need a font first!
$ttffont = 'arial.ttf';
$fontsize = 10;

// An array of quotes
$arrQuotes = array(
'You can put text here',
'Then a different line of text here',
'And more here',
'And it will display each one randomly on page refresh'Winky Winky;

// And now we need a random selection:
$choice = array_rand($arrQuotes);
// We can get the quote and wordwrap
$quote = wordwrap( $arrQuotes[$choice], 80);

// Create the bounding box of the image:
$bounds = imagettfbbox($fontsize, 0, $ttffont, $quote);

// And we do some simple math to calculate the coords.
$width = $bounds[4] - $bounds[6]; // Top right 'x' minus Top left 'x'
$height = $bounds[3] - $bounds[5]; // Lower right y minus Lower left 'y'

//5 px padding for later
$space = 5;

// Create the true color image:
$image = imagecreatetruecolor($width + $space, $height + $space);

// Now we choose the colours for the background/foreground (text) we wish to use:
$colors['bg'] = imagecolorallocate($image, 0, 0, 0);
$colors['fg'] = imagecolorallocate($image, 255, 255, 255);


// And fill in the background with the color:
imagefilledrectangle($image, 0, 0, $width + $space, $height + $space, $colors['bg']);

// To add some spacing we simulate the upper edge based on the font size and write the text!
$x = $space;
$y = $fontsize + $space;
imagettftext($image, $fontsize, 0, $x, $y, $colors['fg'], $ttffont, $quote);

// The next following steps are what we call the "magic" of the PHP document.
// We tell the browser, "This document is a PNG!" and the browser accepts it as an image.
// So if all goes to plan, We will see results after here:
header('Content-type: image/png'Winky Winky;
imagepng($image);

// And finally remove the image from memory as it's not needed:
imagedestroy($image);
?>


You can edit the font, font colour, font size and the background colour. Smile

font
    $ttffont = 'arial.ttf';

(You will need to download the font that you wish to use, you can find some here: You must login or register to view this content. )

font colour (RGB)
    $colors['fg'] = imagecolorallocate($image, 255, 255, 255);
Tis black Winky Winky

font size
    $fontsize = 10;


Background colour
    $colors['bg'] = imagecolorallocate($image, 0, 0, 0);


And upload that to your hosting, then simply add the link to the page (dynamicsig.php) within img tags.

e.g. [IMG]https://jimbotech.co.uk/testing/dynamicsig.php[/IMG]
or without noparse
You must login or register to view this content.

Simple Smile

(If you are having problems)
Some forms require remote images to have the .png/.jpg/.gif etc. File extention, therefore you will need to create a .htaccess file and to replace an image called dynamicsig.png with dynamicsig.php :p
    RewriteEngine On
RewriteRule dynamicsig.png dynamicsig.php

And simply link to dynamicsig.png instead of dynamicsig.php within [img] tags Smile[/spoiler]

Premade with Einstein quotes (More than 50)
[spoiler][PHP]<?php
// Path to our font you wish to use, Note you will need a font first!
$ttffont = 'arial.ttf';
$fontsize = 10;

// An array of quotes
$arrQuotes = array(
'"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."',
'"Imagination is more important than knowledge."',
'"Gravitation is not responsible for people falling in love."',
'"I want to know God\'s thoughts; the rest are details."',
'"The hardest thing in the world to understand is the income tax."',
'"Reality is merely an illusion, albeit a very persistent one."',
'"The only real valuable thing is intuition."',
'"A person starts to live when he can live outside himself."',
'"I am convinced that He (God) does not play dice."',
'"God is subtle but he is not malicious."',
'"Weakness of attitude becomes weakness of character."',
'"I never think of the future. It comes soon enough."',
'"The eternal mystery of the world is its comprehensibility."',
'"Sometimes one pays most for the things one gets for nothing."',
'"Science without religion is lame. Religion without science is blind."',
'"Anyone who has never made a mistake has never tried anything new."',
'"Great spirits have often encountered violent opposition from weak minds."',
'"Everything should be made as simple as possible, but not simpler."',
'"Common sense is the collection of prejudices acquired by age eighteen."',
'"Science is a wonderful thing if one does not have to earn one\'s living at it."',
'"The secret to creativity is knowing how to hide your sources."',
'"The only thing that interferes with my learning is my education."',
'"God does not care about our mathematical difficulties. He integrates empirically."',
'"The whole of science is nothing more than a refinement of everyday thinking."',
'"Technological progress is like an axe in the hands of a pathological criminal."',
'"Peace cannot be kept by force. It can only be achieved by understanding."',
'"The most incomprehensible thing about the world is that it is comprehensible."',
'"We can\'t solve problems by using the same kind of thinking we used when we created them."',
'"Education is what remains after one has forgotten everything he learned in school."',
'"The important thing is not to stop questioning. Curiosity has its own reason for existing."',
'"Do not worry about your difficulties in Mathematics. I can assure you mine are still greater."',
'"Equations are more important to me, because politics is for the present, but an equation is something for eternity."',
'"If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."',
'"Two things are infinite: the universe and human stupidity; and I\'m not sure about the the universe."',
'"As far as the laws of mathematics refer to reality, they are not certain, as far as they are certain, they do not refer to reality."',
'"Whoever undertakes to set himself up as a judge of Truth and Knowledge is shipwrecked by the laughter of the gods."',
'"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones."',
'"In order to form an immaculate member of a flock of sheep one must, above all, be a sheep."',
'"The fear of death is the most unjustified of all fears, for there\'s no risk of accident for someone who\'s dead."',
'"Too many of us look upon Americans as dollar chasers. This is a cruel libel, even if it is reiterated thoughtlessly by the Americans themselves."',
'"Heroism on command, senseless violence, and all the loathsome nonsense that goes by the name of patriotism -- how passionately I hate them!"',
'"No, this trick won\'t work...How on earth are you ever going to explain in terms of chemistry and physics so important a biological phenomenon as first love?"',
'"My religion consists of a humble admiration of the illimitable superior spirit who reveals himself in the slight details we are able to perceive with our frail and feeble mind."',
'"Yes, we have to divide up our time like that, between our politics and our equations. But to me our equations are far more important, for politics are only a matter of present concern. A mathematical equation stands forever."',
'"Great spirits have always found violent opposition from mediocrities. The latter cannot understand it when a man does not thoughtlessly submit to hereditary prejudices but honestly and courageously uses his intelligence."',
'"The most beautiful thing we can experience is the mysterious. It is the source of all true art and all science. He to whom this emotion is a stranger, who can no longer pause to wonder and stand rapt in awe, is as good as dead: his eyes are closed."',
'"A man\'s ethical behavior should be based effectually on sympathy, education, and social ties; no religious basis is necessary. Man would indeeded be in a poor way if he had to be restrained by fear of punishment and hope of reward after death."',
'"The further the spiritual evolution of mankind advances, the more certain it seems to me that the path to genuine religiosity does not lie through the fear of life, and the fear of death, and blind faith, but through striving after rational knowledge."',
'"Now he has departed from this strange world a little ahead of me. That means nothing. People like us, who believe in physics, know that the distinction between past, present, and future is only a stubbornly persistent illusion."',
'"You see, wire telegraph is a kind of a very, very long cat. You pull his tail in New York and his head is meowing in Los Angeles. Do you understand this? And radio operates exactly the same way: you send signals here, they receive them there. The only difference is that there is no cat."',
'"One had to cram all this stuff into one\'s mind for the examinations, whether one liked it or not. This coercion had such a deterring effect on me that, after I had passed the final examination, I found the consideration of any scientific problems distasteful to me for an entire year."',
'"...one of the strongest motives that lead men to art and science is escape from everyday life with its painful crudity and hopeless dreariness, from the fetters of one\'s own ever-shifting desires. A finely tempered nature longs to escape from the personal life into the world of objective perception and thought."',
'"He who joyfully marches to music rank and file, has already earned my contempt. He has been given a large brain by mistake, since for him the spinal cord would surely suffice. This disgrace to civilization should be done away with at once. Heroism at command, how violently I hate all this, how despicable and ignoble war is; I would rather be torn to shreds than be a part of so base an action. It is my conviction that killing under the cloak of war is nothing but an act of murder."',
'"A human being is a part of a whole, called by us _universe_, a part limited in time and space. He experiences himself, his thoughts and feelings as something separated from the rest... a kind of optical delusion of his consciousness. This delusion is a kind of prison for us, restricting us to our personal desires and to affection for a few persons nearest to us. Our task must be to free ourselves from this prison by widening our circle of compassion to embrace all living creatures and the whole of nature in its beauty."',
'"Not everything that counts can be counted, and not everything that can be counted counts."',
'Awesome faceynamic Einstein Quotes ~Jimbo'Winky Winky;

// And now we need a random selection:
$choice = array_rand($arrQuotes);
// We can get the quote and wordwrap
$quote = wordwrap( $arrQuotes[$choice], 80);

// Create the bounding box of the image:
$bounds = imagettfbbox($fontsize, 0, $ttffont, $quote);

// And we do some simple math to calculate the coords.
$width = $bounds[4] - $bounds[6]; // Top right 'x' minus Top left 'x'
$height = $bounds[3] - $bounds[5]; // Lower right y minus Lower left 'y'

//5 px padding for later
$space = 5;

// Create the true color image:
$image = imagecreatetruecolor($width + $space, $height + $space);

// Now we choose the colours for the background/foreground (text) we wish to use:
$colors['bg'] = imagecolorallocate($image, 0, 0, 0);
$colors['fg'] = imagecolorallocate($image, 255, 255, 255);


// And fill in the background with the color:
imagefilledrectangle($image, 0, 0, $width + $space, $height + $space, $colors['bg']);

// To add some spacing we simulate the upper edge based on the font size and write the text!
$x = $space;
$y = $fontsize + $space;
imagettftext($image, $fontsize, 0, $x, $y, $colors['fg'], $ttffont, $quote);

// The next following steps are what we call the "magic" of the PHP document.
// We tell the browser, "This document is a PNG!" and the browser accepts it as an image.
// So if all goes to plan, We will see results after here:
header('Content-type: image/png'Winky Winky;
imagepng($image);

// And finally remove the image from memory as it's not needed:
imagedestroy($image);
?>[/PHP][/spoiler]

If you'd like me to host your quotes... Just ask. :p[/img]

The following user thanked <Jimbo> for this useful post:

JakeM

The following user groaned <Jimbo> for this awful post:

07-28-2011, 05:27 PM #2
Winning
Former Staff
Holy fuck tits that is cool.
07-28-2011, 07:21 PM #3
looks like a C&P from hf's php section

The following user thanked CodingNation for this useful post:

The following 3 users groaned at CodingNation for this awful post:

<Jimbo>,
07-28-2011, 08:06 PM #4
<Jimbo>
</Jimbo>
Originally posted by Winning View Post
Holy fuck tits that is cool.

LOL, I cannot dissagree. :p

Originally posted by KingDeath360 View Post
looks like a C&P from hf's php section

Stop trying to flame,
1) I am not one of the mindless fools who sees posts on another forum and copies them here for 'rep' (I don't actually have a HF account. No )
2) This is a script I came accross long before HF came into the scene, and have used parts in a lot of my sites since then.

If you see a post with any resembelance to this on any other forum, please link me in a PM so I can check it out, but as a matter of fact... The only copy and paste here from a website are the Einstein quotes.

P.S.
You cannot spell You must login or register to view this content. .
Last edited by <Jimbo> ; 07-28-2011 at 08:12 PM.

The following user thanked <Jimbo> for this useful post:

The following 2 users groaned at <Jimbo> for this awful post:

CodingNation,
07-29-2011, 01:00 AM #5
Originally posted by lt
LOL, I cannot dissagree. :p


Stop trying to flame,
1) I am not one of the mindless fools who sees posts on another forum and copies them here for 'rep' (I don't actually have a HF account. No )
2) This is a script I came accross long before HF came into the scene, and have used parts in a lot of my sites since then.

If you see a post with any resembelance to this on any other forum, please link me in a PM so I can check it out, but as a matter of fact... The only copy and paste here from a website are the Einstein quotes.

P.S.
You cannot spell You must login or register to view this content. .

How come I csn view your site? You must login or register to view this content.
It never worked
07-29-2011, 03:28 AM #6
<Jimbo>
</Jimbo>
It occationally goes down, or I will be editing the file you're trying to access. Smile

Originally posted by marrcc View Post
How come I csn view your site? You must login or register to view this content.
It never worked

The following user groaned <Jimbo> for this awful post:

CodingNation
08-01-2011, 08:05 PM #7
Default Avatar
Oneup
Guest
Originally posted by lt
LOL, I cannot dissagree. :p


Stop trying to flame,
1) I am not one of the mindless fools who sees posts on another forum and copies them here for 'rep' (I don't actually have a HF account. No )
2) This is a script I came accross long before HF came into the scene, and have used parts in a lot of my sites since then.

If you see a post with any resembelance to this on any other forum, please link me in a PM so I can check it out, but as a matter of fact... The only copy and paste here from a website are the Einstein quotes.

P.S.
You cannot spell You must login or register to view this content. .


Strange:
You must login or register to view this content.
You must login or register to view this content.


At least 2 that say otherwise. Him saying it looks like a c/p isn't a flame, if you think that is then you really dont know what one is. But figures that 2 sites have the same thing

The following 2 users groaned at Oneup for this awful post:

<Jimbo>,
08-01-2011, 08:22 PM #8
<Jimbo>
</Jimbo>
1) You've just linked me to two other forums.
2) Can you not read, You must login or register to view this content. I don't claim this script (although if you weren’t :derp: you'd know that it's replicate able in a few minutes from scratch).
3) I did write this tutorial, and EVEN provided a script with a fair amount of Einstein quotes.
4) The two links you provided were C&Ps of each other EXACTLY.
5) I Copy and pasted the script from my computer, as I have been using this for at least 3/4 months. And therefore could not link you to the site I got it from; however it was some php forum.
6) If I say it's flaming, it is flaming. He insulted me by basically stating that I am as much a derp as the 12 year olds that spend their time C&Ping for 'rep'.
7) Feel free to go to the other forum and ask for this: You must login or register to view this content.
Cool Man (aka Tustin) I have updated this to work with more forum softwares, by using the .htaccess file; I did not see that on the other sites.
9) Your post didn't make very much sense at all.
10) Read the OP before jumping in and breaking the rules.

Smile
Originally posted by UP View Post
Strange:
[Removed Links]

At least 2 that say otherwise. Him saying it looks like a c/p isn't a flame, if you think that is then you really dont know what one is. But figures that 2 sites have the same thing

The following user thanked <Jimbo> for this useful post:

The following user groaned <Jimbo> for this awful post:

08-02-2011, 03:00 AM #9
Pichu
RIP PICHU.
This is epic...
08-02-2011, 03:21 AM #10
Default Avatar
Oneup
Guest
Originally posted by lt
1) You've just linked me to two other forums.
2) Can you not read, You must login or register to view this content. I don't claim this script (although if you weren’t :derp: you'd know that it's replicate able in a few minutes from scratch).
3) I did write this tutorial, and EVEN provided a script with a fair amount of Einstein quotes.
4) The two links you provided were C&Ps of each other EXACTLY.
5) I Copy and pasted the script from my computer, as I have been using this for at least 3/4 months. And therefore could not link you to the site I got it from; however it was some php forum.
6) If I say it's flaming, it is flaming. He insulted me by basically stating that I am as much a derp as the 12 year olds that spend their time C&Ping for 'rep'.
7) Feel free to go to the other forum and ask for this: You must login or register to view this content.
Cool Man (aka Tustin) I have updated this to work with more forum softwares, by using the .htaccess file; I did not see that on the other sites.
9) Your post didn't make very much sense at all.
10) Read the OP before jumping in and breaking the rules.

Smile


Sorry but I post sources, if this forum is against that then there is a problem, but then again 99% of this community steals things anyways.

Also like I said if you feel that was a flame then you have a problem. Usually the ones that take a defensive stance and start the flaming generally have something to hide. But it just so happens that something that is "easily able to be replicated" was done in such a manner that is was exactly the same. Go figure. YOU are claiming this wasn't a CP then you go ahead and say it is

Originally posted by another user
And therefore could not link you to the site I got it from; however it was some php forum.
.

Wish there weren't so many script kiddies on this forum but that's pretty inevitable.

The following 2 users groaned at Oneup for this awful post:

<Jimbo>,

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo