Forum Settings
Forums
New
Dec 15, 2008 11:53 AM
#1

Offline
Apr 2008
78
Tutorial: Generating images using php and the MAL-RSS-feed

Before the show starts:
This is my first tutorial on php-programming so bare with me if its (maybe) sometimes hard to understand or not really clear what i try to say. So...if you have any questions about this tut or you have any ideas how to improve it let me know. Improvements can never be a bad thing.

1.Starting notes
2.Requirements
3.Setting up the script
4.Vital source-code parts in detail
5.Creatin your own customized signature
6.Additional information
7.Possible errors and how to handle them

Full source files of this tutorial you will need: download
(be sure to keep the given structure intact when you upload the files to your webspace)
[when you unzipped the source, uploaded it, and made everything correct you should get an output according to the one you see below)

This tutorial is for those of you, who want a scripted signature that uses a non-MAL custom font.
An example how it can look like:


1. Starting notes
The script we will make during this tutorial is neither the best, nor the last answer on how to create a scripted signature. There are more advanced scripts out there, which do more than just the basic things provided by this tutorial. Nevertheless you will be able to make a working, customizable scripted signature that can easily be upgraded with more functions.
For more advanced script try taking a look at the „Signature Scripters“ Club (http://myanimelist.net/clubs.php?cid=5076).

If something is unclear, or you just don't know how to do a certain step feel free to post below. Suggestions and criticisms are also welcome.

2. What you will need to successfully pass this tutorial:

  • a good, working webspace that meets the following requirements: (i can recommend 000webhost.com – it meets all requirements)

    • supports php 4 and above
    • phpconfig() should look like this:

      • allow_url_fopen: On
      • file_uploads: On
      • safe_mode: Off
      • GD support: enabled
      • FreeType Version 2.x
      • GIF/JPG/PNG Read Support enabled
      • Note: you can check if your wehost allows this by generating a simple php file. Name the file as you wish e.g. info.php. Content of the file: <?php phpinfo(); ?>Upload the file to your webhost, and acces it through a browser. Your done.

  • a workable ftp-client ( e.g. filezilla or any other ftp-client you like)
  • some enthusiasm to start with (thats the most important thing ^^)

Plusses to have on your side: basic knowledge of webdesign and or php-programming (this is not a 'need to have'); basic knowledge of ftp-clients or how to upload files on a webserver and how to alter chmod of files

So, if your still here, then you are seriously interested in how to script your own flashy signature. Thats good! Lets start then.

First of all, you will need a signature graphic that you like.
So go on and choose one. Come back to this tutorial if you have done so.

3. Setting up the script

I will take you step by step through the setup process.
To start with, download the zip file from the link above and extract it. Here's the link once more: download
Fire up your ftp-client and upload all the files to your webspace. It is very important that you keep the given file-structures intact.

This done, set the following chmods:

  • 777: signature folder
  • 755: sig_creator.php and sig.png

(Note:with a standard ftp-client you can change a files/folders chmod like that: right click on a file or folder, choose 'chmod' in the appearing contextmenu.The rest should be self-explanatory)
Open a browser of your choice and open the url: 'yoursite.com/signature/sig_creator.php'
If your host matches all requirements, and you have done everything right, you should see something like my actual signature.

Congratulations!! You have taken the first steps in creating a custom signature...

Before we start with creating your own personalized sig, we have to do some more homework. Let's get started....

4. Vital source-code parts in detail

If you open the spoiler-tag you will see some source-code of the sig-script we're using right now. Cause it is vital for you to understand this part of the script to generate your own custom sigs, i will explain it in detail.



  • $blub = ImageCreateFromPng("your_pic.png");

    • replace „your_pic.png“ with the picture you want to pimp (must be in the same directory as your the final php file)

  • $font = 'Capture_it';

    • define the font you want to use. The font file must be in the same directory as the final php file. You can use any font you want, as long as you have the correspind file, that defines the font. E.b. For 'capture_it' you need to have the file „capture_it.ttf“ uploaded and in the same directory as your final-php file)
      find free fonts here: http://www.dafont.com/

  • $colour = imagecolorexact($blub,0,0,0);

  • imagefttext($blub,14,0,118,48,$colour,$font,$titles[0]);

    • $titles[0] outputs the very first anime title of your rss-feed
    • $titles[1] outputs the second anime title of your rss-feed and so on
    • find more information here: http://www.php.net/imagefttext

  • imagefttext($blub,12,0,170,60,$colour,$font,$status[0]);

    • $status[0] outputs the very first episodes info of your rss-feed
    • $status[1] outputs the second episodes info of your rss-feed and so on
    • be sure to set the same numbers of $titles and $status, otherwise you will get a messed up output

  • imagepng ($blub);

    • simply creates the final image; this will just output the picture, but doesn't save it. You can however, use the output for your signature (but i wouldn't recommend it, cause this has some disadvantages; however if you use it like this, with the bbcode below you won't have to use a cronjob for auto updates); bbcode would look something like [img.]http://yoursite.com/sig_creator.php[/img.].
    • If you want the pic to be saved you will have to replace 'imagepng($blub)'(if you change it like this, you will need a cronjob[information on this comes later] for auto updates of your sig)

      • replace 'imagepng($blub)' with:
          imagepng($blub, „sig.png“)
          imagedestroy($blub)


