Forum Settings
Forums

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

New
Reply Disabled for Non-Club Members
Pages (9) « 1 2 [3] 4 5 » ... Last »
Oct 6, 2009 8:27 AM

Offline
May 2008
4052
well, all these scripts will automatically download one or more of the rss feeds from the bottom left of your profile:

...and then they will parse out the relevant information to get things like the titles, episode numbers, and status... then it's just a matter of taking that info and putting it into an image. I've tried to divide my script into these three major tasks, where each line is heavily commented to explain what each line does.

For example, to get the watching statuses formatted the same as yours ("watching X of X episodes") you would look for the area marked "FORMAT THE STATUS VALUES" and change it to something like this:

...or if you're using the anime/manga merged version, substitute episodes in that red line with $units[$i] and it will display 'episodes' or 'chapters' depending on the type. ;)

If you have a question about a specific area, don't hesitate to ask in this thread.

I am a banana.
Oct 6, 2009 9:48 AM

Offline
Nov 2008
103
Well, I got most of it. There are just a few things I need to check and then I'll switch em while nobody notices.
Oct 13, 2009 9:08 AM

Offline
May 2008
4052
made a very minor update... just a wording change on the error message in check_cache when the cache folder is not configured properly.

die("Could not write to cache; please make sure the cache directory exists and is writable by all (777 permissions).\n\$cachedpath = {$cachedpath}");

I am a banana.
Oct 14, 2009 1:50 PM

Offline
Aug 2009
403
cailoli said:
Hmmm... did you comment out the two lines of the cache thing?

//$cachedpath = "cache/sig.png"; // a temporary copy of your signature will be stored here at the end
//check_cache(10); // time to cache signature in minutes, comment out this line for testing but put it back afterward!

Or made a directory called cache.

nonono. Just the check cache line, and btw I have something to help you!!!! :D

saka said:
made a very minor update... just a wording change on the error message in check_cache when the cache folder is not configured properly.

die("Could not write to cache; please make sure the cache directory exists and is writable by all (777 permissions).n$cachedpath = {$cachedpath}");


I have a better way ;)

Just replace the whole function check_cache with this:
http://pastebin.com/f299efd57

quick view


This will automatically create the directory with 777 chmods and purge errors if it exists. I have tested it.




---------------
IF YOU CANT GET YOUR SIG TO DISPLAY THE TEXT!!!! DO THIS

comment out this line near the top for testing your signature.

check_cache(10); // time to cache signature in minutes, comment out this line for testing but put it back afterward!


change to

//check_cache(10); // time to cache signature in minutes, comment out this line for testing but put it back afterward!




-----------------------

Good luck, if you have questions feel free to ask saka or I.
Caprica6Oct 15, 2009 5:45 PM
Oct 16, 2009 10:24 PM

Offline
May 2008
4052
mushwars said:
Just replace the whole function check_cache with...

I don't think this is any more likely to work, since mkdir() will also fail if the current directory is not writable (which is about 95% certain not to be since the user would have to do this). It will only work if suPHP is enabled (the minority of *nix servers) or if you're using a shitty windows box since they disregard user permissions by default.

I am a banana.
Nov 17, 2009 10:29 AM

Offline
Apr 2009
3174
Ehehe...As a php-noob, I have a minor problem...
I'm pretty sure I basically set all chmods to 777
and I still get : 'The cache is not writable; please change it to 777 permissions using FTP. $cachedpath = signature/Miku/cache/' as output

