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

Solved Why base64 encode is different on Pocketmine and PHP Website?

Discussion in 'Help' started by LewBr, Dec 29, 2017.

  1. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Hello, I currently use the 64bit encoder on the base64_encode php system, and after I test on pocketmine I saw that there is a difference of site and pocketmine encoders, for example I tested the code using pocketmine with a png skin, and after doing that, even in any other encoder site 64 it gets another totally different code, it's as if the pocketmine did not use the correct encoder.

    All the sites that I tested result in the same coded encoder, except the Pocketmine anyone could help me about it?
    How can I decode a 64bit code on a website exactly the same as the pocketmine encoder?

    If you don't understand correctly, please ask here and i will tell examples of this.
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Can you show examples?
    Please make sure you are working on the same file, and you aren't encoding the filename instead of the file contents. Also make sure the websites you try on did not preprocess the file before encoding it.
     
  3. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    For example, i have on my database a base64_encode($player->getSkin()->getSkinData()); and when i do base64_decode(table_of_skin); on pocketmine, the skin works correctly on a NPC, but noow... i am trying to decode this skin table to an website, like to show the image of the decoded skin for website in php but when i try to decode this encoded skin on my database, it doesn't work, just don't work you can look out by this encoded skin:
    https://pastebin.com/ZLb17nDP
     
    Last edited: Jan 3, 2018
  4. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    I believe $player->getSkin()->getSkinData() returns the skins data not an image. Try adding an image attribute with the data set to the base64 encoded skin data ex)
    PHP:
    <img src="data:image/gif;base64<?php echo $encoded_skin ?>">
     
  5. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    I have tryed, not working. :/
     
    0x15f likes this.
  6. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    It has an way to get the image of the skin of a player on pocketmine? Whitout encoded or anyway? Did anyone know?
     
  7. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    I think this should work :)
    PHP:
    <?php
    //pocket mine part
    public function saveSkin(Player $player) {
        
    $skin $player->getSkin();
        
    $data $skin->getSkinData();

        
    $compressed zlib_encode($dataZLIB_ENCODING_DEFLATE9);
        
    //save $compressed to file or database
    }

    //site part
    $skin_zlib 'zlib string here';
    $skin_raw zlib_decode($skin_zlib);

    $img = @imagecreatefromstring($skin_raw);
    $png imagepng($im);
     
    LewBr likes this.
  8. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Thank you.
     
  9. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    Yep that should work, I wouldn't reccomend storing data like that. I suggest using a web storage service such as AWS S3 to store the images and just retireve them when a user requests the page.
     
  10. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Why you don't recommend? Lag?
     
  11. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    You shouldn't store large amounts of data such as raw file data (in this case the skin data) in a database unless you abseloutely have to, everytime someone visits the page your database is queried and that data is retrieved. If your site is getting large amounts of traffic it will greatly slow PHP, your site, and your database down.
     
    SOFe likes this.
  12. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Oh, i did not know that, i just want to do that to get the face of the skin from a player, like https://cravatar.eu/helmavatar/Steve/32 but they got the skin file from mojang data right? So.. how can i do that for mcpe to get the image profile from a nickname of Xbox Live? Or the skin of the game.. It is possible?
     
    0x15f likes this.
  13. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    This might work (not sure):
    PHP:
    <?php
    //insert previous code I sent
    $size 48;

    $im imagecreatefromstring($skin_raw);
    $av imagecreatetruecolor($size$size);

    imagecopyresized($av$im0088$size$size88);
    imagecolortransparent($imimagecolorat($im630));

    $png imagepng($av);
     
    LewBr likes this.
  14. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Very nice, i will test it today, thank you very mch. This is the site part right?
     
    jjun18i and 0x15f like this.
  15. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    Yes.
     
  16. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Note: not if you optimize your database correctly.
     
    0x15f likes this.
  17. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    True but the process of storing raw image data, fetching it, converting it to a png/jpg takes longer than fetching it from a service like S3.
     
  18. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    Hello, i am back on this thread because i want to ask if it's possible to create a png image on pocketmine? I have tryed to do on window but i receive this error: Call to undefined function leohardu\imagecreatefromstring()
     
  19. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    you need a bin with GD compiled. What OS are you using?
     
  20. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    OS? You mean pocketmine?
    or like windows? I am using multicraft but I can't go to the binaries.. :/
     
  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.