5. Creating your own customized signature

I guess right now, you have chosen, the gfx you want to use as a signature. If not, do so now and come back when your done with that.

As before, i will take you step by step through the whole process.
Due to the fact, that we have to change the source code, you will have to open the file 'sig_creator.php' in any texteditor you like.
Next you have to find the part that looks like this:

  • //generate the image
    $blub = ImageCreateFromPng("your_pic.png");


Now: replace ("your_pic.png") with the name of the sig-gfx you'd like to use e.g. if the png you want to use is called „flashy.png“ you would have to change ("your_pic.png") to ("flashy.png"). [easy isn't it ^^]
For now, leave the rest as it is. Save the file and upload the changed 'sig_creator.php' and your sig-gfx to your webspace.

For information on how to change the font or how to make more than one anime title appear on your sig read point 4.

If you're satisfied with the outcome there is merely one thing left. Once again open the file 'sig_creator.php' in any texteditor you like. Find the following line:

Save the file. Once again. Upload the file 'sig_creator.php' to your webspace. Browse to 'yoursite.com/signature/sig_creator.php'.
If you get an error like „The Image „your-image“ cannot be displayed because it contains errors“ don't start to panic. Instead open the following url: 'yoursite.com/signature/sig.png'
If you get an output everything worked fine.

If you have chosen to save the png-output of the sig-creation process, and you want to use this saved png-file instead of the raw 'php-site' as your sig you have to do one more thin. (read under point 4 how to save the png-output)
That is to automate the update of your signature. Read under point 6: cronjob, how to achieve this.


6. More Information on how to setup the serverside direcotories and how to automate the sig-generating process


  • for further information on chmod look here: http://www.freebsd.org/cgi/man.cgi?query=chmod&sektion=1
  • cronjob: if you want the script to automatically update your signature, you will need a cronjob. A cronjob is a long running process that executes commands at specific dates and times. You can setup your own cronjob but that isn't easy and isn't really needed, cause there are some free cronjob provider out there who already did the scripting for you and offer you easily configurable cronjobs. Find such a provider here (cronjobs.org) or here (cronjob.de[recommended for german users]).
    If you want to setup a cronjob all by yourself from scratch look here for further information:
    http://www.aota.net/Script_Installation_Tips/cronhelp.php3
    (but be warned that this is absolutely not suited for scripting beginners)


7. Possible errors and how to handle them
ehrgeizDec 19, 2008 1:38 PM
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.
Pages (4) [1] 2 3 » ... Last »
Dec 15, 2008 12:32 PM
#2

Offline
Feb 2008
4295
Good tutorial. It should get most interested people on the right track.

I have a few suggestions and comments.
  1. The thread title should probably be "Tutorial: Generating Signatures..."
  2. chmod in FileZilla is under "File Attributes".
  3. The image under imagepng is missing
Now you'll just have to see if anybody understands this and uses this ^_^
Dec 16, 2008 9:50 AM
#3

Offline
May 2008
2838
although I am php retarded, this looks like a great tutorial. Way to go; we need more of those
Dec 17, 2008 6:23 AM
#4

Offline
Apr 2008
78
although I am php retarded, this looks like a great tutorial. Way to go; we need more of those


well...i hope this tutorial will help interested people in creating their own custom sigs.
I think it's definitely a good start and some helpfull information to begin with. No one starts scripting at the top notch. Everyone has to learn how to do it.

@kuroshiroi: thanks for your information
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.
Dec 17, 2008 7:08 AM
#5