any idea how to fix this? >.< (I'm using the merged version btw)
Nov 17, 2009 11:22 AM

Offline
May 2008
4052
I'm not sure how your folder structure is, but the path is relative to where the script is.... so if the script is in the 'signature/Miku' folder, the $cachedpath should just be

$cachedpath = 'cache/sig.png';

the filename needs to be in there like above, not just the folder (also don't worry... sig.png will be created by the script as long as the cache folder is writable).

I am a banana.
Nov 17, 2009 11:30 AM

Offline
Apr 2009
3174
...Omg, thanks x3

...Next problem is... I can't see text >.<
I've put everything on 0 to see if I could see it, but I can't ='(

...I feel so noob >.<
sorry to bother you! You still rock btw
kurootetsurooNov 17, 2009 12:09 PM
Nov 17, 2009 12:52 PM

Offline
May 2008
4052
KokoroChan said:
I've put everything on 0 to see if I could see it, but I can't ='(

if you put the text at 0,0, you probably won't see anything... maybe 1 pixel or two at the top left. Did you see anything with the default values, which are closer to the center?
imagettftextalign($sigimage,14,0,250,36,$colour,$font,$titles[0],'c');
imagettftextalign($sigimage,11,0,250,50,$colour2,$font,$status[0],'c');
imagettftextalign($sigimage,14,0,250,76,$colour,$font,$titles[1],'c');
imagettftextalign($sigimage,11,0,250,90,$colour2,$font,$status[1],'c');


The coordinates start with (0,0) on the top left of the image, and increase the farther right and down you go. The text is oriented with the coordinates as the bottom left corner of the text..... so most likely the text is just off-screen, but there are other things that can cause text not to appear.

edit: the default looks something like this:
sakaNov 17, 2009 12:56 PM

I am a banana.
Nov 17, 2009 1:30 PM

Offline
Apr 2009
3174
Eh. I tried with the default settings and still couldn't see anything. >.<

EDIT: I rescripted it and now it works =D Thanks for your help saka ^^
kurootetsurooNov 17, 2009 2:06 PM
Dec 2, 2009 4:06 PM

Offline
Apr 2008
4287
Nice script. I lost my script files for bard's script so I'll be using this now. Thanks ^^

Dec 3, 2009 2:39 AM

Offline
Jan 2009
1379
i actually have a little problem, my overlay images won't show up
how many times i tried to ;w; i was double checking the names but it was the right name
so my sig became like this now:


and here's my code:
http://pastebin.com/f296193d5

please see it if i do something wrong, thanks in advance
Dec 3, 2009 2:47 AM
Offline
Jul 2008
3032
@suzuka_pew

find this part

// OVERLAY ANOTHER IMAGE over the font and background (optional)
//overlay_image("overlay.PNG");

and remove those lines I've put in red.
Your overlay image should also have this name : overlay.PNG

And the right thread for this question is here ;)
http://myanimelist.net/forum/?topicid=7256&show=0
Dec 3, 2009 11:37 AM

Offline
May 2008
4052
actually, if the question is about my script specifically, I do prefer it's posted here.

Meri is correct about the // ... I commented it out because it isn't needed most times. Perhaps I should make a note there since others have gotten confused.

also, be carefuly with CAPITAL and lowercase in your filenames.... on unix systems (which most webservers are) the case is very important as 'image.png' and 'image.PNG' can be completely different files. The script will stop with an error if it can't find the file, though.

I am a banana.
Dec 3, 2009 4:25 PM

Offline
Apr 2008
4287
The cache wasn't generated properly even after few reloads.



Here's the generated sig

Dec 3, 2009 6:11 PM

Offline
May 2008
4052
Sylpheed said:
The cache wasn't generated properly

can you be more specific? ...just that the image was not generated? there does seem to be a generated image but maybe you're having other troubles...

make sure the cache directory is writable by the server (777) as well as the file, if it exists. Also, make sure the path in $cachedpath matches to the file (case sEnSiTiVe). The cache will update if the php is loaded and 10 minutes has passed since the cache image was modified.

if that doesn't fix it, then post your code to pastebin or codepad so I can peek at it.

I am a banana.
Dec 3, 2009 9:11 PM

Offline
Jan 2009
1379
Meri said:
@suzuka_pew

find this part

// OVERLAY ANOTHER IMAGE over the font and background (optional)
//overlay_image("overlay.PNG");

and remove those lines I've put in red.
Your overlay image should also have this name : overlay.PNG

And the right thread for this question is here ;)
http://myanimelist.net/forum/?topicid=7256&show=0


