Forum Settings
Forums

saka's minimal signature script (with merged anime/manga feeds)

New
May 10, 2009 11:13 AM
#1

Offline
May 2008
4052
After marveling at all the spaghetti code floating around, I decided to make a refined minimal script to complement shiteiru/erhgeiz's script.

This script should work as a drop-in replacement for that script, except without all the obscure token nonsense that plagues it. The file is designed mostly as a learning excercise for people new to php, and because of that I have commented it heavily. I have tried to mark important areas with UPPERCASE comments, so look for those for configuration purposes.

For now I'm just giving you the files , but I plan to post a full tutorial soon. At minimum, you will need a background image ("background.png" default) and a font *.ttf file in the same directory as this script and upload them all to your webserver. You can find great custom fonts at http://dafont.com/

Here's the code:

Download saka's minimal script (with anime/manga merged and example files)
(last updated October 3rd, 2015 - v1.58)

Important Notes on image caching:
  • This script contains support for simple image caching. Your script will get accessed every time someone looks at a forum thread you posted in.... and that can mean thousands of hits in a short time period. Caching basically just makes it so the script doesn't have to build the signature from scratch every single time. Instead it just outputs a reasonably new copy of what it's created previously.

    In order to store that temporary image of your sig, the script will need a writable location to save it. I recommend making an empty directory named 'cache' and making sure it's writable on the server (chmod 777 or change file properties using an FTP client like FileZilla). I've put an empty directory in the zip for you, but you'll need to set the permissions on it after you upload.

    The caching greatly reduces stress on MAL and your server, and makes it much faster. Please use it! (see comments in the script to see how it works, or ask here if you're unsure how to set it up for your server)

  • Image displaying but not updating? By default, the image only updates at most every ten minutes, but for testing/building your sig you may want to set the cache time to 0 minutes so you can see your changes immediately. The script checks its own modification time so re-uploading the php file or deleting the cache image will force it to refresh... but if you are trying different fonts or background images it wouldn't be aware of that. Once your sig is working how you'd like, remember to put the cache time back to something reasonable! I recommend 10-15 minutes.


Where do I point my signature?
The full address to your signature script once you upload it will be something like:
http://yourdomain/path/to/your/signature.png/index.php

...and that address will output your signature image directly (updating in real time if the cache time hasn't passed). The folder is confusingly named "signature.png" to satisfy security checks that the MAL forum uses to make certain attacks more difficult. To avoid incurring the wrath of the security gods, just leave the "/index.php" off the end of the address, giving you forum bbcode that looks like:
[img]http://yourdomain/path/to/your/signature.png[/img]


Alternatively, you can link to the saved image, for example...
[img]http://yourdomain/path/to/your/signature.png/cache/sig.png[/img]

...and have a cronjob visit the sig.php location every few minutes to keep the image current. Loading the cache image directly is faster, and is less likely to make some free hosts mad, so I recommend this indirect method when possible. If you use MAL Updater, you can use the PHP Signature plugin instead of a cronjob (and your sig will update whenever you watch anime).
sakaOct 3, 2017 12:14 PM

I am a banana.
Reply Disabled for Non-Club Members
Pages (9) [1] 2 3 » ... Last »
May 10, 2009 1:35 PM
#2

Offline
Feb 2008
4295
Looks good. Are you going to post this in the creative corner or allow shiteiru/'whatever his name is now' to update his post?
May 10, 2009 1:37 PM
#3

Offline
May 2008
4052
kuroshiroi said:
Looks good. Are you going to post this in the creative corner or allow shiteiru/'whatever his name is now' to update his post?

he knows about it... i don't really mind either way.

I am a banana.
May 10, 2009 2:59 PM
#4

Offline
May 2007
3946
lol@people who change nicks frequently.
May 10, 2009 6:04 PM
#5

Offline
Feb 2009
150
I dont feel like learning more stuff so i'll keep my bombarding sig :)
May 11, 2009 12:40 AM
#6

Offline
Sep 2007
2171
Tried it out, really nice. Only things it is missing are transparency and title cutter I think :)

edit: just typo fix, I'm still half-asleep...
SunyiNyufiMay 11, 2009 12:50 AM
May 11, 2009 5:59 AM
#7

Offline
Apr 2008
78
lol@people who change nicks frequently.


Tell me...what's bad or funny about changing ones nick ? ^^ I don't get it.

Anyway, nearly every nick used online is self given and holds absolutely no meaning, so whats the point in "not changing it" ?

I don't really mind if people know me or not.
Who cares in the first place?

Btw. who cares which episodes have been watched by nick xyz in the last 4 or 5 hours (except you know him and want to know desperately what he was watching)...not me

The only purpose i made this sig thingie in the first place, was that custom sigs look a lot better than the mal generated ones. Besides that, there is absolutely no point (at least in my opinion) for creating self updating sigs.

Just my 2 cents.

Last not least: i don't want everyone to know what i'm doing where and why. So...in every community i'am i do indeed have a different nick.
Call it paranoia........who cares anyway ^^

Now go on and do something that matters like learning japanese or so :-D
Luck is the last dying wish of those who wanna believe that winning can happen by accident, sweat on the other hand is for those who know it's a choice, so decide now because destiny waits for no man.
May 11, 2009 6:52 AM
#8
Offline
Dec 2008
4167
Uh, it was screwing up on the transparencys for my sig, should add that
imagealphablending($sigimage,true);
imagesavealpha($sigimage,true);

thingy

Not that I know anything though, took me like 10 minutes to figure out where the heck to put it! lol
May 11, 2009 6:58 AM
#9

Offline
May 2008
4052
SunyiNyufi said:
Tried it out, really nice. Only things it is missing are transparency and title cutter I think :)