Offline
Oct 2006
1569
Your post is very much appreciated. I've been meaning to fool around with this stuff some, and it's ever so nice not to have to start from scratch.
Dec 18, 2008 7:54 AM
#6

Offline
Oct 2006
1569
Just thought I'd add an observation after spending a while tweaking the script for my own signature: the script needs more comments. I'm bad about adding them in my own code, but they're extremely helpful when digging through someone else's, and for something like this where the intent is for people who know less than you about programming (perhaps even very little) or at least aren't familiar with the specifics of parsing RSS feeds and image generation and such to get in and mess with things and learn from it, comments in the code are pretty critical. I managed just fine myself and am very grateful for the assistance, but I imagine with less programming experience I would've had trouble.
Dec 18, 2008 8:00 AM
#7

Offline
Aug 2007
1371
@_@

wow
Dec 18, 2008 11:50 AM
#8

Offline
Apr 2008
78
@krelian: thanks for your reply and sharing your thoughts

The improvement of this tutorial depends on such statements and replies.
I will add more and better comments as soon as possible.
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.
Dec 18, 2008 9:10 PM
#9

Offline
Dec 2007
218
Thanks a lot for this :D It is very helpful. I started learning php recently so I had the basics with me. I will surely make my siggy out of this, it is all neat and simple.

Also, like krelian said, putting more comments in the code will totally help (someone like me :P who is quite new to this) especially to the part where you prepare the parsed info for the signature :D this will surely help get better understanding of it.
Dec 18, 2008 9:53 PM

Offline
Jan 2008
809
Hey, great tutorial! I use "imagerectangle" sometimes too in GD.
Dec 19, 2008 12:39 PM

Offline
Dec 2007
218
I made one :D

Just one thing in the code, I guess is not that big deal and I know it doesn't have any effect, but that last comment you added, for the imagedestroy function, the variable you kept in brackets, shouldn't it be the same variable you declared for holding the image? i.e. ($blub)
NotADoctor_Dec 19, 2008 12:43 PM
Dec 19, 2008 1:39 PM

Offline
Apr 2008
78
Fara7 said:
for the imagedestroy function, the variable you kept in brackets, shouldn't it be the same variable you declared for holding the image? i.e. ($blub)


that's right...don't know what i thought while writing this ^^
fixed it - thanks for the hint

and a nice sig Fara
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.
Dec 19, 2008 1:41 PM

Offline
Oct 2006
1569
Indeed it should. I forgot to mention that one.
Dec 22, 2008 3:03 AM

Offline
Dec 2007
218
Say I want to show the date too, then I need to use <pubDate> </pubdate> from the RSS file, right? and declare a variable to hold it along with the other variables already declared?

Dec 22, 2008 4:54 AM

Offline
Oct 2006
1569
Yep. You can basically just copy the code that reads the title and then change the variables (you'll need a new array and a counter variable as well, initialized at 0 like the others). Also, if you want to format the date differently than MAL does, you could use strtotime to convert it to a Unix timestamp and then strftime to output a string in whatever format you like.
Dec 22, 2008 10:10 AM

Offline
Dec 2007
218
I tried it and it didn't work :( I declared the variable that will hold the date and also the counter value. I copied the part which fetches the titles and made the needed changes to the variables but nothing worked. Whenever I load the picture I don't get any dates.

I guess I shouldn't be working with this right now since tomorrow I have an Informatics practical test in Visual Basic and PL/SQL :P.....this will get me confused between syntaxes, I already get confused between VB and PL/SQL.....
Dec 22, 2008 10:36 AM

Offline
Oct 2006
1569
Hah, yeah, I always get a little mixed up on syntax too between different languages (which is why it's so handy to have the internet around, though I don't guess that helps in a test environment).

Anyway, here's what I did:

$date = "<pubDate>";
$dateend = "</pubDate>";
$d = 0;


added to the variable declarations at the top, and

for ($j=1;$j<$i;$j++) {
if ($cnt = strstr($buffer[$j],$date)) {
$ncnt = str_replace($date, "", $cnt);
$end = strstr($ncnt, $dateend);

$tmpstring = str_replace($end,"",$ncnt);

$dates[$d] = strftime("%d %B %Y",strtotime($tmpstring));

$d++;
}
}


right after the loop that goes through the titles. That'll give you a dates array to use at the end. You'll probably want to check the specifics of strftime so you can change that format string ("%d %B %Y") to whatever suits you
Dec 22, 2008 11:56 AM

Offline
Dec 2007
218
Oh thanks a lot for that :) It works now. Actually I realized what was the mistake I made before. When I assigned <pubDate> to $date, I forgot to check if the case matched what was given in the RSS file and wrote it as <pubdate>.....oh well, I always tend to do such silly mistakes and get stuck trying to find where I went wrong xD
Dec 24, 2008 5:12 PM

