ai-minecraft-image
A library for converting images into Minecraft skin formats, providing a convenient way to generate character appearances programmatically. This package simplifies the process of creating Minecraft skins from various image sources.
Installation
Add ai_minecraft_image to your list of dependencies in mix.exs:
elixir
def deps do
[
{:ai_minecraft_image, "~> 0.1.0"}] end
Then, run mix deps.get to fetch the dependency.
Usage
Here are some examples demonstrating how to use ai-minecraft-image:
1. Basic Image to Skin Conversion: elixir image_path = "path/to/your/image.png"
case AiMinecraftImage.convert(image_path) do {:ok, skin_data} ->
# Skin data is a binary that can be saved to a file or used elsewhere.
File.write!("skin.png", skin_data)
IO.puts("Skin created successfully!")->
IO.puts("Error creating skin: #{reason}")end
2. Handling Different Image Formats: elixir defmodule ImageConverter do def convert_to_skin(image_path) do
case AiMinecraftImage.convert(image_path) do
{:ok, skin_data} -> {:ok, skin_data}
{:error, reason} -> {:error, reason}
endend end
case ImageConverter.convert_to_skin("path/to/another/image.jpg") do {:ok, skin_data} ->
# Process the skin data
File.write!("skin2.png", skin_data)->
IO.puts("Conversion failed: #{reason}")end
3. Using Pipes for Chained Operations: elixir "path/to/my/image.bmp" |> AiMinecraftImage.convert() |> case do {:ok, skin_data} ->
File.write!("skin3.png", skin_data)
:ok->
IO.puts("Error: #{reason}")
:errorend
4. Pattern Matching on Result Types: elixir defmodule SkinProcessor do def process_image(image_path) do
AiMinecraftImage.convert(image_path)
|> handle_result()end
defp handle_result({:ok, skin_data}) do
# Further processing of the skin data. For example, uploading it to a service.
File.write!("processed_skin.png", skin_data)
IO.puts("Skin processed successfully.")end
defp handle_result({:error, reason}) do
IO.puts("Error during processing: #{reason}")end end
SkinProcessor.process_image("path/to/yet/another/image.gif")
5. Handling Invalid Image Paths: elixir image_path = "nonexistent/image.png"
case AiMinecraftImage.convert(imagepath) do {:ok, } ->
IO.puts("This should not happen.")->
IO.puts("Image file not found. Please check the path.")->
IO.puts("An unexpected error occurred: #{reason}")end
Features
- Simple Image Conversion: Easily transform images into Minecraft skin format.
- Error Handling: Provides clear error messages for common issues like invalid file paths or unsupported image formats.
- Binary Output: Returns the skin data as a binary, ready to be saved to a file or used in other applications.
- Idiomatic Elixir API: Designed for seamless integration with Elixir projects, leveraging pattern matching and pipelines.
License
MIT
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/