transparent overlays should work without imagealphablending() as long as only 24-bit png is used. I guess I could add an overlay by default or something, but I figured that had been covered enough already elsewhere. I might be wrong though.

I'll add in a title truncation line when I get back tonight.

ehrgeiz said:
The only purpose i made this sig thingie in the first place, was that custom sigs look a lot better than the mal generated ones. Besides that, there is absolutely no point (at least in my opinion) for creating self updating sigs.

Just my 2 cents.

yeah that's pretty much my opinion also... but there should be easier ways to make them look nice. It would be best if Xinil might get to expanding the existing sig system to have at least a few different fonts.

I just wanted to give people some options in the hosted php department.

I am a banana.
May 11, 2009 7:09 AM
Offline
Dec 2008
4167
Cutting after however many characters would be nice to add too, cause I'm sure it'll come up

edit: love this code lol, theres barely anything with it so its easy for me to figure out how to add all the stuff like cutting on my own. Nice to have options, thanks for it.
123114334dMay 11, 2009 7:15 AM
May 18, 2009 12:51 AM

Offline
May 2008
4052
Text 'cutting' and image overlays are now supported by default in the script. You can use the textlimit() and overlay_image() functions as defined in the script. You can use the new open_image() function to open any type of image that GD supports, although I recommend sticking with PNG.

Here's an example of limiting the string length to 25 characters:
$titles[0] = textlimit($titles[0], 25);

Here's an example of image overlay:
// open an image
$sigimage = open_image("background.png");

// put my png overlay on it
overlay_image("overlay.png");

...easy right? ^^

I've also added basic image caching by using a check_cache() function and tried to make it as simple as possible to understand. This still requires permission changes, but hopefully it's not too much for people.

I am a banana.
May 18, 2009 5:44 AM

Offline
Feb 2008
4295
I recently added this way-too-long code to my script:
$replaceCharacters =     array('/ä/','/~/','/☆/','/†/');
$replaceWithCharacters = array('a','-','*','+');
$animeTitle = preg_replace($replaceCharacters,$replaceWithCharacters,$animeTitle);
It takes care of the characters (that I know of from MAL) that a lot of fonts don't include. Of course, * and + are no ☆ and † but you get the point.

I'm considering switching over to your script, I'd need to incorporate some minor changes but overall, it does what I need. I'm assuming it actually works with 000webhost's cron jobs?
May 18, 2009 7:05 AM

Offline
May 2008
4052
hmmm...It would be nice to compile a more comprehensive replacement method, or even better to have a fall-back font and let it switch to a unicode font only for writing those characters. I considered doing this in my own (non-minimal) script at one point... but since I no longer use the text I didn't bother. I don't really want to add anything more to this one, but it should be easy to add basic replacements using strtr(), near the other character replaces...

