pixel_curtain 0.0.2 → 0.0.3
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.
- data/README.md +20 -0
- data/bin/pixel_curtain +14 -0
- data/lib/pixel_curtain/curtain.rb +30 -0
- data/lib/pixel_curtain/image.rb +23 -0
- data/lib/pixel_curtain/version.rb +1 -1
- metadata +7 -3
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Pixel Curtain is a Gem and Utility to generate beautiful patterns from images:
|
2
|
+
|
3
|
+

|
4
|
+
|
5
|
+
Installation
|
6
|
+
------------
|
7
|
+
|
8
|
+
First install the pixel_curtain gem:
|
9
|
+
|
10
|
+
gem install pixel_curtain
|
11
|
+
|
12
|
+
That's it! You're in business now. You can try out the command line tool by doing
|
13
|
+
|
14
|
+
pixel_curtain input.png
|
15
|
+
|
16
|
+
Then look for the output.png file
|
17
|
+
|
18
|
+
Credits
|
19
|
+
-------
|
20
|
+
Pixel Curtain is written by [Nick Rowe](http://dcxn.com). Fork it and do something cool!
|
data/bin/pixel_curtain
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
dir = File.expand_path(File.dirname(__FILE__))
|
4
|
+
require dir + '/../lib/pixel_curtain'
|
5
|
+
|
6
|
+
input_file = ARGV[0]
|
7
|
+
|
8
|
+
if input_file.nil?
|
9
|
+
puts "input file required"
|
10
|
+
else
|
11
|
+
curtain = PixelCurtain::Curtain.new(input_file)
|
12
|
+
curtain.process(20)
|
13
|
+
curtain.save("output.png")
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PixelCurtain
|
2
|
+
class Curtain
|
3
|
+
def initialize(file_name)
|
4
|
+
@source_image = ChunkyPNG::Image.from_file(file_name)
|
5
|
+
@output = ChunkyPNG::Image.new(1440,900)
|
6
|
+
end
|
7
|
+
|
8
|
+
def process(number_of_divisions=10)
|
9
|
+
|
10
|
+
if (number_of_divisions > @source_image.dimension.width)
|
11
|
+
number_of_divisions = @source_image.dimension.width
|
12
|
+
end
|
13
|
+
|
14
|
+
source_division_size = @source_image.dimension.width / number_of_divisions
|
15
|
+
destination_division_size = @output.dimension.width / number_of_divisions
|
16
|
+
|
17
|
+
(0...number_of_divisions).each do |x|
|
18
|
+
avgPixel = @source_image.crop(source_division_size*x,0,
|
19
|
+
source_division_size,@source_image.dimension.height).average_pixel
|
20
|
+
@output.setPixelBlock(x*destination_division_size,0,@output.dimension.height,destination_division_size,avgPixel)
|
21
|
+
end
|
22
|
+
@output
|
23
|
+
end
|
24
|
+
|
25
|
+
def save(file_name)
|
26
|
+
@output.save(file_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class ChunkyPNG::Image
|
2
|
+
def average_pixel
|
3
|
+
# Sum the total R, G, and B pieces
|
4
|
+
ave = self.pixels.inject([0,0,0]) do |sum,element|
|
5
|
+
sum[0] += ChunkyPNG::Color.r(element)
|
6
|
+
sum[1] += ChunkyPNG::Color.g(element)
|
7
|
+
sum[2] += ChunkyPNG::Color.b(element)
|
8
|
+
sum
|
9
|
+
end
|
10
|
+
# Cache the pixel_count value for speed
|
11
|
+
pixel_count = self.pixels.count
|
12
|
+
# Return the average value of each component as a new Color
|
13
|
+
ChunkyPNG::Color.rgb(ave[0] / pixel_count, ave[1] / pixel_count, ave[2] / pixel_count)
|
14
|
+
end
|
15
|
+
|
16
|
+
def setPixelBlock(startX, startY, height, width, newPixel)
|
17
|
+
(startX...startX+width).each do |x|
|
18
|
+
(startY...startY+height).each do |y|
|
19
|
+
self[x,y] = newPixel
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pixel_curtain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nick Rowe
|
@@ -17,8 +17,8 @@ dependencies: []
|
|
17
17
|
description: Generate beautiful backgrounds from images
|
18
18
|
email:
|
19
19
|
- nixterrimus@dcxn.com
|
20
|
-
executables:
|
21
|
-
|
20
|
+
executables:
|
21
|
+
- pixel_curtain
|
22
22
|
extensions: []
|
23
23
|
|
24
24
|
extra_rdoc_files: []
|
@@ -26,8 +26,12 @@ extra_rdoc_files: []
|
|
26
26
|
files:
|
27
27
|
- .gitignore
|
28
28
|
- Gemfile
|
29
|
+
- README.md
|
29
30
|
- Rakefile
|
31
|
+
- bin/pixel_curtain
|
30
32
|
- lib/pixel_curtain.rb
|
33
|
+
- lib/pixel_curtain/curtain.rb
|
34
|
+
- lib/pixel_curtain/image.rb
|
31
35
|
- lib/pixel_curtain/version.rb
|
32
36
|
- pixel_curtain.gemspec
|
33
37
|
has_rdoc: true
|