Offline
Jul 2007
2780
Its really really late here 3:15 pm so i have to sleep. But i wanted a tytorial like this so bad that i was thinking of starting a thread :P Really thanks with a quickglance it seemed really nice.Ill comment again after i make my sig tommorow.

EDIT: I made an account at the website you suggested and it worked perfect. But after 2-3 my sig was gone. I accessed the website and saw that " Website is under maintenance it will be back in 2-4 hours". 6 hours passed and still no sig. How aften are these "check ups" ? Any other better free host? Thanks for help
CloudyDec 25, 2008 12:47 PM
Dec 27, 2008 4:53 PM

Offline
Oct 2007
879
I did exactly what the tutoriall said but
i keep getting the 500 Internal Server Error when I open the sig_creator.php

Yes
the folder is chmod to 777
and the two files are at 755.
subishiroDec 27, 2008 5:11 PM
Dec 27, 2008 5:19 PM

Offline
Feb 2008
4295
Cloud1234: If you're asking about 000webhost, afaik the checks only happen once. I've been using them for a couple of months now and the only time they checked my site was when it started receiving visitors and never again.

Mukyaa: Which host are you using and please post a link the the sig_creator.php so we can see the error output.
Dec 27, 2008 5:33 PM

Offline
Oct 2007
879
[http://tjs.nextgenwebhosting.com/signature/sig_creator.php]My sig_creator.php[/url]

I got my hosting from a friend.
It has cPanel, 1GB Space and 5GB Monthly Bandwidth.
Dec 27, 2008 5:45 PM

Offline
Feb 2008
4295
Try setting the folder to 757, it seems your host doesn't like group writing permissions for some reason. If that doesn't work I've got nothing.

Edit: Some googling revealed this to be a likely cause and if this doesn't work you might need to set the permissions to 755.
Dec 27, 2008 5:47 PM

Offline
Oct 2007
879
kuroshiroi said:
Try setting the folder to 757, it seems your host doesn't like group writing permissions for some reason. It that doesn't work I've got nothing.


Did that and got
"Internal Server Error

Directory "/home/tjsnext/public_html/signature" is writeable by others"
Dec 27, 2008 5:48 PM

Offline
Feb 2008
4295
Hehe, just edited it, try 755.
Dec 27, 2008 5:51 PM

Offline
Oct 2007
879
thanks now it works...
just need to make it now

EDIT: I made it! Hopefully it's alright as my first sig.
Now another question, how do I get the score information from my list?
subishiroDec 29, 2008 11:16 AM
Dec 30, 2008 4:07 AM

Offline
Apr 2008
78
i'm at work right now, so im bound to give you just a short answer (hope it helps anyway)

some hints:
- you will need several layers:

  • 1st layer: bgimage [this will be the base of your image, all other layers have to be copied on top of that]
  • 2nd layer: Animetext
  • 3rd layer: foreground image

- you have to merge and copy the layers to get the final image
merging can be done with:
ImageCopyMerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct )
copy-pasting of images is done with:
ImageCopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )

I might make a sequel to this Tutorial where i will explain how to achieve such things like image rotation, multiple layers and advanced text effects.
For now you can find an example how to handle multiply layers in KHobbit*s signature script (find it here
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.
Dec 30, 2008 6:26 AM

Offline
Feb 2008
4295
I'm chiming in, since I can hopefully be of some help.

I played around with shiteiru's code and basically this is the order you'll want your code to be, I think everything's included:
---------------------------------------------------------------------------------------
//generate the image
$blub = imagecreatefrompng('bgimg.png');
------
here be random function for image.
------

//imagecolorexact(image, red(between 0 and 255), green, blue)
//imagecolorexact($blub,0,0,0) = black font | imagecolorexact($blub,255,255,255) = white font
$colour = imagecolorexact($blub,0,0,0);
$font = 'Capture_it.ttf';

//imagefttext(image, font size, angle, x-pos(relative to the image in px), y-pos, font color, fontfile, text output)
imagefttext($blub,14,0,118,48,$colour,$font,$titles[0]);
imagefttext($blub,12,0,170,60,$colour,$font,$status[0]);

// Copy
imagecopy($blub, $src, 0, 0, 0, 0, 600, 140);

imagepng ($blub); //we want our final image to be in the png format
---------------------------------------------------------------------------------------

and then this is the randomizing code, stolen and modified from my own code.
---------------------------------------------------------------------------------------
$num = rand(0,2);
switch($num)
{
case 0:
$src = imagecreatefrompng ('chie_face.png');
break;
case 1:
$src = imagecreatefrompng ('chie_chest.png');
break;
case 2:
$src = imagecreatefrompng ('chie_leg.png');
break;
default:
$src = imagecreatefrompng ('chie_face.png');
}
---------------------------------------------------------------------------------------
It's not fancy but it works and it's plenty for this application.

If you want to change something else besides the image, such as font colors and such you can just cut and paste code into the switch as needed.

I hope this helps.

Edit: I'm actually doing this a little differently though, for instance the Haruhi image in this sig is not two different images, just one that I move around with the y coordinates of imagecopy, so you can probably do something similar using the switch.
Unnecessary feature: http://kuroshiroi.net78.net/malsig/kuro.php?sig=haruhi&ver=60
I can even move her around using the url ;)
kuroshiroiDec 30, 2008 6:37 AM
Dec 30, 2008 7:21 AM

Offline
Dec 2007
218
So switch() is a conditioning statement. As long as the random number created by rand() equals the number after case, it displays an image. Just like the select statement in VB :)
Dec 30, 2008 7:41 AM

Offline
Feb 2008
4295
Fara7 said:
So switch() is a conditioning statement. As long as the random number created by rand() equals the number after case, it displays an image. Just like the select statement in VB :)
Yup, I actually tried to use select at first but that didn't really work :)
The only real difference is that php's switch needs the break; command to work like select does. That threw me off for a while.
Dec 30, 2008 5:08 PM

Offline
Feb 2008
4295
The switch needs to be above this line:

imagecopy($blub, $src, 0, 0, 0, 0, 600, 140);

and not at the bottom. I should probably have just pasted it together in the right order myself but I thought I would try to show you how the switch works first.

I'm surprised you're not getting an error actually :)
Dec 30, 2008 5:11 PM

Offline
Oct 2006
1569
At first glance, I'm thinking your problem is that this bit
<pre>$num = rand(0,2);
switch($num)
{
case 0:
$src = imagecreatefrompng ('chie_face.png');
break;
case 1:
$src = imagecreatefrompng ('chie_chest.png');
break;
case 2:
$src = imagecreatefrompng ('chie_leg.png');
break;
default:
$src = imagecreatefrompng ('chie_face.png');

Needs to go above this bit
<pre>// Copy
imagecopy($blub, $src, 0, 0, 0, 0, 600, 140);

imagepng ($blub); //we want our final image to be in the png format


The former chooses which image to overlay and the latter copies it over and saves out the signature, so if you've got them reversed you're pasting in the overlay image and saving the result before there's anything there.

[edit] Looks like I'm too slow to be useful =P
Dec 30, 2008 5:28 PM

Offline
Feb 2008
4295
Krelian: Nothing wrong with bashing windy over the head with a wall of text :)
Dec 31, 2008 2:37 AM

Offline
Oct 2008
390
Is there any way to limit my output characters?

Example: I have "Code Geass - Hangyaku no Lelouch" and I want it to show 15 characters so it should look like this "Code Geass - Han..."
Dec 31, 2008 4:30 AM

Offline
Apr 2007
1609
Ripaz said:
Is there any way to limit my output characters?

Example: I have "Code Geass - Hangyaku no Lelouch" and I want it to show 15 characters so it should look like this "Code Geass - Han..."

The way I normally do this is through the following method:

$substringanime = substr($animetitle, 0, 15);
imagettftext($image, $fontsize, $angle, $xbasepoint, $ybasepoint, $color, $font, $substringanime);
The second command, the imagettftext, is just the normal one pepole use to put their titles on with the normal parameters. The first one tells it to only use a substring of whatever you were looking at (in this case $animetitle), beginning at position 0 and extending 15 characters. The output of that is used in the next line.

This doesn't handle the ellipsis, though. But you can handle that easily by changing $substringanime in the second line to something like "$substringanime..." (Note that it needs to be in quotes like any other constant text.)

