Make your own PHP adoptables system

Need help with the site/forum/pets? Ask questions and get help from other members here.

Re: Make your own PHP adoptables system

Postby qhost » Wed Feb 11, 2009 11:44 pm

thenickdude wrote:What code have you got so far, Kiara?


I couldn't find the editted one so this was the basic sort of code:

Code: Select all
<?php
$text='text';
$imgname='test.png';

$im = @imagecreatefrompng($imgname);
$color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 8, 5, 5, $text, $color);
imagepng($im);
imagedestroy($im);
?>


According to what one of the examples said, "imagecolorallocate($im, 255, 255, 255)" is supposed to make the background white, but it doesn't.

I wanted to upgrade my adoptables system too after Rolly-chan helped me out with the adopts growing after a certain amount of days x3
    Image-----

    she/they | adult | australia | artist | writer
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    My name is Boo & I am perpetually tired.
    Taking a break from CS for a little while!

    Spotted Tribal count: 31
    ♥︎ Click here to see the hoard! ♥︎
    -
User avatar
qhost
 
Posts: 4352
Joined: Wed Oct 01, 2008 6:36 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Wed Feb 11, 2009 11:49 pm

Kiara wrote:
Code: Select all
<?php
$text='text';
$imgname='test.png';

$im = @imagecreatefrompng($imgname);
$color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 8, 5, 5, $text, $color);
imagepng($im);
imagedestroy($im);
?>


According to what one of the examples said, "imagecolorallocate($im, 255, 255, 255)" is supposed to make the background white, but it doesn't.


It's creating a colour of white (it's the same as #FFFFFF in HTML, a brightness of 255 in each of the red, green and blue channels combines to make white. 0,0,0 is black) and storing it in the variable $color. Later on, it uses that colour in the call to imagestring: It's using it as the text colour. When you say that the background ends up black, do you mean the background of the whole picture is black? Can you still see your pet image? Or do you mean the background of the text is black? A picture here would really help diagnose the problem :). You might try calling:

imagesavealpha($im, true);

Before your call to imagepng(). You're also missing this call:

header("Content-Type: image/png");

Before the call to imagepng. This tells the browser what kind of picture you are sending it. Some browsers can guess that it is a PNG image, but some can't, so you need this line to be compatible.

Have you checked out the documentation for imagestring? It explains what each parameter does:

http://nz.php.net/manual/en/function.imagestring.php
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby qhost » Thu Feb 12, 2009 12:02 am

thenickdude wrote:
It's creating a colour of white (it's the same as #FFFFFF in HTML, a brightness of 255 in each of the red, green and blue channels combines to make white. 0,0,0 is black) and storing it in the variable $color. Later on, it uses that colour in the call to imagestring: It's using it as the text colour. When you say that the background ends up black, do you mean the background of the whole picture is black? Can you still see your pet image? Or do you mean the background of the text is black? A picture here would really help diagnose the problem :). You might try calling:

imagesavealpha($im, true);

Before your call to imagepng(). You're also missing this call:

header("Content-Type: image/png");

Before the call to imagepng. This tells the browser what kind of picture you are sending it. Some browsers can guess that it is a PNG image, but some can't, so you need this line to be compatible.

Have you checked out the documentation for imagestring? It explains what each parameter does:

http://nz.php.net/manual/en/function.imagestring.php


Well, I'll add that code and see if it helps. Thanks x3

I'll try the site too. I can't remember which site I looked at...D:
    Image-----

    she/they | adult | australia | artist | writer
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    My name is Boo & I am perpetually tired.
    Taking a break from CS for a little while!

    Spotted Tribal count: 31
    ♥︎ Click here to see the hoard! ♥︎
    -
User avatar
qhost
 
Posts: 4352
Joined: Wed Oct 01, 2008 6:36 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Thu Feb 12, 2009 12:09 am

That's the PHP website itself, so it should be your very first port of call for PHP issues. You'll see a whole list of GD functions on the left of that page I linked you to. You can use the search box to find out about any PHP function! :)
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Rancor1358 » Thu Feb 12, 2009 5:06 am

thenickdude wrote:You've put URLs where you should have put filenames in the file you're using for adoptables.xml. The images must be hosted on your website. If they are in the same folder as simple.php, all you need to put is their filename, without http:// or your domain name in front.


Oh right.. Stupid me! Lol, um? Ok, so I just need to put the images in the same folder then? -Waddles off to try and fix-

Rancor
User avatar
Rancor1358
 
Posts: 234
Joined: Mon Nov 10, 2008 10:07 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Thu Feb 12, 2009 9:58 am

They can be in a folder. If your site was laid out like this:

/simple.php
/pic1.png
/pics/pic2.png
/pics/pic3.png

Then in your XML file, for the filename you could use any of these

"pic1.png"
"pics/pic2.png"
"pics/pic3.png"
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby qhost » Fri Feb 13, 2009 12:19 am

Well, I figured out how to change the writing colour and where the writing is (I didn't even have to read anything on the site XD) so I don't have to worry about that. The finished picture looks like this (I used an old Christmas adoptable to try it out on).

The only thing I need now is (other than where to put the codes etc.)..

either a colour underneath the writing, similar to the pets here, so the writing is clearer to see (example without) or something that makes the image longer/larger depending on what text is written (example without).

If I can't get something like that, I still have no idea where to put the codes D:

I'm really annoying D: ...
    Image-----

    she/they | adult | australia | artist | writer
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    My name is Boo & I am perpetually tired.
    Taking a break from CS for a little while!

    Spotted Tribal count: 31
    ♥︎ Click here to see the hoard! ♥︎
    -
User avatar
qhost
 
Posts: 4352
Joined: Wed Oct 01, 2008 6:36 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Nick » Fri Feb 13, 2009 12:55 am

"Where you put the codes" is where you want them to be executed, relative to the other instructions you've already got. The code gets run step by step from top to bottom. So you're loading an image, before you allocate a new colour to use with that image, before you use that colour to draw text, before you call imagepng to send the completed picture to the user, before you call imagedestroy to get rid of your image. If you wanted to, for example, draw a filled rectangle of colour behind the text, that would have to happen before the text gets drawn. imagefilledrectangle() could be useful here:

http://nz.php.net/manual/en/function.im ... tangle.php
User avatar
Nick
Admin
 
Posts: 6349
Joined: Thu Jul 03, 2008 2:40 pm
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby darkbringer » Fri Feb 13, 2009 1:10 pm

oh ive always wanted to create my own adoptables site-but im really bad at coding and such.

oh i tried it using a free domain at the website you suggested but after i inset the PHP in HTML view once saved it dosent appear and when i check the HTML its not there? im not very good at this >.<
Image
Pet's name: tyra
User avatar
darkbringer
 
Posts: 11
Joined: Fri Dec 19, 2008 11:51 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Re: Make your own PHP adoptables system

Postby Lady » Sat Feb 14, 2009 3:46 pm

Okay, I have to ask.. How do you make the adoptables grow after a certain amount of days instead of on a certain date? I like the idea of people being able to grab the adopts the entire time they're up until they are taken down, rather than when I have to remove them because they're about to grow.

It's basically how they work on here, where it doesn't matter when you adopt them but after a certain amount of time (or sometimes on a date, though I know how that works already) they will grow on their own--like after ten days or so.
ImageImageImageImage
User avatar
Lady
 
Posts: 4424
Joined: Tue Jun 24, 2008 5:44 am
My pets
My items
My wishlist
My gallery
My scenes
My dressups
Trade with me

Who is online

Users browsing this forum: Pyromaniacal and 0 guests