#1
|
||||
|
||||
Editing Images with PHP
Hi, so there's no "save draft" option that I can find sooooooooo I'm posting this unfinished tutorial here. Sorry about that, but feel free to post on the little bit I've got thrown up here. Thanks~
Right, first note, anything I type is not going to be related to the MysidiaScript but might be cool things to edit into your script. This is because I do not have a Mys site at the moment. Eventually I will get one (probably next release or so) but for now, bear with my random findings. BUT YES! Editing images with PHP. The most I've experimented with are merging two images and recoloring an image, so I'll talk about those for now. ;D Now you may ask yourself, why would I do this? I have -insert art program here-, why do I want to use PHP? Well, this lets you edit and merge images on the fly, and can save you lots of time and space. First, we'll start with the basics. Then I'll show you how merge images and recolor them~ For these examples I'll only be referring to PNGs and GIFs since those are most used for adoptables I'd think. Defining an image: First you need to decide which file type you're using and whether you're saving it to the server or not. Each has a basic set up like so: GIF (not saved to server): PHP Code:
PNG (not saved to server): PHP Code:
But when you save to the server there's a line you must remove and some specifications you need to add to the "imageTYPE" method: PNG (saved to server): PHP Code:
Right now this only outputs the image you just made. Which is boring...and pointless. SO NOW WE EDIT THEM!
__________________
"I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic Last edited by PTGigi; 10-18-2012 at 10:51 AM. |
#2
|
||||
|
||||
Merging Images is surprisingly easier than I thought it would be when looking it up.
Instead of just outputting the image right away, we need to create an image PHP can use. Depending on the file type you can just change "imagecreatefrompng" to "imagecreatefromgif" if you want to use another filetype. PHP Code:
imagecopymerge(IMAGE1,IMAGE2,X1,Y1,X2,Y2,WIDTH,HEIGHT,TRANSPAREN CY) IMAGE1 is your first image, this is the base image which all your other images will go on top of. The new image is set to this variable. IMAGE2 is your second image, this is the image that is being placed on top of the base image. X1 and Y1 are the X and Y coordinates of the main image. Unless you're doing something special, it's best to leave this as 0,0. Note: 0,0 is the top-left of the image! X2 and Y2 are the X and Y coordinates of the second image. If you want to position it over a certain part of your previous image, change these. Though I prefer to make all the images the same size and just have the placement done through transparent edges o3o WIDTH and HEIGHT are the width and height of the main image. If you want this to be flexible you can use the functions imagesx() and imagesy() (as seen above) to get the width and the hieght of the image for you. TRANSPARENCY is how translucent the image being placed is. The numbers range between 0-100, 100 being opaque and 0 is transparent. But this fancy little code can not only merge two images, it can merge so many more images in one go! This is also rather easy in the grand scheme of things! Simply duplicate the imagecopymerge, imagecreatefrompng, and imagedestroy lines and you're all set ;D PHP Code:
Aaaaaaand that's all for merging I suppose. If you have any questions feel free to ask! In the context of adoptables, you could use this to make items or accessories for adoptables or let users make their own custom avatars and the link. Fun no? :D
__________________
"I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic Last edited by PTGigi; 10-18-2012 at 10:49 AM. |
#3
|
||||
|
||||
Recoloring an image is pretty easy, just kinda annoying to do. I'll be using GIFs as an example, because this method changes color by individual pixels, and PNGs can have lots of colors while GIFs generally have a more defined palette.
For this, we use the function imagecolorset as well as imagecolorexact. imagecolorset changes the defined color to a new one, while imagecolorexact picks the exact color we want to change. There are other functions to grab colors as well, but I find imagecolorexact to be the more flexible (there is also imagecolorclosest, which I've never tried to use and just discovered while typing up this tutorial. Sounds nicer though (grabs a color close to the one you selected if the one you selected doesn't exist), so I almost suggest using that XD). There's also imagecolorat which just defines it based on the specified pixel (x,y). It's very inflexible, so I don't really suggest using it. PHP Code:
imagecolorexact(IMAGE,RED,GREEN,BLUE); IMAGE is your image. This is so it can get the color palette from your image RED the red value of the color (value between 0-255) GREEN the green value of the color (value between 0-255) BLUE the blue value of the color (value between 0-255) DERP. I DECIDED TO START WRITING THIS IN THE MIDDLE OF CLASS. But now I have work to do sooooooo this will be left half finished until I get around to it. Sorry XD
__________________
"I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic Last edited by PTGigi; 10-19-2012 at 10:46 AM. |
#4
|
||||
|
||||
Saving this post for...IDK. I'll just keep this just in case I need it.
__________________
"I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic |
#5
|
||||
|
||||
Oh neat, thanks for writing this tutorial Gigi. I hope it will help some people out, sure it will.
__________________
Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site. |
#6
|
||||
|
||||
Hello HoF! :3
Yeah I'm sure it will XD People could use it to add items/clothing to adoptables, or make custom avatars and such. 8D Course, I got to finish this first, but the possibilities are exciting! :D
__________________
"I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic |
#7
|
||||
|
||||
Eagerly awaiting the completion of this tutorial... ;3
PS: Added your newest nuzlocke to my favorites on SJ. ;3
__________________
|
#8
|
||||
|
||||
Thank you! Busy with classes today so I'll try to get to this during the weekend~
Fixed an error with the saving to server. ^-^" (good thing I just tried to do that XD)
__________________
"I see now that the circumstances of one's birth are irrelevant; it is what you do with the gift of life that determines who you are."~Mewtwo My Adoptables|Nuzlocke Webcomic |
#9
|
||||
|
||||
Has anyone ever tried to attempt this? I want to learn to do this so badly, but the original poster never finished the tutorial.
|
#10
|
||||
|
||||
I've had rotten luck learning this, haha. Just need to find a way to code backgrounds for Pet profiles ...removable ones. Well adding a toy in front of them would be pretty cool too, as long as it was removable. OR .. something I used to do was have a backup image to draw on ... to restore it ...
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Editing Side Bar Links | GuardiansWish | Questions and Supports | 4 | 10-22-2012 09:18 AM |
Editing adoptables | Papyrus | Questions and Supports | 2 | 01-24-2012 06:53 AM |
Editing the HTML side of the CSS? | Sasoragon | Questions and Supports | 6 | 02-17-2011 10:40 AM |
Editing Content | Rozel | Questions and Supports | 4 | 01-29-2011 01:14 PM |
Editing pages. | Saphira | Questions and Supports | 1 | 01-11-2009 05:46 PM |
What's New? |
What's Hot? |
What's Popular? |