$buffer = strtr($buffer, array('ä' => 'a',...) );

kuroshiroi said:
I'm considering switching over to your script, I'd need to incorporate some minor changes but overall, it does what I need. I'm assuming it actually works with 000webhost's cron jobs?

there shouldn't be any problem. something like this should do it:
sakaSep 10, 2009 6:54 PM

I am a banana.
May 18, 2009 7:35 AM

Offline
Feb 2008
4295
saka said:
I don't really want to add anything more to this one
I hear you on that but it beats having boxes and shit in the sig.
Jun 2, 2009 10:12 PM

Offline
May 2009
52
Looks like i've learnt how to script, thanks alot.
Can you put JPEG pictures instead of png? or it doesnt work with JPEG?
Jun 2, 2009 10:49 PM

Offline
May 2008
4052
ryuK- said:
Looks like i've learnt how to script, thanks alot.
Can you put JPEG pictures instead of png? or it doesnt work with JPEG?


jpeg images should work just fine ...it should even work with GIF (not animated) and a host of other formats like BMP, XPM, and GD raw images.

By default, it still converts the output to PNG, though. If you don't want this, you can change the imagepng(...) lines at the end to imagejpeg() instead just to avoid extra conversion and/or reduce filesize if you don't need transparency. Remember to change the header(...) lines accordingly also.

I am a banana.
Jun 2, 2009 11:38 PM

Offline
May 2009
52
Thanks, i got it working
Jun 19, 2009 12:18 PM

Offline
Apr 2008
254
saka said:
erm... it's filled with #'s possibly?

you're probably getting a parsing error.... just remove all the #'s in your code if they are actually there (global replace in your text editor should handle it).
btw... it's better to just ask in the thread for my script if you have questions.

Okay I done that, but still it isn't working. Maybe let's start from begging. That whole code must be put in one php file (ex. sig_creator), then I must have background, overlay (I'm using it), font file and cache folder, right? I got that all, cache folder chmod is set 777, server is 000webhost.com and the code is like in other topic (but without #'s), still it isn't working. What could be the problem?
Jun 19, 2009 12:25 PM

Offline
Feb 2008
4295
Post the code again with the error.
Jun 19, 2009 12:59 PM

Offline
May 2008
4052


Fixed the errors, Silmoren...

make sure you have the url set like i have done above, and that the $font is the path to an actual *.ttf font file.

not sure why you wanted to strip out all the comments... nor exactly exactly what is wrong... but I'll look later tonight if I have time.

I am a banana.
Jun 19, 2009 3:05 PM

Offline
Apr 2008
254
Okay, everything seems to go better way now, great thanks for help, but still I would use some more ^^ Sig is loading now, but there's no text on it, whatever I do. Here's the text-regarding code:


Changing font, color, position, doesn't do anything, sig is still empty
Jun 19, 2009 3:12 PM

Offline
Feb 2008
4295
Well, what color is your background, are you sure that's the correct position of the text and since fonts are very CaSe-SeNsItIvE, check that, including the ttf.
Jun 19, 2009 5:03 PM

Offline
May 2008
4052
one more thing that might be the culprit: the mal forums will strip backslashes on edit... it's right on my post now, but I had to edit it once to put the backslashes back in. Without them the regular expressions break and none of your RSS data is loaded... which might cause no text to appear.

Make sure these three lines contain backslashes in your version:


You can check that your rss data is being matched by putting a line like this right before your text lines:
var_dump($titles); exit(0);

That will output what the titles array looks like and then stop the script.... so you should see some data when you try to run it.

You should see a list of all the titles in your feed... If nothing is there, something is probably going wrong with parsing. You can just remove the test code if it is working, or use it to test other variables if you'd like.

If that fails, just compare your code against my original since we know that works.... ;P

I am a banana.
Jun 20, 2009 5:16 AM

Offline
Apr 2008
254
Checked the code, it's exacly the same as Your original code, also that var_dump line doesn't work, nothing changes (at first time I got "NULL error", but later nothing changed). Changing font position, angle, size, doesn't do anything.

Maybe something's with font file, it was .otf, I've changed it to ttf...
Jun 20, 2009 6:32 AM

