Giter VIP home page Giter VIP logo

minecraft-avatars's Introduction

minecraft-avatars

This is a Ruby gem that allows you to easily retrieve a player's raw Minecraft skin from Amazon S3 (http://s3.amazonaws.com/MinecraftSkins/Notch.png) and restructure it into a variety of usable sizes and formats.

It relies on the simple, pure-ruby 'chunky_png' gem to parse and restructure the skins, rather than huge libraries like RMagick.

It uses nearest neighbor resizing to perfectly resize the avatars to the size you desire.

Installation

Add this line to your application's Gemfile:

gem 'minecraft-avatars'

And then execute:

$ bundle

Or install it yourself as:

$ gem install minecraft-avatars

Documentation

Usage of minecraft-avatars is extremely simple and straightforward. As of right now, there are two types of avatars.

# Extract the 8x8 face and head accessory to a 64x64 image
image = MinecraftAvatars::Face.new(player_name, size = 64, accessories = true)

# Extract the standard character avatar (front of the head, arms, legs, and torso) to a 32x64 image
image = MinecraftAvatars::FlatCharacter.new(player_name, size = 64, accessories = true)

Keep in mind that avatars are not lazy-loaded and perform an HTTP request every time the class is intialized.

# Get the raw blob (this is what youll likely be using)
image.to_blob(constraints = {})

# Save the image to a file
image.save(file_path, constraints = {})

# Output the image to an I/O stream
image.write(io, constraints = {})

All returned avatars share a set of methods used for exporting the image data in a variety of ways. These methods are simply aliases to the internal ChunkyPNG::Canvas::PNGEncoding methods. Therefor, you can use the same parameters you can for ChunkyPNG.

The documentation can be found at http://rdoc.info/gems/chunky_png/ChunkyPNG/Canvas/PNGEncoding

Examples

Retrieve a 128x128 face avatar for Notch with no accessories and save it to /tmp/notch.png. Also catch exceptions incase Notch somehow doesn't exist.

begin
    image = MinecraftAvatars::Face.new "Notch", 128, false
    image.save '/tmp/notch.png'
rescue MinecraftAvatars::InvalidPlayerException => e
    # Notch doesn't exist? WHAT THE FU-
end

minecraft-avatars's People

Contributors

jacobjervey avatar

Watchers

 avatar  avatar

Forkers

melair

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.