okay, i have tried it and it works :D thanks meri :3

saka said:
also, be carefuly with CAPITAL and lowercase in your filenames.... on unix systems (which most webservers are) the case is very important as 'image.png' and 'image.PNG' can be completely different files. The script will stop with an error if it can't find the file, though.

yep, i already aware about that CAPITAL and lowercase filenames :)
but thanks for telling it again.
Dec 4, 2009 9:14 AM

Offline
Apr 2008
4287
@saka
I've already set up the cron and everything.

Cache seems fine since it worked. I think this script won't work if cache is not in 777. Anyway, I made sure I did the right thing.

I mean the sig is generating without problems. I assume the cache is separated from the generated sig itself since it's in a different directory. Those I posted above were the "cached" one and the one is tagged in www/sig/sig_creator.php


It worked after reloading it XD

Does this script have other features? I have some free space below XD

The one with the php extension is working.
SylpheedDec 4, 2009 9:17 AM

Dec 4, 2009 10:45 AM

Offline
May 2008
4052
well, whenever the php one is loaded, it will update the cache copy. It might have updated only because you linked to the php one on this page, and when I or other people loaded this forum page, it updated your cache. ;)

It could be that your cron job is what isn't configured properly. There is no harm linking directly to the php version of your sig; you just gain 1-3 seconds of speed by using cron and linking to the cached version.

I am a banana.
Dec 5, 2009 8:15 PM

Offline
Apr 2008
4287
saka said:
well, whenever the php one is loaded, it will update the cache copy. It might have updated only because you linked to the php one on this page, and when I or other people loaded this forum page, it updated your cache. ;)

It could be that your cron job is what isn't configured properly. There is no harm linking directly to the php version of your sig; you just gain 1-3 seconds of speed by using cron and linking to the cached version.


I thought it affects the server load both here and on my site.

I have this in my cron:
http://etherune.net/sig/auu/sig_creator.php

and it's set to 15minutes

Should I just set my sig to the php one?

Dec 5, 2009 11:25 PM

Offline
May 2008
4052
Sylpheed said:
I thought it affects the server load both here and on my site.

not having a cache at all can be problematic, but it's not setup that way. If you load the php, it will use the modification time of the cached image to know whether it needs a new one or not. Basically it handles it for you... it's just a warning not to comment it out except maybe during testing. ;)

Using cron is a separate issue, and not required at all.... if you just point to the php without using cron and your script isn't loaded for a while, then the first person who loads it will have to wait for your server to generate it from scratch which might take a second or two..... where if you were using cron it would have been refreshing the image every X minutes so a copy was always ready. Also, using the cache image directly is more resilient to errors -- like if mal is having rss trouble or your server's php stops working (like 000webhost does when your account is audited). It's handy, but not needed.

I am a banana.
Dec 6, 2009 5:23 AM

Offline
Apr 2008
4287
I'll redirect it to the php then XD

Dec 10, 2009 3:46 AM
Offline
Jul 2008
3032
What should I do to make this output posible?

on-hold at 8 of 50 episodes

or

dropped at 8 of 50 episodes.


