ai-minecraft-image
v1768297.318.754
Published
Professional integration for https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/
Maintainers
Readme
ai-minecraft-image
A JavaScript library to convert images into Minecraft skin formats, providing a simple way to create custom character skins. This package simplifies the complex process of image manipulation required for Minecraft skin creation.
Installation
Install the package using npm: bash npm install ai-minecraft-image
Usage
Here are several examples demonstrating how to use ai-minecraft-image in your JavaScript/Node.js projects:
1. Basic Image Conversion:
This example shows how to convert a local image file into a Minecraft skin data buffer. javascript const { convertImageToSkin } = require('ai-minecraft-image'); const fs = require('fs');
async function createSkin() { try { const imagePath = 'path/to/your/image.png'; // Replace with your image path const skinBuffer = await convertImageToSkin(imagePath);
// Save the buffer to a file (e.g., skin.png)
fs.writeFileSync('skin.png', skinBuffer);
console.log('Skin created successfully!');} catch (error) { console.error('Error creating skin:', error); } }
createSkin();
2. Converting from a Buffer:
If you already have image data in a buffer, you can convert it directly. javascript const { convertImageBufferToSkin } = require('ai-minecraft-image'); const fs = require('fs');
async function createSkinFromBuffer() { try { // Example: Load image data into a buffer (replace with your actual buffer) const imageBuffer = fs.readFileSync('path/to/your/image.png');
const skinBuffer = await convertImageBufferToSkin(imageBuffer);
// Save the buffer to a file (e.g., skin.png)
fs.writeFileSync('skin.png', skinBuffer);
console.log('Skin created successfully from buffer!');} catch (error) { console.error('Error creating skin from buffer:', error); } }
createSkinFromBuffer();
3. Handling Errors:
It's important to handle potential errors during the conversion process. javascript const { convertImageToSkin } = require('ai-minecraft-image');
async function createSkinWithErrorHandling() { try { const imagePath = 'invalid/path/to/image.png'; // Intentionally invalid path const skinBuffer = await convertImageToSkin(imagePath);
// This will not be reached if an error occurs
console.log('Skin created successfully!');} catch (error) { console.error('Error creating skin:', error.message); // Log the error message } }
createSkinWithErrorHandling();
4. Using with Asynchronous Image Loading:
This example demonstrates usage when fetching an image from a remote URL using node-fetch.
javascript
const { convertImageBufferToSkin } = require('ai-minecraft-image');
const fs = require('fs');
const fetch = require('node-fetch'); // Ensure node-fetch is installed: npm install node-fetch
async function createSkinFromURL() { try { const imageUrl = 'https://example.com/image.png'; // Replace with a real image URL const response = await fetch(imageUrl);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const imageBuffer = await response.buffer();
const skinBuffer = await convertImageBufferToSkin(imageBuffer);
fs.writeFileSync('skin_from_url.png', skinBuffer);
console.log('Skin created successfully from URL!');} catch (error) { console.error('Error creating skin from URL:', error); } }
createSkinFromURL();
API Summary
convertImageToSkin(imagePath: string): Promise<Buffer>: Converts an image file at the given path to a Minecraft skin data buffer. Returns a Promise that resolves with a Buffer containing the skin data, or rejects with an error if the conversion fails.convertImageBufferToSkin(imageBuffer: Buffer): Promise<Buffer>: Converts an image data buffer to a Minecraft skin data buffer. Returns a Promise that resolves with a Buffer containing the skin data, or rejects with an error if the conversion fails.
License
MIT License
This package is part of the ai-minecraft-image ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/