If you'll notice, my current signature is using this technique. The lettering in it is not tracked, but rather every letter you see on it is a substring of 1, and can be individually placed, colored, and moved around however I please. It's a bit more work and lines to add in, but it opens the door a little bit to a few more nontraditional designs.

EDIT: Forgot to mention the ellipsis.
IriDec 31, 2008 5:03 AM
Dec 31, 2008 5:04 AM

Offline
Apr 2008
78
the way Iri mentioned is the most easy and straightforward to do it.
for my script, there's a really easy way to achieve a cutting for all animetitles with just minimal changes...

find this piece of code in the php-file:

//now we have to prepare the information we cached in the $buffer array earlier

//for this we are going to use a for-loop

//this for-loop just extracts the anime_title information

for ($j=1;$j<$i;$j++) {
if ($cnt = strstr($buffer[$j],$title)) { //strstr('string to be searched', 'string to search')
//if the specified string has been found do...
//str_replace('found string', 'replace with', 'replace it in')
//and save it in the variable $ncnt
$ncnt = str_replace($title, "", $cnt);
$end = strstr($ncnt, $titleend); //strstr('string to be searched', 'string to search')
//once again replace a part of the string and save the outcome in a new arrai
$titles[$t] = str_replace($end,"",$ncnt);
$t++;
}

}

and replace it with this one:

//now we have to prepare the information we cached in the $buffer array earlier

//for this we are going to use a for-loop

//this for-loop just extracts the anime_title information

for ($j=1;$j<$i;$j++) {
if ($cnt = strstr($buffer[$j],$title)) { //strstr('string to be searched', 'string to search')
//if the specified string has been found do...
//str_replace('found string', 'replace with', 'replace it in')
//and save it in the variable $ncnt
$ncnt = str_replace($title, "", $cnt);
$end = strstr($ncnt, $titleend); //strstr('string to be searched', 'string to search')
//once again replace a part of the string and save the outcome in a new arrai
$cutter = str_replace($end,"",$ncnt);
$titles[$t] = substr($cutter, 0, 15);

$t++;
}
}

the rest can stay as it was before
the only part that really gets a change is the one i made extra super eye catching with red color

be aware that this change influences all animetitle in our array

Edit: in depth explanation of the used code

  • substr($cutter, 0, 15)

    • substr ( string $string , 'startingpoint in integer' , 'desired length of the whole string specified by integer' )

  • substr: Returns the portion of string specified by the start and length parameters
ehrgeizDec 31, 2008 5:49 AM
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.
Dec 31, 2008 7:50 AM

Offline
Dec 2007
218
Thanks all, I found this helpful. I was testing it: here.

Oh, I have a question, how is it possible to output the titles and status on the same line? I tried this:
imagefttext($image,14,0,7,118,$colour,$font,$titles[0].$status[0]);

but still, it moves the status to the next line.
Dec 31, 2008 9:20 AM

Offline
Oct 2008
390


Thanks for help. It works great. Only problem is that someone can mistook anime I'm currently watching (as you see it shows that Im watching Code Geass R2 but it misses R2 so it looks like Im watching 1. season) Is there a way to put code so it shows "..." when title is to big?
Dec 31, 2008 9:58 AM

Offline
Dec 2007
218
I was able figure out how to do this but by using one line (not the info from MAL). Here's the very simple code.
<?php
$string = "Code Geass - Hangyaku no Lelouch R2";

If (strlen($string) > 20)
{
$reqstr = substr($string, 20, strlen($string));
$repstr = str_replace($reqstr, '....', $string);
}

print $repstr;
?>
This is the output: Here.

So something similar has to be done for the titles.

Edit:
I tried it out on the signature code and guess it is done this way.
//prepare the parsed information for the pic
for ($j=1;$j<$i;$j++) {
if ($cnt = strstr($buffer[$j],$title)) {
$ncnt = str_replace($title, "", $cnt);
$end = strstr($ncnt, $titleend);
$string = str_replace($end,"",$ncnt);
if (strlen($string) > 20) {
$required = substr($string, 20, strlen($string));
$replace = str_replace($required,"....",$string);
}
$titles[$t] = $replace;
$t++;

}
}


Strlen() - this returns the length of a string.

I am not much knowledgeable in php but I hope this was helpful.
NotADoctor_Dec 31, 2008 10:34 AM
Dec 31, 2008 8:19 PM