Basically I want to add to the status, currents, units & totals.
Can this be done with a if statement?
something like
} else if ($status[$i] == "On Hold") {
$status[$i] = "on-hold at $current[$i] of $totals[$i] $units[$i]";
Dec 10, 2009 8:22 AM

Offline
May 2008
4052
I think that my comment in the script is incorrect; it is actually "On-Hold" in the rss and not "On Hold", so the only thing you need to do is convert to lowercase, and strtolower() is already in my example script.

You can certainly use if statements like that also, and that's exactly how you want to work with different statuses.

Here's how I would do it:
	// FORMAT THE STATUS VALUES - you can change the format as you like
if ( preg_match('/Plan to/',$status[$i]) ) {
$status[$i] = "$status[$i]"; // doesn't really do anything, but feel free to modify
} else { // any other status
$status[$i] = "$status[$i] at $current[$i] of $totals[$i] $units[$i]";
}
$status[$i] = strtolower($status[$i]); // make all the statuses lowercase

...or if you want completed to not show episodes/chapters either:

I am a banana.
Dec 10, 2009 9:04 AM
Offline
Jul 2008
3032
Thank you saka. You really are amaze <3
I tried it and as you can see it works just great.

The second version is if I'm getting this correctly is to make the output just:
''completed'' and not ''completed x number of x episodes'' right?

I think that's even better, since you really dont need for numbers of episodes to show when you have finished something.

Thanks again <3
Dec 10, 2009 3:51 PM

Offline
Apr 2008
4287
How bout

"Update xx [time] ago?"

Dec 11, 2009 12:00 AM

Offline
May 2008
4052
Meri said:
The second version is if I'm getting this correctly is to make the output just:
''completed'' and not ''completed x number of x episodes'' right?

yep

Sylpheed said:
How bout

"Update xx [time] ago?"


hmm... well, use the anime/manga merged version (since it parses the timestamps). You'll need a function to generate a nice human-readable string, so put this somewhere near the bottom before ?>....


...and now you can put something like this into your format loop:


If you copy and paste the above function and replace that section, you should get output kinda like this:


It's not necessary to put the "time ago" in the status either like I did here... you can just put $ago[$i] into imagettftextalign() lower in the code. It might need a little tweaking if time zones on the server are an issue, but I hope that the idea isn't too difficult to follow... the script parses the timestamps from mal out of the rss feed, and then the nicetime() function above compares to the current server time to make something readable.

Also, keep in mind that the "time ago" is from whatever time the image was last updated, which isn't always immediate. I think it's just fine to be accurate to within five minutes or so though. ;)

I am a banana.
Dec 11, 2009 6:19 AM

Offline
Apr 2008
4287
Where will I put the second one?

Dec 11, 2009 8:37 AM

Offline
May 2008
4052
find the section of code that looks similar to the gray parts, and copy/paste the green bits to overwrite the rest. It's around line 70 or so.

I am a banana.
Dec 12, 2009 1:02 PM

Offline
Apr 2007
1964
I switch for the merged script and I was wondering if there's a way to change the $units?
like instead of saying "episodes/chapters" I want it to say "ep/ch"




Dec 12, 2009 7:16 PM

Offline
May 2008
4052
you can do something like this in the main formatting loop, kinda similar to the last question
// change unit names
$units[$i] = strtr($units[$i], array( 'chapters'=>'ch', 'episodes'=>'ep' ) );

I am a banana.
Dec 12, 2009 8:46 PM

Offline
Apr 2008
4287
saka said:
find the section of code that looks similar to the gray parts, and copy/paste the green bits to overwrite the rest. It's around line 70 or so.


It says Bad data in my sig ><

I overwrote all the green one after the line:
$titles[$i] = textlimit($titles[$i],20);


and before the lowercase/uppercase function



I've also added the ago function before ?>
SylpheedDec 12, 2009 8:50 PM

Dec 12, 2009 8:55 PM

Offline
May 2008
4052
there's probably some small mistake that's making php generate a warning before or after the image data (and hence corrupting the image).

post the full code to pastebin or codepad and i'll have a look at it... can be as simple as a stray space after the ?> or sometimes it happens if you switch to utf-8 instead of ansi in your text editor.

I am a banana.
Dec 14, 2009 9:24 AM

Offline
Apr 2008
4287
Sorry for the delay...here it is

http://codepad.org/2MlPSR3Z

Dec 14, 2009 12:14 PM

Offline
May 2008
4052
just got a chance to test this. I'm not getting any warnings or corrupt data.... though I did forget to post the modified version of the nicetime() function from before. It was always returning "Bad date". I've modified it and put it into your code and i get this:



