minecraft-avatars 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/lib/minecraft-avatars.rb +14 -0
- data/lib/minecraft-avatars/base_image.rb +19 -0
- data/lib/minecraft-avatars/exceptions.rb +26 -0
- data/lib/minecraft-avatars/face.rb +23 -0
- data/lib/minecraft-avatars/flat_character.rb +31 -0
- data/lib/minecraft-avatars/raw_skin.rb +46 -0
- data/lib/minecraft-avatars/version.rb +3 -0
- data/minecraft-avatars.gemspec +24 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jacob Jervey
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# MinecraftAvatars
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
It relies on the simple pure ruby 'chunky_png' library to parse and restructure the skins, rather than huge libraries like RMagick.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'minecraft-avatars'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install minecraft-avatars
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "minecraft-avatars/version"
|
2
|
+
require "minecraft-avatars/flat_character"
|
3
|
+
require "minecraft-avatars/face"
|
4
|
+
|
5
|
+
module MinecraftAvatars
|
6
|
+
SKIN_URL = "http://s3.amazonaws.com/MinecraftSkins"
|
7
|
+
SKIN_SECTIONS = {
|
8
|
+
:head_front => [8, 8, 8, 8],
|
9
|
+
:head_accessory => [40, 8, 8, 8],
|
10
|
+
:leg_front => [4, 20, 4, 12],
|
11
|
+
:body_front => [20, 20, 8, 12],
|
12
|
+
:arm_front => [44, 20, 4, 12]
|
13
|
+
}
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MinecraftAvatars
|
2
|
+
class BaseImage
|
3
|
+
|
4
|
+
attr_accessor :chunky
|
5
|
+
|
6
|
+
def to_blob(constraints = {})
|
7
|
+
chunky.to_blob(constraints)
|
8
|
+
end
|
9
|
+
|
10
|
+
def save(filename, constraints = {})
|
11
|
+
chunky.save(filename, constraints)
|
12
|
+
end
|
13
|
+
|
14
|
+
def write(io, constraints = {})
|
15
|
+
chunky.write(io, constraints)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module MinecraftAvatars
|
2
|
+
|
3
|
+
class BaseException < ::Exception
|
4
|
+
end
|
5
|
+
|
6
|
+
class InvalidPlayerException < BaseException
|
7
|
+
attr_accessor :player
|
8
|
+
|
9
|
+
def initialize(player)
|
10
|
+
self.player = player
|
11
|
+
self.message = "Player #{player} does not exist"
|
12
|
+
super()
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class InvalidResolutionException < BaseException
|
17
|
+
attr_accessor :resolution
|
18
|
+
|
19
|
+
def initialize(resolution)
|
20
|
+
self.resolution = resolution
|
21
|
+
self.message = "Resolution #{resolution} is not valid!"
|
22
|
+
super()
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'minecraft-avatars/raw_skin'
|
2
|
+
require 'minecraft-avatars/base_image'
|
3
|
+
require 'minecraft-avatars/exceptions'
|
4
|
+
|
5
|
+
module MinecraftAvatars
|
6
|
+
class Face < BaseImage
|
7
|
+
|
8
|
+
def initialize(player_name, size=64)
|
9
|
+
|
10
|
+
throw InvalidResolutionException unless (size & (size-1)) == 0
|
11
|
+
|
12
|
+
skin = RawSkin.new(player_name)
|
13
|
+
self.chunky = ChunkyPNG::Image.new(8, 8, ChunkyPNG::Color::TRANSPARENT)
|
14
|
+
|
15
|
+
self.chunky.compose!(skin.sections[:head_front], 0, 0)
|
16
|
+
self.chunky.compose!(skin.sections[:head_accessory], 0, 0)
|
17
|
+
|
18
|
+
self.chunky.resample_nearest_neighbor!(size, size)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'minecraft-avatars/raw_skin'
|
2
|
+
require 'minecraft-avatars/base_image'
|
3
|
+
require 'minecraft-avatars/exceptions'
|
4
|
+
|
5
|
+
module MinecraftAvatars
|
6
|
+
class FlatCharacter < BaseImage
|
7
|
+
|
8
|
+
def initialize(player_name, height=64, accessories=true)
|
9
|
+
|
10
|
+
throw InvalidResolutionException unless (height & (height-1)) == 0
|
11
|
+
|
12
|
+
width = height/2
|
13
|
+
|
14
|
+
skin = RawSkin.new(player_name)
|
15
|
+
|
16
|
+
self.chunky = ChunkyPNG::Image.new(16, 32, ChunkyPNG::Color::TRANSPARENT)
|
17
|
+
|
18
|
+
self.chunky.compose!(skin.sections[:head_front], 4, 0)
|
19
|
+
self.chunky.compose!(skin.sections[:head_accessory], 4, 0) if accessories
|
20
|
+
self.chunky.compose!(skin.sections[:body_front], 4, 8)
|
21
|
+
self.chunky.compose!(skin.sections[:leg_front], 4, 20)
|
22
|
+
self.chunky.compose!(skin.sections[:leg_front].mirror, 8, 20)
|
23
|
+
self.chunky.compose!(skin.sections[:arm_front], 0, 8)
|
24
|
+
self.chunky.compose!(skin.sections[:arm_front].mirror, 12, 8)
|
25
|
+
|
26
|
+
self.chunky.resample_nearest_neighbor!(width, height)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'chunky_png'
|
3
|
+
require 'minecraft-avatars/exceptions'
|
4
|
+
|
5
|
+
module MinecraftAvatars
|
6
|
+
|
7
|
+
class RawSkin
|
8
|
+
|
9
|
+
attr_accessor :player_name
|
10
|
+
attr_accessor :sections
|
11
|
+
attr_accessor :image
|
12
|
+
|
13
|
+
def initialize(player_name)
|
14
|
+
|
15
|
+
self.sections = {}
|
16
|
+
self.player_name = player_name
|
17
|
+
begin
|
18
|
+
image_uri = open "#{MinecraftAvatars::SKIN_URL}/#{player_name}.png"
|
19
|
+
raw_data = image_uri.read
|
20
|
+
rescue OpenURI::HTTPError => e
|
21
|
+
if e.message == "403 Forbidden"
|
22
|
+
raise MinecraftAvatars::InvalidPlayerException.new(player_name)
|
23
|
+
else
|
24
|
+
raise e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
self.image = ChunkyPNG::Image.from_blob(raw_data)
|
29
|
+
|
30
|
+
deconstruct
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def deconstruct
|
35
|
+
|
36
|
+
MinecraftAvatars::SKIN_SECTIONS.each do |name, section|
|
37
|
+
x, y, width, height = section
|
38
|
+
chunk = self.image.crop x, y, width, height
|
39
|
+
|
40
|
+
self.sections[name] = chunk
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'minecraft-avatars/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "minecraft-avatars"
|
8
|
+
spec.version = MinecraftAvatars::VERSION
|
9
|
+
spec.authors = ["Jacob Jervey"]
|
10
|
+
spec.email = ["jacob.jervey@gmail.com"]
|
11
|
+
spec.description = %q{Ruby gem for retrieving Minecraft skins and returning them in a variety of sizes and formats}
|
12
|
+
spec.summary = %q{Minecraft skin API}
|
13
|
+
spec.homepage = "https://github.com/jacobjervey/minecraft-avatars"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "chunky_png", "~> 1.2.8"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minecraft-avatars
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jacob Jervey
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: chunky_png
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.8
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.8
|
62
|
+
description: Ruby gem for retrieving Minecraft skins and returning them in a variety
|
63
|
+
of sizes and formats
|
64
|
+
email:
|
65
|
+
- jacob.jervey@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- lib/minecraft-avatars.rb
|
76
|
+
- lib/minecraft-avatars/base_image.rb
|
77
|
+
- lib/minecraft-avatars/exceptions.rb
|
78
|
+
- lib/minecraft-avatars/face.rb
|
79
|
+
- lib/minecraft-avatars/flat_character.rb
|
80
|
+
- lib/minecraft-avatars/raw_skin.rb
|
81
|
+
- lib/minecraft-avatars/version.rb
|
82
|
+
- minecraft-avatars.gemspec
|
83
|
+
homepage: https://github.com/jacobjervey/minecraft-avatars
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.8.25
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Minecraft skin API
|
108
|
+
test_files: []
|