Offline
Oct 2006
1569
Regarding printing the title and status on the same line, that ought to work fine (though you could do with some spaces in there instead of just tacking one string onto the other). I ran into the same problem though - there's a newline character in there that you need to get rid of. The trim function should do the trick nicely there.
Dec 31, 2008 11:55 PM

Offline
Dec 2007
218
It worked :) Thanks!

This is how I used the trim function.
$status[$z] = trim(str_replace($end2,"",$ncnt),"\n");
Jan 1, 2009 3:53 AM

Offline
Jul 2007
2780
Ok im trying to customize the sig you see i have now. But there are some problems.

First of all, as you see i know how to install and use a fond.But the problem is that it works ONLY for "capture_it" and no other. I tried 4-5 different fonts, i uploaded the ttf in the file directory where it should be but still nothing.Why does it work ONLY for "capture it" font? I did everything in the tytorial but still...

Secondly, I want my sig to have more than 1 update.I thought that since with this:
imagefttext($blub,14,45,10,120,$colour,$font,$titles[0]);
imagefttext($blub,13,45,15,137,$colour,$font,$status[0]);

I got one if i did this (with different X-pos of course):

imagefttext($blub,14,45,10,120,$colour,$font,$titles[0]);
imagefttext($blub,13,45,15,137,$colour,$font,$status[0]);
imagefttext($blub,14,45,10,120,$colour,$font,$titles[1]);
imagefttext($blub,13,45,15,137,$colour,$font,$status[1]);

I would get 2 updates... But it doesnt work.

My last problem is how to place dots when the anime is too long. For example now Akane doesnt fit in my sig. I want if it crosses the border to end like this:
Akane-Iru Ni ...

Instead of just going through.

I really need some help :(

Heres my whole script atm- If someone could tell me what to change or to modify it so that will work i would be glad :3

CloudyJan 1, 2009 4:06 AM
Jan 1, 2009 4:01 AM

Offline
Dec 2007
218
What is the extention of the font you are trying to use? If the extension is 'TTF' (in capital letters) it won't work (this happens to me sometimes), so try changing the extension to 'ttf'.

For adding dots to long titles, try what I posted 2 posts above this or wait for someone who knows better to give a better way :)
Jan 1, 2009 4:16 AM

Offline
Oct 2008
390
@Fara7: I replaced this code you gave me, but it doesn't show nothing when I put 2 character number. Only works with 1 character numbers.

EDIT: I just might know where is problem. I think when title is shorter than for example 20 characters it will not show it. I would fix it but PHP is not my better side. Other than that the rest is working fine.
RipazJan 1, 2009 4:39 AM
Jan 1, 2009 4:52 AM

Offline
Apr 2008
78
@ripaz: to show something like 'Code Geass R2' like 'Code Geass...' you will have to do the following tewaks to the code:

find the following code:

for ($j=1;$j<$i;$j++) {
if ($cnt = strstr($buffer[$j],$title)) { //strstr('string to be searched', 'string to search')
//if the specified string has been found do...
//str_replace('found string', 'replace with', 'replace it in')
//and save it in the variable $ncnt
$ncnt = str_replace($title, "", $cnt);
$end = strstr($ncnt, $titleend); //strstr('string to be searched', 'string to search')
//once again replace a part of the string and save the outcome in a new arrai
$cutter = str_replace($end,"",$ncnt);
$titles[$t] = substr($cutter, 0, 15);
$t++;
}
}

and replace it with this:

for ($j=1;$j<$i;$j++) {
if ($cnt = strstr($buffer[$j],$title)) { //strstr('string to be searched', 'string to search')
//if the specified string has been found do...
//str_replace('found string', 'replace with', 'replace it in')
//and save it in the variable $ncnt
$ncnt = str_replace($title, "", $cnt);
$end = strstr($ncnt, $titleend); //strstr('string to be searched', 'string to search')
//once again replace a part of the string and save the outcome in a new arrai
$cutter = str_replace($end,"",$ncnt);
If (strlen($cutter) > 12)
{
$titles[$t] = substr($cutter, 0, 12);
$titles[$t] .= "...";
}
else{
$titles[$t] = str_replace($end,"",$ncnt);
}

$t++;

}

}


the vital parts are marked in red
what it will do: check if a title is longer than 12 characters, if so the loop will be activated, the string will be trimmed and '...' after the 12th character. It is vital that you cut the string after the 12th char cause you want to add 3 dots and get a final counting of 15 to work with.