Here's the code, only modified a line and removed the empty lines: http://pastebin.com/m4ffa5402

since you're getting that weird bug in yours, most likely it's a text encoding issue. Make sure it's ANSI and not UTF-8 since sometimes that causes issues. In Notepad++ it can be selected under Format > Encode in ANSI then save again. If you use the Download link on pastebin it will also give it to you as ANSI text.

I am a banana.
Dec 15, 2009 8:33 AM

Offline
Apr 2008
4287
Thanks it's working now ^^

Can I move it on the next line so it won't collide with the episode update...or that would be another recoding of that block?

Dec 15, 2009 11:31 AM

Offline
May 2008
4052
sure thing... just download this code and overwrite: http://pastebin.com/m20179ee2

the lines i changed:
http://pastebin.com/pastebin.php?diff=m20179ee2
(basically i just took the $ago[$i] out of the status, and made a new imagettftextalign() below the others)

I am a banana.
Dec 17, 2009 8:15 PM

Offline
Apr 2009
38
I found a few useful things in your script. In particular, your use of imagettfbox is brilliant. But I couldn't help but notice a few strange things.

First and foremost, why use regex on the XML?

html_entity_decode or htmlspecialchars_decode might be a better choice here.
// now we have to sanitize the information we saved to the buffer (no newlines/tabs and replace xml entities)
$buffer = strtr($buffer, array("\n" => '', "\r" => '', "\t" => ''));
$buffer = html_entity_decode($buffer, ENT_QUOTES);


Seeing "or" is just weird.
        // FORMAT THE STATUS VALUES - you can change the format as you like
