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

must be of the type string, resource given,

Discussion in 'Development' started by Levi, Apr 13, 2019.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    $capeData = @imagecreatefrompng( $this->plugin->getDataFolder() . "cape.png" );
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    please give all the code, and show which line does the error come from
     
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    /** @var Player $player */
    /** @var string $capeData */
    $skin = $player->getSkin();
    $player->setSkin(new Skin($skin->getSkinId(), $skin->getSkinData(), $capeData, $skin->getGeometryName(), $skin->getGeometryData()));
     
  4. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    capeData must be a string just like SkinData
     
  5. Emirhan Akpınar

    Emirhan Akpınar Slime

    Messages:
    90
    It must be string, not resource.

    Firstly convert .png to string with this function. You can use this on every gd operation.
    PHP:
    public function convertToString(string $file) : string{
            
    assert(file_exists($file));
            
    $image imagecreatefrompng($file);
            
    $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)
                        . 
    pack("c", ($color >> 8) & 0xFF)
                        . 
    pack("c"$color 0xFF)
                        . 
    pack("c"255 - (($color 0x7F000000) >> 23));
                }
            }
            
    imagedestroy($image);
            return 
    $data;
    }
    After set player skin.
    PHP:
    $capeData $this->convertToString($this->plugin->getDataFolder() . "cape.png");
    $skin $player->getSkin();
    $player->setSkin(new Skin($skin->getSkinId(), $skin->getSkinData(), $capeData$skin->getGeometryName(), $skin->getGeometryData()));
    $player->sendSkin();
    :)
     
    Last edited: Apr 14, 2019
    Levi likes this.
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I think you showed the wrong error line. You are indeed passing a string there. Check your line numbers again
     
    jasonwynn10 likes this.
  7. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
     
  8. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    thanks cap
     
  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.