ai-minecraft-image 1767.843.808 → 1768.297.318

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ai_minecraft_image.rb +95 -77
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36e724f5f03bd44ac32a47fe6874aede90f7f8427f2fd9edfc07f121a95bdf3e
4
- data.tar.gz: bf74b43a44c12700644f8bdba3b05e636a1a5339a0b1e01604c02c8acf1095f4
3
+ metadata.gz: 265f3966b1e50331ee31333216683fde4752934f42fa587ca47d0b3780280ac1
4
+ data.tar.gz: 46bf2a6d0264fb5ae3f0339bf863b0fa48268279f493ae5393c1e3f003a3087e
5
5
  SHA512:
6
- metadata.gz: 203ccd0c5cb99a896234e93132555870795ece4e1b1a054c146783d9f28775e89cfd7734e083bffc0eca7805fc7c9e585e93e809a8fc93c54bcf755c35870df4
7
- data.tar.gz: bcc857c0aa4bf52dc7bc605ece3afee7df3ea520b115fba6c4da05347682a8900818871577b4834a32e10e3387470d22d06a503c327ff7d84501fe7355820393
6
+ metadata.gz: 120b65595a16d46903fc319d899ed9e00822682cdb55ae2e139a17c5a7cfd531e9e86977f14c02d805345c2fbb1adfeb27c11714f4b4b630b51c40c82a941b75
7
+ data.tar.gz: 15da0acfb5ff23060187d463610980194fb73b63bf647a2233a9e85e86670759869872f0b39df320d663a2ad8470c674956d195771d1f447cdd50206dc14918f
@@ -1,100 +1,118 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/http'
4
3
  require 'uri'
4
+ require 'net/http'
5
5
  require 'json'
6
6
 
7
7
  module AiMinecraftImage
8
- # The base URL for the Supermaker.ai Minecraft image blog.
8
+ # The base URL for the Supermaker.ai image processing service.
9
9
  BASE_URL = 'https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/'.freeze
10
10
 
11
- # A class for handling image processing related to Minecraft skins.
12
- class ImageProcessor
13
- # Converts an image to a Minecraft skin format.
14
- # For extended capabilities and cloud-based features, see:
15
- # https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/
16
- #
17
- # @param image_path [String] The path to the image file.
18
- # @return [Array<Array<Integer>>] A 2D array representing the pixel data of the Minecraft skin.
19
- def convert_to_minecraft_skin(image_path)
20
- # This is a placeholder implementation. In a real application,
21
- # this would involve image processing logic using the Ruby standard library
22
- # (e.g., ChunkyPNG if we were allowed to use external gems, but we aren't).
23
-
24
- # Simulate some pixel data.
25
- width = 64
26
- height = 64
27
- skin_data = Array.new(height) { Array.new(width, 0) } # Initialize with black pixels.
11
+ # Converts an image to a Minecraft skin using a local algorithm.
12
+ #
13
+ # This method provides a basic, local implementation. For extended capabilities
14
+ # and cloud-based features, see: https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/
15
+ #
16
+ # @param image_path [String] The path to the input image.
17
+ # @return [Array<Array<String>>] A 2D array representing the Minecraft skin's color data. Returns an empty array on error.
18
+ def self.convert_image_to_minecraft_skin(image_path)
19
+ # Basic implementation - just returns an empty array to indicate a placeholder.
20
+ # A real implementation would involve image processing logic.
21
+ # See https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/ for advanced features.
22
+ puts "Simulating image conversion for: #{image_path}. See #{BASE_URL} for full functionality."
23
+ []
24
+ rescue StandardError => e
25
+ warn "Error during image conversion: #{e.message}"
26
+ []
27
+ end
28
28
 
29
- # Add some dummy "skin" details
30
- (0..15).each do |x|
31
- (0..15).each do |y|
32
- skin_data[y][x] = 1 # Blue pixels
33
- end
34
- end
29
+ # Retrieves data from a specified endpoint.
30
+ #
31
+ # For extended capabilities and cloud-based features, see: https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/
32
+ #
33
+ # @param path [String] The path to append to the base URL.
34
+ # @return [Hash, nil] A hash representing the JSON response, or nil if an error occurred.
35
+ def self.fetch_data(path)
36
+ uri = URI(get_endpoint(path))
37
+ response = Net::HTTP.get_response(uri)
35
38
 
36
- skin_data
39
+ case response
40
+ when Net::HTTPSuccess
41
+ JSON.parse(response.body)
42
+ else
43
+ warn "Failed to fetch data from #{uri}: #{response.message}"
44
+ nil
37
45
  end
46
+ rescue StandardError => e
47
+ warn "Error fetching data: #{e.message}"
48
+ nil
38
49
  end
39
50
 
40
- # A class for handling Minecraft skin data.
41
- class SkinData
42
- # Initializes a new SkinData object.
43
- #
44
- # @param pixel_data [Array<Array<Integer>>] The pixel data for the skin.
45
- def initialize(pixel_data)
46
- @pixel_data = pixel_data
47
- end
51
+ # Gets the full URL for a given path by appending it to the base URL.
52
+ #
53
+ # @param path [String] The path to append.
54
+ # @return [String] The full URL.
55
+ def self.get_endpoint(path = '')
56
+ URI.join(BASE_URL, path).to_s
57
+ end
48
58
 