// lets format the strings to look like "watching @ 11/26" for watching, and only show status for the rest
if ($status[$i] == "Watching" || $status[$i] == "Rewatching") {


Saving it this way saves a lot of space.
Echoing the image we just saved as opposed to letting imagepng generate it again trades disk access for generation time. Most likely, both are cached. However, I trust my OS's disk I/O driver to cache it more than I trust PHP/GD.
// finally, let's output our pretty signature image to the browser
header("Content-type: image/png");
@imagepng($sigimage, $cachedpath, 9, PNG_ALL_FILTERS); // try to save a copy of our signature to the cache location we set earlier
echo file_get_contents($cached_path);


Shaved off a trim and made it less confusing. "strlen($a) > $b ? ...$a... : $a" should never really exist.
// textlimit($string, $length) takes any $string you pass it and resturns it shortened to $length characters (use it to limit title length)
function textlimit($string, $length=25) {
$string = trim($string);
if (strlen($string) > $length)
$string = trim(substr($string,0,$length-3)) . "...";
return $string;
}


Also, there's a silly forum bug that makes me lose my slashes when I preview my message.
Dec 17, 2009 9:34 PM

Offline
May 2008
4052
raylu said:
I found a few useful things in your script. In particular, your use of imagettfbox is brilliant. But I couldn't help but notice a few strange things.

First and foremost, why use regex on the XML?

html_entity_decode or htmlspecialchars_decode might be a better choice here.

I would have used html_entity_decode but strtr is faster, and it saves me a line of code without added confusion. I know that I cannot expect more than these entities, since those are the only ones xml requires encoded, and I was actually the one who told Xinil to encode them so I don't expect that to change.

raylu said:
Seeing "or" is just weird.

I'm more used to || too, but part of this is to get users new to php exposed to it so might as well use the plain english boolean operators. Doesn't really matter... it's only preference.

raylu said:
Saving it this way saves a lot of space.
Echoing the image we just saved as opposed to letting imagepng generate it again trades disk access for generation time. Most likely, both are cached. However, I trust my OS's disk I/O driver to cache it more than I trust PHP/GD.
// finally, let's output our pretty signature image to the browser
header("Content-type: image/png");
@imagepng($sigimage, $cachedpath, 9, PNG_ALL_FILTERS); // try to save a copy of our signature to the cache location we set earlier
echo file_get_contents($cached_path);

The image should still be in memory, where the one we "saved" may have failed because many people setting these up don't know how to chmod... which is the reason for the @. I know it's setup to fail now anyway when you do check_cache() but I don't see a big difference.

raylu said:
Shaved off a trim and made it less confusing. "strlen($a) > $b ? ...$a... : $a" should never really exist.
// textlimit($string, $length) takes any $string you pass it and resturns it shortened to $length characters (use it to limit title length)
function textlimit($string, $length=25) {
$string = trim($string);
if (strlen($string) > $length)
$string = trim(substr($string,0,$length-3)) . "...";
return $string;
}


yeah, I used a bit of magic there and stuck it in one line... guess I was just trying to reduce line count.

raylu said:
Also, there's a silly forum bug that makes me lose my slashes when I preview my message.

there's an overaggressive content filter on the edit boxes... mal uses a really broken custom bbcode implementation. I've yelled at it many times when posting code. I thought it only strips slashes on edit, though... but maybe not. I've complained about the bbcode and broken post filter before.... you can go post a bug in the support forum though and maybe Xinil will actually pay attention. I suspect strip_slashes is enabled on a server somewhere.

I am a banana.
Dec 17, 2009 10:44 PM

Offline
Apr 2009
38
saka said:
The image should still be in memory, where the one we "saved" may have failed because many people setting these up don't know how to chmod... which is the reason for the @. I know it's setup to fail now anyway when you do check_cache() but I don't see a big difference.


The image is in memory, but that doesn't mean GD is guaranteed to use it instead of regenerating it. The disk cache on a standard webserver environment will, though.

It still irks me that regex is being used on XML.
Dec 17, 2009 10:47 PM

Offline
May 2008
4052
raylu said:
It still irks me that regex is being used on XML.

strtr() is string substitution, not regex... it's what html_entity_decode() uses internally anyway, with a preset translation table a bit larger than mine. ;)

I am a banana.
Dec 18, 2009 12:52 PM

Offline
Apr 2009
38
I was talking about the preg_match_all.
Dec 18, 2009 1:12 PM

Offline
May 2008
4052
oh right lol.... yeah it's poor style I guess but it does the job. Also, I don't really trust mal's xml generation since it tends to occasionally miss entities that break xml_parse(). If it's any consolation, the code I wrote for myself uses xml_parse and grabs the data from an associative array.

I am a banana.
Dec 20, 2009 6:40 PM

Offline
May 2009
190
Is there a way to change the "completed" status to something like "24/24"? A new sig I'm working on doesn't have space for it :<
[
Dec 20, 2009 6:47 PM

Offline
Apr 2009
38
https://pastee.org/sddk8

I'm assuming you don't have room for the other statuses either ("Plan to Watch", "Dropped", "On Hold", etc.) so I just took them out.
Dec 20, 2009 9:05 PM

Offline
May 2009
190
That helped a lot, thank you!~
[
Dec 27, 2009 5:49 AM

Offline
Apr 2008
4287
@saka
Thanks for the script. ^^

It won't align to l r r or it wasn't just loaded well

Dec 27, 2009 8:17 AM

Offline
May 2008
4052
it looks right aligned to me. It right aligns to the x,y you give.... so that means that x,y will be the bottom right corner of the text. Since it was centered before you'll need to increase the x value to the right side of wherever you want it. Looks like adding about 175px to the x values should work.

I am a banana.
Dec 27, 2009 8:21 AM

Offline
Apr 2008
4287
That was stupid...I think I'm just sleepy XD

I forgot about the x y positioning and thought it was the same as a word processor XD

Dec 30, 2009 4:57 AM
Offline
Jul 2008
3032
I was wondering if the script version on the first page is the one that centers the updates text.
If not, saka can you please link me up?
I want the anime/manga together one ~

thanks.
Reply Disabled for Non-Club Members
Pages (9) « 1 2 [3] 4 5 » ... 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