PHP in signatures?

Talk about anything in here.
Post Reply
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

PHP in signatures?

Post by EcazS »

Can you have php in the signature? :shock:
I figured with that dynamic image thing you have.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP in signatures?

Post by jacek »

That's a script that makes the image.

Not actually php in my signature as such.
Image
User avatar
Dylan
Posts: 150
Joined: Fri May 06, 2011 7:14 pm

Re: PHP in signatures?

Post 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 ;)
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: PHP in signatures?

Post 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?
User avatar
Dylan
Posts: 150
Joined: Fri May 06, 2011 7:14 pm

Re: PHP in signatures?

Post 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.
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: PHP in signatures?

Post 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 :lol:
User avatar
Dylan
Posts: 150
Joined: Fri May 06, 2011 7:14 pm

Re: PHP in signatures?

Post by Dylan »

That is about the same principle applied :lol:
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: PHP in signatures?

Post by EcazS »

Dylan wrote:That is about the same principle applied :lol:
Oooh! :lol: :lol: :lol:
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP in signatures?

Post 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 :lol:
That's exactly what I have done :?
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: PHP in signatures?

Post 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 :lol:
That's exactly what I have done :?
I was expecting something more complicated XD
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP in signatures?

Post by jacek »

the simplest solution is best ;)
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: PHP in signatures?

Post by EcazS »

It was actually much easier than what I though :lol:
I thought it would be at least 50 lines of code but for me it ended up with 7 :lol:
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP in signatures?

Post 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 !
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: PHP in signatures?

Post by EcazS »

:lol: 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"); 
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP in signatures?

Post 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);	
}
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: PHP in signatures?

Post by EcazS »

I'm guessing str_contains is a function of yours(?)
And what font are you using? Mine looks all blurry :lol:
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP in signatures?

Post 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 :lol:
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 ;)
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: PHP in signatures?

Post by EcazS »

Got them :) Thanks!

You could also just use strpos($var, ":") in this case

Edit,
Oh, that function was using strpos :lol:
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: PHP in signatures?

Post by jacek »

EcazS wrote:You could also just use strpos($var, ":") in this case

Edit,
Oh, that function was using strpos :lol:
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 :lol:
Image
Post Reply