Jupeto Posted August 30, 2012 Group: Members Topic Count: 34 Topics Per Day: 0.01 Content Count: 225 Reputation: 39 Joined: 01/20/12 Last Seen: October 6, 2024 Share Posted August 30, 2012 (edited) I'm just wondering if how can I apply a palette on my created single head frame resource something like in the code below $head = imagecreatefrompng('first.png'); I'm using PHP to apply .pal file. Also, please be noted that the image above doesn't come / parsed from .spr file Edited August 30, 2012 by Jupeto Quote Link to comment Share on other sites More sharing options...
GreenBox Posted August 30, 2012 Group: Members Topic Count: 9 Topics Per Day: 0.00 Content Count: 303 Reputation: 101 Joined: 11/13/11 Last Seen: October 11, 2023 Share Posted August 30, 2012 You can't do this on a PNG as the colors are stored as RGBA colors, but you can find the color index by comparing the pixel against the original palette, then swap the colors with the new palette. Example: $origpallete = array(...); $newpallete = array(...); for ($x = 0; $x < $width; $x++) { for ($x = 0; $x < $width; $x++) { $color = getcolor($x, $y); for ($i = 0; $i < count($origpallete); $i++) { if ($origpallete[$i] == $color) break; } if ($i < count($newpallete)) setpixel($x, $y, $newpallete[$i]); } } Quote Link to comment Share on other sites More sharing options...
Jupeto Posted August 31, 2012 Group: Members Topic Count: 34 Topics Per Day: 0.01 Content Count: 225 Reputation: 39 Joined: 01/20/12 Last Seen: October 6, 2024 Author Share Posted August 31, 2012 (edited) I really don't know how to work with palettes To any of you know how please do help, Thanks here's my current code $sprite = new sprite('../../data/sprite/head/' . $gender . '/' . $head . '_' . $gender . '.spr'); $sprite_resource = $sprite->displayFrame( $frame ); $palette_handle = fopen( '../../data/palette/head/9.pal', "r" ); $palette_data = fread( $palette_handle, 1024 ); /* Open the base job image */ $base_job = imagecreatefrompng('../../data/sprite/body/1.png'); $frame = $sprite->frames[$frame]; $width = $frame['width']; $height = $frame['height']; $data = $frame['data']; $pal = array(); for ( $i=0, $j=4; $i<256; ++$i, ++$j ) $pal[$i] = imagecolorallocate( $sprite_resource, ord($sprite->palette[$j++]), ord($sprite->palette[$j++]), ord($sprite->palette[$j++]) ); for ( $i=0; $i < $width * $height; ++$i ) { imagesetpixel( $sprite_resource, $i % $width, $i/$width | 0, $pal[ ord($data[$i]) ] ); } /* Create the base head image*/ imagegif( $sprite_resource, $temp_file ); This currently results to this image; I only want the head to be dyed Edited August 31, 2012 by Jupeto Quote Link to comment Share on other sites More sharing options...
Camilla Posted August 31, 2012 Group: Members Topic Count: 21 Topics Per Day: 0.00 Content Count: 345 Reputation: 231 Joined: 03/21/12 Last Seen: December 12, 2024 Share Posted August 31, 2012 Not sure it will help but that's how I do it. I'll use pseudo-code, because I forgot about PHP. Make sure your PNG Head is in 8 bits. Export the palette of your PNG in .pal (using photoshop), let's name it "Original_Head.pal". Remove the photoshop header in your .pal file. Load "Original_Head.pal" in hex string in your php script. => $hex_head_pal Load "New.pal" that you want to apply to your head in hex string => $hex_new_pal Load your "Head.png" in hex string => $hex_head_image Now do: $hex_head_image.replace($hex_head_pal, $hex_new_pal). Then create your image using a png header and echo the binary content of the image. Load your image in a src. Quote Link to comment Share on other sites More sharing options...
Jupeto Posted September 1, 2012 Group: Members Topic Count: 34 Topics Per Day: 0.01 Content Count: 225 Reputation: 39 Joined: 01/20/12 Last Seen: October 6, 2024 Author Share Posted September 1, 2012 (edited) Well I'm now able to extract the frame from each .spr file. I was reading this thread but I'm still not getting the right syntax http://www.google.co...8kW0gN7uoPoff6w Edited September 1, 2012 by Jupeto Quote Link to comment Share on other sites More sharing options...
KeyWorld Posted September 3, 2012 Group: Members Topic Count: 9 Topics Per Day: 0.00 Content Count: 379 Reputation: 304 Joined: 11/10/11 Last Seen: December 2, 2014 Share Posted September 3, 2012 Well, I will release my php charsim soon, but I can help for now. There is a lot of codes that aren't used in your code so it's hard to know what you do exactly. But for sure, the $j in the for() should be init as 0 (not 4). Well if you need help it will be better to post the whole script, here or in pm Quote Link to comment Share on other sites More sharing options...
Question
Jupeto
I'm just wondering if how can I apply a palette on my created single head frame resource something like in the code below
I'm using PHP to apply .pal file. Also, please be noted that the image above doesn't come / parsed from .spr file
Edited by JupetoLink to comment
Share on other sites
5 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.