Solved Error for Skin

Discussion in 'Development' started by xXNiceAssassinlo YT, Feb 13, 2019.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    My friend created a skin on blockbench app and the module, the size of png file is 128 x 128 of, but I get err saying invalid skin.
     
  2. wolfdale

    wolfdale Zombie

    Messages:
    258
    Can you show how do you convert the png to skin?
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
     

    Attached Files:

  4. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    he means the code
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
  6. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
  7. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    I think this is the error you're getting
    Code:
    if(!$skin->isValid()){
       throw new \InvalidStateException("Specified skin is not valid, must be 8KiB or 16KiB");
    }
    
    the error says exactly what the problem is
     
  8. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    ... how tf am I suppose to make it 8KiB or 16 bc size is 128x128
     
  9. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    it just means that the size isn't 128x128
     
  10. wolfdale

    wolfdale Zombie

    Messages:
    258
    The code you provided only reads up to a width of 64, so you only read 64 x 128 of the file
    Use this instead
    PHP:
    public function SetSkin($playerstring $filestring $exstring $geo){
            
    $skin $player->getSkin();
            
    $path $this->getDataFolder() . $file $ex;
            
    $img = @imagecreatefrompng($path);
            
    $skinbytes "";
            list(
    $width$height) = @getimagesize($path);
            for(
    $y 0$y $height$y++){
                for(
    $x 0$x $width$x++){
                    
    $colorat = @imagecolorat($img$x$y);
                    
    $a = ((~((int)($colorat >> 24))) << 1) & 0xff;
                    
    $r = ($colorat >> 16) & 0xff;
                    
    $g = ($colorat >> 8) & 0xff;
                    
    $b $colorat 0xff;
                    
    $skinbytes .= chr($r) . chr($g) . chr($b) . chr($a);
                }
            }
            @
    imagedestroy($img);
            
    $player->setSkin(new Skin($skin->getSkinId(), $skinbytes"""geometry.rmsp." $geofile_get_contents($this->getDataFolder() . "geometry.json")));
            
    $player->sendSkin();
            
    $player->sendMessage(C::GREEN "You have disguise as " $file);
        }
     
    xXNiceAssassinlo YT likes this.
  11. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    here's another solution if you want
    PHP:
    $img = @\imagecreatefrompng($path);
    $byte "";
    for(
    $y 0$height imagesy($img); $y $height$y++){
        for(
    $x 0$width imagesx($img); $x $width$x++){
            
    $color imagecolorat($img$x$y);
            
    $byte .= pack("c", ($color >> 16) & 0xFF//red
                
    pack("c", ($color >> 8) & 0xFF//green
                
    pack("c"$color 0xFF//blue
                
    pack("c"255 - (($color 0x7F000000) >> 23)); //alpha
        
    }
    }
     
  12. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    Ty I must be blind I didn’t saw that 64
     
  13. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    maybe because you shouldn't copy paste code
     
  14. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    .. well you shouldn’t reply if u didn’t know wolfdale helped than u made it short
     
  15. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
     
  16. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    But size was 128x128
     
  17. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    I meant your $skinBytes variable
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.