@cloud:

imagefttext($blub,14,45,10,120,$colour,$font,$titles[0]);
imagefttext($blub,13,45,15,137,$colour,$font,$status[0]);
imagefttext($blub,14,45,10,120,$colour,$font,$titles[1]);
imagefttext($blub,13,45,15,137,$colour,$font,$status[1]);
[/qote]
this should work, try to make the y-pos a little smaller e.g. replace 120 with 50 an 137 with 67 and see if it works


My last problem is how to place dots when the anime is too long. For example now Akane doesnt fit in my sig. I want if it crosses the border to end like this:
Akane-Iru Ni ...

see above, thats the same prob ripaz has...

to the font-problem
if you have something like:
$font = 'Your_Font';
try replacing it with:
$font = Your_Font.ttf';

note that: the font has to be written case-sensitive; also, if the font has another ending than .ttf you will have to write the font plus the ending in case-sensitive letters like in my example above, otherwise it wont work.
ehrgeizJan 1, 2009 5:07 AM
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.
Jan 1, 2009 5:07 AM

Offline
Oct 2008
390
Yeah I have done that. Replaced code and now look like this

//this for-loop just extracts the anime_title information
for ($j=1;$j<$i;$j++) {
if ($cnt = strstr($buffer[$j],$title)) { //strstr('string to be searched', 'string to search')
//if the specified string has been found do...
//str_replace('found string', 'replace with', 'replace it in')
//and save it in the variable $ncnt
$ncnt = str_replace($title, "", $cnt);
$end = strstr($ncnt, $titleend); //strstr('string to be searched', 'string to search')
//once again replace a part of the string and save the outcome in a new arrai
$cutter = str_replace($end,"",$ncnt);
If (strlen($cutter) > 32)
{
$titles[$t] = substr($cutter, 0, 32);
$titles[$t] .= "...";
}
$t++;
}
}


Sig looks like this:


Currently watching Akikan! that has 12 characters in total (with TV suffix). I have set 32 characters to cut but when title is shorter than that it will not show it at all. Dunno if I explained well.
Jan 1, 2009 5:09 AM

Offline
Apr 2008
78
fixed the issue in my above post, realized the problem as soon as i posted the solution...

you have to add this part

else{
$titles[$t] = str_replace($end,"",$ncnt);
}
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.
Jan 1, 2009 5:12 AM

Offline
Jul 2007
2780
Ok i solved the fond and the 2 updates problem.But the dots just wont show up :3

This is my code what am i doing wrong?

This is what i get
Jan 1, 2009 5:18 AM

Offline
Apr 2008
78
try this:

for ($j=1;$j<$i;$j++) {
if ($cnt = strstr($buffer[$j],$title)) { //strstr('string to be searched', 'string to search')
//if the specified string has been found do...
//str_replace('found string', 'replace with', 'replace it in')
//and save it in the variable $ncnt
$ncnt = str_replace($title, "", $cnt);
$end = strstr($ncnt, $titleend); //strstr('string to be searched', 'string to search')
//once again replace a part of the string and save the outcome in a new arrai
$cutter = str_replace($end,"",$ncnt);
If (strlen($cutter) > 6)
{
$titles[$t] = substr($cutter, 0, 6);
$titles[$t] .= "...";
}
else{
$titles[$t] = str_replace($end,"",$ncnt);
}
$t++;

}

}
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.
Jan 1, 2009 5:26 AM

Offline
Jul 2007
2780
Its the same as before
Pages (4) [1] 2 3 » ... Last »

More topics from this board

» New Clashing Feelings volume after a decade

Shiratori-san - Sep 27

4 by Shiratori-san »»
6 hours ago

» MyAnimeList x Honeyfeed Writing Contest 2025 Submission

Avarion - Yesterday

2 by Avarion »»
10 hours ago

» MAL Analog Horror

Wendy-- - Sep 27

10 by Shizuna »»
Yesterday, 3:05 PM

» Vladimir Volfovich Zhirinovsky's MAL Diary of Kawai Memories

V_V_Zhirinovsky - Yesterday

1 by V_V_Zhirinovsky »»
Yesterday, 1:00 AM

» New Android App – Shimeji Mascot Screen Pets

shimejimascot - Sep 26

8 by hacker09 »»
Sep 26, 10:03 PM
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login