masked_ape_club 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +224 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/collection/0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D.json +110004 -0
- data/lib/collection/ape.rb +110029 -0
- data/lib/masked_ape_club/version.rb +5 -0
- data/lib/masked_ape_club.rb +134 -0
- data/sig/masked_ape_club.rbs +4 -0
- metadata +105 -0
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'masked_ape_club/version'
|
4
|
+
require_relative './collection/ape'
|
5
|
+
|
6
|
+
require 'uri'
|
7
|
+
require 'net/http'
|
8
|
+
require 'rmagick'
|
9
|
+
require 'json'
|
10
|
+
|
11
|
+
|
12
|
+
module MaskedApeClub
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
include Collection
|
16
|
+
|
17
|
+
class Load
|
18
|
+
|
19
|
+
attr_reader :gateway, :collection, :image
|
20
|
+
|
21
|
+
|
22
|
+
def initialize( gateway: 'https://ipfs.io/ipfs/' )
|
23
|
+
@gateway = gateway
|
24
|
+
# puts ">> #{@gateway}"
|
25
|
+
@collection = Collection.load( @gateway )
|
26
|
+
@image = nil
|
27
|
+
return true
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def mask_ape( id: 1, fuzz: "1%" )
|
32
|
+
blob = self.load( id: id )
|
33
|
+
image = self.mask( fuzz: fuzz )
|
34
|
+
return image
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def load( id: 1 )
|
39
|
+
token = @collection
|
40
|
+
.find { | a | a['token_id'].to_i == id }
|
41
|
+
|
42
|
+
url = token['metadata']['image']
|
43
|
+
uri = URI( url )
|
44
|
+
blob = Net::HTTP.get( uri )
|
45
|
+
@image = Magick::Image.from_blob( blob ).first
|
46
|
+
|
47
|
+
return true
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def write( path: )
|
52
|
+
@image.write( path )
|
53
|
+
return true
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def mask( fuzz: '1%', position: 1500, size: 2 )
|
58
|
+
image = @image
|
59
|
+
image.format = 'PNG'
|
60
|
+
image.fuzz = fuzz
|
61
|
+
|
62
|
+
pixels = []
|
63
|
+
image
|
64
|
+
.each_pixel { | pixel, c, r | pixels.push( pixel ) }
|
65
|
+
|
66
|
+
background_color = pixels[ position ]
|
67
|
+
.to_color( Magick::AllCompliance, false, 8, true )
|
68
|
+
|
69
|
+
mask = Magick::Image
|
70
|
+
.new( image.columns, image.rows) { self.background_color = 'transparent' }
|
71
|
+
|
72
|
+
|
73
|
+
size = 2
|
74
|
+
cols = 631
|
75
|
+
rows = 631
|
76
|
+
|
77
|
+
img = Magick::Image.new( 631, 631) { self.background_color = 'transparent' }
|
78
|
+
|
79
|
+
[
|
80
|
+
[ 0, 0, size, 0, 0, size, 0, 0 ],
|
81
|
+
[ cols, 0, cols-size, 0, cols, size, cols, 0 ],
|
82
|
+
[ 0, rows, 0, rows-size, size, rows, 0, rows ],
|
83
|
+
[ cols, rows, cols, rows-size, cols-size, rows, 0, rows ]
|
84
|
+
].each { | a |
|
85
|
+
triangle = Magick::Draw.new
|
86
|
+
triangle.fill( background_color )
|
87
|
+
triangle.stroke('transparent')
|
88
|
+
triangle.polygon( a[ 0 ], a[ 1 ], a[ 2 ], a[ 3 ], a[ 4 ], a[ 5 ], a[ 6 ], a[ 7 ] )
|
89
|
+
triangle.draw( img )
|
90
|
+
}
|
91
|
+
|
92
|
+
w = 2
|
93
|
+
[
|
94
|
+
[ 0, 0, w, rows ],
|
95
|
+
[ 0, 0, cols, w ],
|
96
|
+
[ cols-w, 0, cols, cols ],
|
97
|
+
[ 0, rows, cols, rows-w ]
|
98
|
+
].each { | a |
|
99
|
+
gc = Magick::Draw.new
|
100
|
+
gc.fill( background_color )
|
101
|
+
gc.rectangle( a[ 0 ], a[ 1 ], a[ 2 ], a[ 3 ] )
|
102
|
+
gc.draw( img )
|
103
|
+
}
|
104
|
+
|
105
|
+
@image = image
|
106
|
+
.composite( img, 0, 0, Magick::OverCompositeOp)
|
107
|
+
.paint_transparent( background_color )
|
108
|
+
|
109
|
+
return @image
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def censored( upper_left_x: 240, upper_left_y: 210, lower_right_x: 460, lower_right_y: 270, color: 'black' )
|
114
|
+
censored = Magick::Draw.new
|
115
|
+
censored.fill( color )
|
116
|
+
censored.rectangle( upper_left_x, upper_left_y, lower_right_x, lower_right_y )
|
117
|
+
censored.draw( @image )
|
118
|
+
|
119
|
+
return true
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
def background( blob:, gravity: Magick::CenterGravity, offset_x: 0, offset_y: 0, width: 631, height: 631)
|
124
|
+
background = Magick::Image.from_blob( blob ).first
|
125
|
+
background.format = 'PNG'
|
126
|
+
background.crop_resized!( 631, 631, gravity )
|
127
|
+
|
128
|
+
@image.resize_to_fit!( width, height )
|
129
|
+
@image = background.composite( @image, offset_x, offset_y, Magick::OverCompositeOp )
|
130
|
+
|
131
|
+
return true
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: masked_ape_club
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- a6b8
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-http
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: uri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.10.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.10.1
|
55
|
+
description: Let the apes out and free them from backgrounds. With the goal to bring
|
56
|
+
them to context.
|
57
|
+
email:
|
58
|
+
- hello@13plus4.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".rubocop.yml"
|
64
|
+
- CHANGELOG.md
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/collection/0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D.json
|
74
|
+
- lib/collection/ape.rb
|
75
|
+
- lib/masked_ape_club.rb
|
76
|
+
- lib/masked_ape_club/version.rb
|
77
|
+
- sig/masked_ape_club.rbs
|
78
|
+
homepage: https://github.com/a6b8/masked-ape-club-for-ruby
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata:
|
82
|
+
allowed_push_host: https://rubygems.org
|
83
|
+
homepage_uri: https://github.com/a6b8/masked-ape-club-for-ruby
|
84
|
+
source_code_uri: https://github.com/a6b8/masked-ape-club-for-ruby
|
85
|
+
changelog_uri: https://raw.githubusercontent.com/a6b8/masked-ape-club-for-ruby/main/CHANGELOG.md
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.6.0
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubygems_version: 3.2.3
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Let the apes out.
|
105
|
+
test_files: []
|