Offline
Feb 2008
4295
Silmoren said:
Checked the code, it's exacly the same as Your original code, also that var_dump line doesn't work, nothing changes (at first time I got "NULL error", but later nothing changed). Changing font position, angle, size, doesn't do anything.

Maybe something's with font file, it was .otf, I've changed it to ttf...
You changed the name of the font or the code?
Jun 20, 2009 9:11 AM

Offline
May 2008
4052
Silmoren said:
Checked the code, it's exacly the same as Your original code, also that var_dump line doesn't work, nothing changes (at first time I got "NULL error", but later nothing changed). Changing font position, angle, size, doesn't do anything.

...which just further implies that something is wrong before the text stuff. There's probably nothing in the $titles array, so you're printing out a lot of nothing. An empty string prints just about the same when moved or rotated. ;)

Silmoren said:
Maybe something's with font file, it was .otf, I've changed it to ttf...

*.otf should work just as well, as long as it matches the filename in your code...

I still suspect something on one of the parsing lines is not correct, but I can't tell without looking at it. I've zipped up my test files and sent you a link via pm.

Just replace with your background.png and ol.png and it should work just fine.

I am a banana.
Jun 20, 2009 11:08 AM

Offline
Apr 2008
254
Okay, as it can be seen the problem is out, it was the font file that generated errors, changed it and everything seems fine. Once more many thanks for all people, who helped me creating this sig ^^
Jun 20, 2009 11:41 AM

Offline
May 2008
4052
ooooo looks great, too.

I am a banana.
Jun 22, 2009 10:39 AM

Offline
May 2008
1707
Hey, I'm making a signature for a friend using the anime/manga merged feeds. Anime updates works great, but when manga is updated, it looks like this:

It doesn't show the read chapter. It also showed the manga type before, but I managed to remove that. This problem is out of my skills though :P

This is what my code looks like:
Jun 22, 2009 11:21 AM

Offline
Feb 2008
4295
I'm guessing you'll need to edit
if ($status[$i] == "Watching" or $status[$i] == "Re-Watching")
to something like this:
if ($status[$i] == "Watching" or $status[$i] == "Re-Watching" or $status[$i] == "Reading")


Basically, tell the script how it should format the reading manga entries.
Jun 22, 2009 11:28 AM

Offline
May 2008
1707
Thank you, works great now :)
Jul 2, 2009 5:44 PM

Offline
Sep 2007
530
Great script
Jul 3, 2009 2:02 PM

Offline
Apr 2008
254
Hmmm recently I wanted to change script from Anime to Anime/Manga. Everything works just fine but 2 problems.

Is it possible with this script to create signature that displays two titles with statuses, where one title is always for manga and other is always for anime? I've changed few things but that script always shows me my recent changes, so when I watch two animes, it displays changes about those two animes, when I read two mangas, it displayes changes about those two mangas.

Second thing is, that script displayes how many anime episodes I've watched, but it doesn't display how many manga chapters I've read.

Also made small change to the code, so that manga title won't be displayed with "- Manga" at the title end:

$titles[$i] = preg_replace('/ - (TV|Movie|ONA|OVA|OAD|Special|Manga)$/', '', $titles[$i]);
Jul 3, 2009 2:57 PM

Offline
May 2008
4052
Silmoren said:
Is it possible with this script to create signature that displays two titles with statuses, where one title is always for manga and other is always for anime? I've changed few things but that script always shows me my recent changes, so when I watch two animes, it displays changes about those two animes, when I read two mangas, it displayes changes about those two mangas.

I set it up like this intentionally, although since the status contains 'chapters' instead of 'episodes', you should be able to use this to determine whether an entry is anime or manga.

You could duplicate the preg_match_all lines and parse the anime and manga buffers separately instead of the combined one... You'd need to make some new array names, or make the titles[], status[] etc arrays two dimensional.

If that sounds odd to you, you can do this easier workaround... If you've got more than 15 anime in your list (most people), you can just comment out the line that sorts the combined entries by date:
// array_multisort($timestamps,SORT_DESC,$titles,$status,$current,$totals,$units);

...and then the most recent manga entry should always be the 16th one (since the recent anime feeds list 15 entries). It's not as elegant, but it works.

Silmoren said:

Second thing is, that script displayes how many anime episodes I've watched, but it doesn't display how many manga chapters I've read.