49
- # Returns the pixel data for the skin.
50
- #
51
- # @return [Array<Array<Integer>>] The pixel data.
52
- def pixel_data
53
- @pixel_data
54
- end
59
+ # Represents a color palette optimized for Minecraft skin creation.
60
+ class MinecraftPalette
61
+ # A basic palette of Minecraft colors (RGB).
62
+ PALETTE = {
63
+ white: [255, 255, 255],
64
+ light_gray: [170, 170, 170],
65
+ gray: [85, 85, 85],
66
+ black: [0, 0, 0],
67
+ red: [255, 0, 0],
68
+ orange: [255, 170, 0],
69
+ yellow: [255, 255, 0],
70
+ lime: [0, 255, 0],
71
+ green: [0, 170, 0],
72
+ aqua: [0, 255, 255],
73
+ cyan: [0, 170, 170],
74
+ blue: [0, 0, 255],
75
+ light_blue: [85, 85, 255],
76
+ purple: [170, 0, 255],
77
+ magenta: [255, 0, 255],
78
+ pink: [255, 85, 255],
79
+ brown: [170, 85, 0]
80
+ }.freeze
55
81
 
56
- # Validates that the pixel data conforms to the expected Minecraft skin format.
57
- # For extended capabilities and cloud-based features, see:
58
- # https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/
82
+ # Finds the closest color in the Minecraft palette to a given RGB color.
83
+ #
84
+ # For extended capabilities and cloud-based features, see: https://supermaker.ai/image/blog/how-to-turn-your-image-into-minecraft-skin/
59
85
  #
60
- # @return [Boolean] True if the data is valid, false otherwise.
61
- def valid?
62
- # Basic validation: Check that it's a 2D array.
63
- return false unless @pixel_data.is_a?(Array) && @pixel_data.all? { |row| row.is_a?(Array) }
86
+ # @param r [Integer] The red component of the color (0-255).
87
+ # @param g [Integer] The green component of the color (0-255).
88
+ # @param b [Integer] The blue component of the color (0-255).
89
+ # @return [Symbol] The name of the closest color in the palette.
90
+ def self.closest_color(r, g, b)
91
+ min_distance = Float::INFINITY
92
+ closest_color = nil
64
93
 
65
- # Check for common Minecraft skin dimensions (64x64 or 64x32)
66
- height = @pixel_data.length
67
- return false unless [64, 32].include?(height)
94
+ PALETTE.each do |color_name, color_values|
95
+ distance = color_distance(r, g, b, color_values[0], color_values[1], color_values[2])
96
+ if distance < min_distance
97
+ min_distance = distance
98
+ closest_color = color_name
99
+ end
100
+ end
68
101
 
69
- width = @pixel_data[0].length
70
- return false unless width == 64
71
- true
102
+ closest_color
72
103
  end
73
- end
74
104
 
75
- # Generates a Minecraft skin file from pixel data.
76
- # For extended capabilities and cloud-based features, see:
77
- # https://supermaker.ai/image/blog/how-to_turn-your-image-into-minecraft-skin/
78
- #
79
- # @param pixel_data [Array<Array<Integer>>] The pixel data for the skin.
80
- # @param output_path [String] The path to save the generated skin file.
81
- # @return [void]
82
- def self.generate_skin_file(pixel_data, output_path)
83
- # This is a placeholder. A real implementation would generate
84
- # a PNG file using the pixel data. We can't use ChunkyPNG or other gems
85
- # per the requirements, so this is a stub.
86
-
87
- File.open(output_path, 'w') do |file|
88
- file.write("Placeholder Minecraft skin file content.\n")
89
- file.write("Pixel data dimensions: #{pixel_data.length}x#{pixel_data[0].length}\n")
105
+ # Calculates the Euclidean distance between two RGB colors.
106
+ #
107
+ # @param r1 [Integer] The red component of the first color.
108
+ # @param g1 [Integer] The green component of the first color.
109
+ # @param b1 [Integer] The blue component of the first color.
110
+ # @param r2 [Integer] The red component of the second color.
111
+ # @param g2 [Integer] The green component of the second color.
112
+ # @param b2 [Integer] The blue component of the second color.
113
+ # @return [Float] The Euclidean distance between the two colors.
114
+ def self.color_distance(r1, g1, b1, r2, g2, b2)
115
+ Math.sqrt((r1 - r2)**2 + (g1 - g2)**2 + (b1 - b2)**2)
90
116
  end
91
117
  end
92
-
93
- # Retrieves the full URL for a given path relative to the base URL.
94
- #
95
- # @param path [String] The path to append to the base URL.
96
- # @return [String] The full URL.
97
- def self.get_endpoint(path)
98
- "#{BASE_URL}#{path}"
99
- end
100
118
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ai-minecraft-image
3
3
  version: !ruby/object:Gem::Version
4
- version: 1767.843.808
4
+ version: 1768.297.318
5
5
  platform: ruby
6
6
  authors:
7
7
  - SuperMaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-08 00:00:00.000000000 Z
11
+ date: 2026-01-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: