npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

minecraft-drops-avatar

v1.0.1

Published

Fetch Minecraft skins directly from Mojang API and render them into algorithmic, chunky Drops-style pixel avatars.

Readme

minecraft-drops-avatar

A lightweight Minecraft skin utility that fetches profiles directly from the official Mojang API and uses an algorithmic pixel matrix to render high-fidelity, chunky Drops-style avatars on native HTML5 canvas.

Credits

The core pixel layout function used inside avDropsRenderSkin was taken directly from the client-side JavaScript source code of the mc-tools.net website. All rights to the original logic layout belong to them.

Installation

npm install minecraft-drops-avatar

Basic Usage

The package exports two helper loaders and the core matrix processing pipeline.

import { loadImageFromUrl, avDropsRenderSkin } from "minecraft-drops-avatar";

// 1. Render an avatar directly from a public URL string or static public asset path
const skinImg = await loadImageFromUrl("./img.png");
const canvas = avDropsRenderSkin(skinImg, true); // true enables the overlay layers

// 2. Append generated graphic directly into your viewport DOM node
document.body.appendChild(canvas);

Next.js Core Blueprint Example

Because Mojang blocks direct client-side requests via CORS policies, wrap the profile resolution step safely on your server layer.

1. The Server Proxy (app/api/skin/[username]/route.ts)

import { NextResponse } from "next/server";
import { getSkinUrlByUsername } from "minecraft-drops-avatar";

export async function GET(request: Request, { params }: { params: Promise<{ username: string }> }) {
  try {
    const { username } = await params;
    const skinUrl = await getSkinUrlByUsername(username);
    return NextResponse.json({ url: skinUrl });
  } catch (err: unknown) {
    const errorMessage = err instanceof Error ? err.message : "Internal server error";
    return NextResponse.json({ error: errorMessage }, { status: 500 });
  }
}

2. The Client Component Viewport (components/Avatar.tsx)

"use client";

import { useEffect, useRef, useState } from "react";
import { loadImageFromUrl, avDropsRenderSkin } from "@/lib/minecraft";

async function getSkinByUsername(username: string): Promise<HTMLImageElement> {
  const res = await fetch(`/api/skin/${username}`);
  if (!res.ok) throw new Error("Could not fetch skin via internal proxy");

  const data = (await res.json()) as { url: string };

  return loadImageFromUrl(data.url);
}

interface AvatarProps {
  username?: string;
  url?: string;
}

export function Avatar({ username, url }: AvatarProps) {
  const containerCanvasRef = useRef<HTMLCanvasElement>(null);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    let isMounted = true;

    async function renderAvatar() {
      setError(null);
      try {
        let skinImg: HTMLImageElement | null = null;

        if (url) {
          skinImg = await loadImageFromUrl(url);
        } else if (username) {
          skinImg = await getSkinByUsername(username);
        } else {
          skinImg = await getSkinByUsername("mhf_steve");
        }

        if (!isMounted || !skinImg) return;

        const generatedCanvas = avDropsRenderSkin(skinImg, true);

        const targetCanvas = containerCanvasRef.current;
        if (targetCanvas) {
          targetCanvas.width = generatedCanvas.width;
          targetCanvas.height = generatedCanvas.height;
          const ctx = targetCanvas.getContext("2d");
          if (ctx) {
            ctx.imageSmoothingEnabled = false;
            ctx.drawImage(generatedCanvas, 0, 0);
          }
        }
      } catch (err) {
        if (!isMounted) return;
        console.error(err);
        setError("Failed to render avatar");
      }
    }

    renderAvatar();

    return () => {
      isMounted = false;
    };
  }, [username, url]);

  if (error) {
    return <div style={{ color: "red", fontSize: "14px" }}>{error}</div>;
  }

  return (
    <canvas
      ref={containerCanvasRef}
      style={{
        width: "112px",
        height: "128px",
        imageRendering: "pixelated",
      }}
    />
  );
}