Page 1 of 1
PHP in signatures?
Posted: Fri May 06, 2011 7:14 pm
by EcazS
Can you have php in the signature?
I figured with that dynamic image thing you have.
Re: PHP in signatures?
Posted: Fri May 06, 2011 7:16 pm
by jacek
That's a script that makes the image.
Not actually php in my signature as such.
Re: PHP in signatures?
Posted: Fri May 06, 2011 7:34 pm
by Dylan
http://www.youtube.com/watch?v=qq4OjDdS4eQ
Jacek (BetterPHP) actually has a fantastic tutorial on exactly how the signature is made ^
Basically, as he stated, the script generate the image and he just includes the page
Re: PHP in signatures?
Posted: Fri May 06, 2011 7:43 pm
by EcazS
Ah ok. Before I watch it could I do something similar without the youtube api? Like I do something on my site and it creates the image and blablabla?
Re: PHP in signatures?
Posted: Fri May 06, 2011 7:44 pm
by Dylan
Yup. The YouTube API is merely how he fetches his last signature made. You could make any number of dynamic signatures with or without the API merely by generating an image on your webpage. The tutorial would not be a lost cause as it explains that piece of things as well, you would just have to apply the information in a new context.
Re: PHP in signatures?
Posted: Fri May 06, 2011 7:48 pm
by EcazS
Alrighty then! I'll have a go at it. I guess I just could use the GD library and create an image on my host and then have the filename and img link in my signature
Re: PHP in signatures?
Posted: Fri May 06, 2011 7:49 pm
by Dylan
That is about the same principle applied
Re: PHP in signatures?
Posted: Fri May 06, 2011 7:50 pm
by EcazS
Re: PHP in signatures?
Posted: Fri May 06, 2011 8:09 pm
by jacek
EcazS wrote:Alrighty then! I'll have a go at it. I guess I just could use the GD library and create an image on my host and then have the filename and img link in my signature
That's exactly what I have done
Re: PHP in signatures?
Posted: Fri May 06, 2011 8:58 pm
by EcazS
jacek wrote:EcazS wrote:Alrighty then! I'll have a go at it. I guess I just could use the GD library and create an image on my host and then have the filename and img link in my signature
That's exactly what I have done
I was expecting something more complicated XD
Re: PHP in signatures?
Posted: Fri May 06, 2011 9:52 pm
by jacek
the simplest solution is best
Re: PHP in signatures?
Posted: Fri May 06, 2011 10:51 pm
by EcazS
It was actually much easier than what I though
I thought it would be at least 50 lines of code but for me it ended up with 7
Re: PHP in signatures?
Posted: Fri May 06, 2011 10:56 pm
by jacek
Yeah there is really not much to it, PHP is weirdly good at image things, saying that the function names are a bit of a nightmare !
Re: PHP in signatures?
Posted: Fri May 06, 2011 11:01 pm
by EcazS
Ye.
Just a question, how can I get parts of the text bold? This is how I'm doing it ATM
Imagettftext($img, 10, 0, $pos_x, $pos_y, $color, 'verdana.ttf', "Testing... 123");
Re: PHP in signatures?
Posted: Fri May 06, 2011 11:06 pm
by jacek
I have a separate font file that is bold, and I split the video title on : (with explode). Then call imagettftext twice
This is the code I use ...
if (str_contains(':', $title)){
$parts = explode(':', $title);
$parts[0] = trim($parts[0]) . ':';
$parts[1] = trim($parts[1]);
$size = imagettfbbox(11, 0, './fonts/bold_font.ttf', $parts[0]);
$width = $size[2] - $size[0];
imagettftext($img, 11, 0, 8, 17, $font, './fonts/bold_font.ttf', $parts[0]);
imagettftext($img, 11, 0, $width + 14, 17, $font, './fonts/font.ttf', $parts[1]);
}else{
imagettftext($img, 11, 0, 8, 17, $font, './fonts/font.ttf', $title);
}
Re: PHP in signatures?
Posted: Fri May 06, 2011 11:36 pm
by EcazS
I'm guessing str_contains is a function of yours(?)
And what font are you using? Mine looks all blurry
Re: PHP in signatures?
Posted: Fri May 06, 2011 11:39 pm
by jacek
EcazS wrote:I'm guessing str_contains is a function of yours(?)
See my "three missing string functions" post in the php code section
EcazS wrote:And what font are you using? Mine looks all blurry
I have no idea, but you can download them here
http://betterphp.co.uk/ext/img/banners/fonts/
Post when you have them, that folder needs to be protected
Re: PHP in signatures?
Posted: Fri May 06, 2011 11:41 pm
by EcazS
Got them
Thanks!
You could also just use strpos($var, ":") in this case
Edit,
Oh, that function was using strpos
Re: PHP in signatures?
Posted: Fri May 06, 2011 11:45 pm
by jacek
EcazS wrote:You could also just use strpos($var, ":") in this case
Edit,
Oh, that function was using strpos
yeah, strpos seems like a bit of a un-clean way to do that so I made a function to wrap it until php is fixed