mythic Posted March 13, 2010 Share Posted March 13, 2010 I'm sorry for the extremely lame title. The problem I'm having is that I'm using phpbb3 and a mod on it to create avatars. The mod is no longer supported, dude dropped off the face of the earth. But right now, we're having a trouble with our images saving all messed up. Because there are too many colors. They look like this: That hair is meant to be black... Anyway, I'm wondering how I can fix this in the coding, or if its because of the GD library. The code where it saves the image is here: // START Save case save: // Check if user has an Avatar yet! If not, create one! $sql = "SELECT * FROM $table_avatar_characters WHERE user = $user_id"; $result = $db->sql_query($sql); $tot_users = $db->sql_affectedrows($result); if ($tot_users < 1) { $sql2 = "SELECT * FROM $table_avatar_layers ORDER BY position DESC"; $result2 = $db->sql_query($sql2); $tot_layers = $db->sql_affectedrows($result2); $insert_values = ''; $insert_layers = ''; for( $i = 0; $i < $tot_layers; $i++ ) { $row2 = $db->sql_fetchrow($result2); $row2_name = $row2['name']; $insert_layers .= ",$row2_name"; $insert_values .= ",'' "; } // Create character! $sql3 = "INSERT INTO $table_avatar_characters (user$insert_layers) VALUES ('$user_id'$insert_values)"; $db->sql_query ( $sql3 ); } // Now that they got a character, insert the selected images into the db! $sql = "SELECT * FROM $table_avatar_layers ORDER BY position DESC"; $result = $db->sql_query ( $sql ); $tot_layers = $db->sql_affectedrows($result); $insert_values = ''; $insert_layers = ''; $dont_show = ''; $no_show_list = ''; $dont_show_layers = ''; for( $i = 0; $i < $tot_layers; $i++ ) { $row = $db->sql_fetchrow($result); $insert_layers .= ",$row2_name"; if($insert_values != "") { $insert_values .= ', '; } $row_name = $row['name']; $post_row_name = $_POST[$row_name]; $insert_values .= "$row_name = '$post_row_name'"; } $camorea_display = 'avatar_save'; // Update character! $sql = "UPDATE $table_avatar_characters SET $insert_values WHERE user = '$user_id' "; $db->sql_query ( $sql ); // START At last, create the PNG image! $tot_width = $avatar_width; $tot_height = $avatar_height; // Get all layers in the correct order! $sql = "SELECT * FROM $table_avatar_layers ORDER BY position ASC"; $result = $db->sql_query ( $sql ); $tot_layers = $db->sql_affectedrows($result); $crtavatar = false; for( $i = 0; $i < $tot_layers; $i++ ) { $row = $db->sql_fetchrow($result); if ($_POST[$row['name']] != 'spacer.gif') { if($crtavatar == false) { $avatar_front = @$avatar_build($phpbb_root_path.$sprites_path.'/'.$_POST[$row['name']]); $crtavatar = true; } else { $image = @$avatar_build($phpbb_root_path.$sprites_path.'/'.$_POST[$row['name']]); @imagecopy ($avatar_front, $image, 0, 0, 0, 0, $tot_width, $tot_height); @ImageDestroy($image); } } } $save = $user_id; imagealphablending($avatar_front, false); imagesavealpha($avatar_front, true); imagepng($avatar_front, $phpbb_root_path . $chars_path . '/' . $save . '.png'); imagedestroy($avatar_front); // END At last, create the PNG image! $exported_save = $chars_path."/".$save.".png"; break; // END Save I have a feeling that it's saving as 8-bit, but I want to up that so that the images don't appear messed up. Does anyone know how? Link to comment https://forums.phpfreaks.com/topic/195080-png-saving-with-messed-up-colors/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.