Also made small change to the code, so that manga title won't be displayed with "- Manga" at the title end:

$titles[$i] = preg_replace('/ - (TV|Movie|ONA|OVA|OAD|Special|Manga)$/', '', $titles[$i]);

Strange, I thought I had fixed that already, but I guess i forgot to update the url. The full line to remove all types is this:
$titles[$i] = preg_replace('/ - (TV|Movie|ONA|OVA|OAD|Special|Manga|Manhwa|Manhua|Novel|One Shot|Doujin|OEL)$/', '', $titles[$i]);

I'll fix this on the first page shortly.
sakaJul 3, 2009 3:00 PM

I am a banana.
Jul 4, 2009 5:44 AM

Offline
Sep 2007
530
Forgive me if I'm asking a lot, but is there a way to reposition text if the anime title has less then a certain amount of letters?
Jul 4, 2009 6:15 AM

Offline
Feb 2008
4295
Roxkis said:
Forgive me if I'm asking a lot, but is there a way to reposition text if the anime title has less then a certain amount of letters?
Should be rather easy, if you know a little programming. You'd have to use http://php.net/manual/en/function.strlen.php and some kind of conditional statement like a switch or an if.

There may be some errors there, but it should be something like this:

if (strlen($titles[0])>5)
{
imagettftext($sigimage,14,0,118,38,$colour,$font,$titles[0]);
imagettftext($sigimage,11,0,125,50,$colour,$font,$status[0]);
}
else
{
imagettftext($sigimage,14,0,200,38,$colour,$font,$titles[0]);
imagettftext($sigimage,11,0,150,50,$colour,$font,$status[0]);
}


In this case, the first 2 lines will execute if the length is over 5 and the last 2 will execute if the length is below 5.

Yes, I overuse white space, give me a break.
kuroshiroiJul 4, 2009 6:20 AM
Jul 4, 2009 12:22 PM

Offline
Apr 2008
254
saka said:
If that sounds odd to you, you can do this easier workaround... If you've got more than 15 anime in your list (most people), you can just comment out the line that sorts the combined entries by date:
// array_multisort($timestamps,SORT_DESC,$titles,$status,$current,$totals,$units);

...and then the most recent manga entry should always be the 16th one (since the recent anime feeds list 15 entries). It's not as elegant, but it works.

Nope, it doesn't work for me, when I use it, sig only displays anime entries.

saka said:
You could duplicate the preg_match_all lines and parse the anime and manga buffers separately instead of the combined one... You'd need to make some new array names, or make the titles[], status[] etc arrays two dimensional.

Hmm I understand what what you mean, but my low PHP skill doesn't allow me to use that.

Well I'll stick with what I've got now, still it's not so bad :P
Jul 4, 2009 5:13 PM

Offline
May 2008
4052
works for me... Try this code:
http://pastebin.com/m361654e1

the titles array comes out like this, where 0-14 are anime and 15+ are manga:


these are the lines i changed, which might be helpful:
http://pastebin.com/pastebin.php?diff=m361654e1

I am a banana.
Jul 5, 2009 7:41 AM

Offline
Apr 2008
254
Hmm that seems to work nicely, thanks for help ^^
Jul 5, 2009 8:31 AM

Offline
Feb 2008
4295
saka 1 - php 0
Jul 10, 2009 4:38 AM

Offline
Apr 2008
254
Small change in code:

if ($status[$i] == "Watching" or $status[$i] == "Re-Watching" or $status[$i] == "Reading" or $status[$i] == "Re-Reading") {


Without this, sig won't display amount of manga chapters
SilmorenJul 16, 2009 2:53 AM
Jul 11, 2009 3:36 PM

Offline
May 2008
4052
Thanks for mentioning that. This has been pointed out before so I've updated it in the code.

Since with dual feeds its more likely people will list lots of statuses, I've changed it to an in_array() call so that you don't need to keep writing " or $status[$i] == " every time. I encourage people to change the formatting bits any way they'd like.

Here's the diff:

I am a banana.
Jul 15, 2009 12:40 PM

Offline
Feb 2009
7
saka said:

kuroshiroi said:
I'm considering switching over to your script, I'd need to incorporate some minor changes but overall, it does what I need. I'm assuming it actually works with 000webhost's cron jobs?

there shouldn't be any problem. something like this should do it:


is that how you did it? I tried to create a cron job exactly like that, but it doesn't update. I have to manually visit the php file to get my cache pic to update, so I know that is working.

mine looks like this and yes, I added it (just in case anyone asked)


any idea what I could be doing wrong?
redlupineJul 15, 2009 12:45 PM
Jul 15, 2009 2:46 PM

Offline
May 2008
4052
make sure the second field starts with public_html since the path should contain that. I'm not sure how it was left out of my screenie from earlier, but it should be there. So the second field for you would be:
public_html/myanimelist/sig_creator2.php

I am a banana.
Jul 15, 2009 9:22 PM

Offline
Feb 2009
7
saka said:
make sure the second field starts with public_html since the path should contain that. I'm not sure how it was left out of my screenie from earlier, but it should be there. So the second field for you would be:
public_html/myanimelist/sig_creator2.php


it's still not updating, maybe that was just part of the problem
I've tried playing around with the check_cache function, to see if that was the problem, but no luck there
Jul 15, 2009 11:26 PM

Offline
May 2008
4052
check_cache() will just prevent the sig from updating more frequently than once every X minutes. If your cron job is set to visit it every ten minutes, then you should still see the updates after that 10 minutes (or the cache time, whichever is greater).

The script seems to be generating it properly, so it must be a problem with the cronjob and not the script. The settings you showed should work though... are you sure it isn't working? Try making an anime update, then wait 20 mins and check the cache image.

There are also alternatives to using cron, such as using MAL Updater's php signature plugin to visit the url.

I am a banana.
Jul 16, 2009 12:02 PM

Offline
Aug 2008
175
I used the script posted on the first page (this), the anime and manga merged one. But I get this error: Parse error: parse error in C:\xampp\htdocs\sig\index4.php on line 62

Does anyone know what to do?
Jul 16, 2009 12:05 PM

Offline
Feb 2009
7
thanks for trying to help, but it's still not working

I made a strange discovery though. I tried 3 other cron job sites and tried to point them to my php file url, but the all failed when I tried to set the cron. I think there's something about my php file that cron jobs don't like.

Maybe I gotta make it not output an image, just save it to a the cache. Is there a way to do that?

EDIT: Nevermind, I fixed it, that was exactly the problem
I commented out the
header("Content-type: image/png");
line and BAM, now it works

EDIT2:
False alarm, it still doesn't work. Either it was a one time deal that it updated or someone was messing with me and manually ran my php
redlupineJul 16, 2009 9:18 PM
Jul 16, 2009 12:07 PM

Offline
Jul 2008
97
V3gas said:
I used the script posted on the first page (this), the anime and manga merged one. But I get this error: Parse error: parse error in C:xampphtdocssigindex4.php on line 62

Does anyone know what to do?


in fact there is missing a )

if ( in_array($status[$i], array("Watching", "Re-Watching", "Reading", "Re-Reading") ) {
should be changed to

if ( in_array($status[$i], array("Watching", "Re-Watching", "Reading", "Re-Reading") ) ) {
Jul 16, 2009 12:23 PM

Offline
Aug 2008
175
Niroko said:
]should be changed to

if ( in_array($status[$i], array("Watching", "Re-Watching", "Reading", "Re-Reading") ) ) {

Oh. Hahaha, such a small mistake. I guess I didn't look closely enough.

EDIT: Can anyone tell me how to not display Plan to Watch/- Read?
V3gasJul 16, 2009 1:16 PM
Reply Disabled for Non-Club Members
Pages (9) [1] 2 3 » ... Last »

More topics from this board

» Scripted Signature Showcase

KHobbits - Jul 9, 2008

23 by KHobbits »»
Oct 21, 2014 6:42 PM

» MAL Signature Designer

Apocist - Mar 11, 2014

10 by Apocist »»
Aug 6, 2014 3:01 PM

» iSignature

i906 - Dec 11, 2009

9 by USKurosaki »»
Apr 10, 2013 8:40 PM

» Animated Signatures

koleare - Jan 3, 2013

1 by Rezurrekt »»
Jan 10, 2013 4:13 PM

» List of Free PHP Hosts that meet script requirements

saka - Jun 8, 2010

31 by saka »»
Oct 26, 2012 2:58 AM
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login