1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Can't set user's cape

Discussion in 'Development' started by aTmG, Jul 15, 2018.

  1. aTmG

    aTmG Silverfish

    Messages:
    22
    GitHub:
    ATMG
    I am trying to get custom capes from png files with:

    PHP:
    $image imagecreatefrompng($this->getDataFolder() . "cape.png");
    $data '';
    for (
    $y 0$height imagesy($image); $y $height$y++) {
        for (
    $x 0$width imagesx($image); $x $width$x++) {
            
    $color imagecolorat($image$x$y);
            
    $data .= pack("c", ($color >> 16) & 0xFF//red
                
    pack("c", ($color >> 8) & 0xFF//green
                
    pack("c"$color 0xFF//blue
                
    pack("c"255 - (($color 0x7F000000) >> 23)); //alpha
        
    }
    }
    and then setting $data to the capedata paramter in the skin class.
    I am pretty sure this is for skins only though and not capes because the post I got this from used it for skins and I get Specified skin is not valid, must be 8KiB or 16KiB. The length of the data is only 4096 characters too. How can I get something like this working for capes only instead?
     
    RyanShaw likes this.
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    According to this thread, capes have to be 8192 bytes.
    P.S: I just googled "pmmp capes" to find this.
     
    Last edited: Jul 15, 2018
    HimbeersaftLP likes this.
  3. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Methinks you mean 8192 bytes.

    @aTmG What are the dimensions of your cape.png?
     
  4. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Yep, I meant to check that number before I posted but forgot to. Edited.
     
  5. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    No, it can be used for capes too.

    I've checked this code with a simple script (can't check with PM right now, because my MCW10E has updated to v1.5... :confused:) and it should work fine.
    PHP:
    <?php

    $image 
    imagecreatefrompng("cape.png");
    $data '';
    for (
    $y 0$height imagesy($image); $y $height$y++) {
        for (
    $x 0$width imagesx($image); $x $width$x++) {
            
    $color imagecolorat($image$x$y);
            
    $data .= pack("c", ($color >> 16) & 0xFF//red
                
    pack("c", ($color >> 8) & 0xFF//green
                
    pack("c"$color 0xFF//blue
                
    pack("c"255 - (($color 0x7F000000) >> 23)); //alpha
        
    }
    }

    echo 
    strlen($data) . " bytes!\n";
    [​IMG]
    Could you please post the "cape.png", that you're trying to read?
     
  6. aTmG

    aTmG Silverfish

    Messages:
    22
    GitHub:
    ATMG
    Alright, I've tried both of these
     

    Attached Files:

  7. aTmG

    aTmG Silverfish

    Messages:
    22
    GitHub:
    ATMG
    Seems like the pngs are the issue, since they are 744 bytes and 808 bytes respectively. I don't even know if that matters though.
     
  8. Tee7even

    Tee7even Slime

    Messages:
    81
    GitHub:
    tee7even
    As I thought, those are not of the right format. Using this template, you can try to convert them, but they are both larger than a usual cape. As for what causing the problem is that those cape PNGs don't have the large empty area and that's why they're smaller when they're uncompressed.
    Red - front
    Green - back
    Blue - top
    Magenta - bottom
    Cyan - left and right sides
     

    Attached Files:

    Last edited: Jul 15, 2018
    Levi and Awzaw like this.
  9. aTmG

    aTmG Silverfish

    Messages:
    22
    GitHub:
    ATMG
    Thank you!
     
    RyanShaw and Tee7even like this.
  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.