diff --git a/app/Services/Minecraft.php b/app/Services/Minecraft.php index 4b8b67b9..9fee615a 100644 --- a/app/Services/Minecraft.php +++ b/app/Services/Minecraft.php @@ -35,7 +35,7 @@ class Minecraft * Generate skin preview * * @link https://github.com/NC22/Minecraft-HD-skin-viewer-2D/blob/master/SkinViewer2D.class.php - * @param resource $resource + * @param string $resource * @param int $size * @param bool|string $side 'front' or 'back' * @param bool $base64 Generate image from base64 string diff --git a/tests/ServicesTest/MinecraftTest.php b/tests/ServicesTest/MinecraftTest.php new file mode 100644 index 00000000..86e98637 --- /dev/null +++ b/tests/ServicesTest/MinecraftTest.php @@ -0,0 +1,74 @@ +assertEquals(50, imagesx($avatar)); + $this->assertEquals(50, imagesy($avatar)); + + imagepng(imagecreatetruecolor(128, 64), vfsStream::url('root/skin.png')); + $avatar = Minecraft::generateAvatarFromSkin(vfsStream::url('root/skin.png'), 50); + $this->assertEquals(50, imagesx($avatar)); + $this->assertEquals(50, imagesy($avatar)); + + $avatar = Minecraft::generateAvatarFromSkin( + TextureController::getDefaultSkin(), + 50, + 'f', + true + ); + $this->assertEquals(50, imagesx($avatar)); + $this->assertEquals(50, imagesy($avatar)); + } + + public function testGeneratePreviewFromSkin() + { + imagepng(imagecreatetruecolor(64, 32), vfsStream::url('root/skin.png')); + $preview = Minecraft::generatePreviewFromSkin(vfsStream::url('root/skin.png'), 50, true); + $this->assertEquals(25, imagesx($preview)); + $this->assertEquals(50, imagesy($preview)); + + imagepng(imagecreatetruecolor(128, 64), vfsStream::url('root/skin.png')); + $preview = Minecraft::generatePreviewFromSkin(vfsStream::url('root/skin.png'), 50); + $this->assertEquals(56, imagesx($preview)); + $this->assertEquals(50, imagesy($preview)); + + imagepng(imagecreatetruecolor(128, 128), vfsStream::url('root/skin.png')); + $preview = Minecraft::generatePreviewFromSkin(vfsStream::url('root/skin.png'), 50); + $this->assertEquals(56, imagesx($preview)); + $this->assertEquals(50, imagesy($preview)); + + $preview = Minecraft::generatePreviewFromSkin( + TextureController::getDefaultSkin(), + 50, + true, + true + ); + $this->assertEquals(25, imagesx($preview)); + $this->assertEquals(50, imagesy($preview)); + } + + public function testGeneratePreviewFromCape() + { + imagepng(imagecreatetruecolor(128, 64), vfsStream::url('root/cape.png')); + $preview = Minecraft::generatePreviewFromCape(vfsStream::url('root/cape.png')); + $this->assertEquals(250, imagesx($preview)); + $this->assertEquals(166, imagesy($preview)); + } +}