picss 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 919d1d65debf25eac30e5d30cc26fd06a7c28dea
4
+ data.tar.gz: 4f037edfeafcad5db8dfdc8a81568383bd29c218
5
+ SHA512:
6
+ metadata.gz: 3d854459a30ef849370ab730e2e495ff2f790a0f3dfef1c8739bb401886eede0a16be1690cf208667fab1bd172ef9670a78f98da8ce4d2815c9c8668d36162f2
7
+ data.tar.gz: 23dc7bb26f1bc81b60530a0739a214ca99e500b623a1128d553d94370f9f10144683a969a1424939656e95920f78bd69365f15bda0739cfd9d6d7cc4b19b20c3
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/picss"
4
+
5
+ puts Picss::Main.new.convert ARGV[0]
@@ -0,0 +1,12 @@
1
+ require "picss/version"
2
+ require_relative "picss/css_writer"
3
+ require "chunky_png"
4
+
5
+ module Picss
6
+ class Main
7
+ def convert(img, scale=1)
8
+ image = ChunkyPNG::Image.from_file(img)
9
+ CSSWriter.convert(image, scale: scale)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Picss
2
+ class ColorConverter
3
+ def self.hex_to_rgba hex
4
+ parts = hex.scan(/../)
5
+ r = parts[0].to_i(16)
6
+ g = parts[1].to_i(16)
7
+ b = parts[2].to_i(16)
8
+ a = parts[3] || '1'
9
+ a = a.to_i(16) / 255.0 if a != '1'
10
+ return "rgba(#{r},#{g},#{b},#{a})"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,47 @@
1
+ require "mustache"
2
+ require_relative "color_converter"
3
+
4
+ module Picss
5
+ class CSSWriter
6
+ @@template = <<-EOS
7
+ .class {
8
+ position: relative;
9
+ height: {{height}}px;
10
+ width: {{width}}px;
11
+ }
12
+ .class:after {
13
+ content: " ";
14
+ position: absolute;
15
+ background: transparent;
16
+ height: {{scale}}px;
17
+ width: {{scale}}px;
18
+ top: -{{scale}}px;
19
+ left: -{{scale}}px;
20
+ box-shadow:
21
+ {{box_shadows}}
22
+ ;
23
+ }
24
+ EOS
25
+ @@pixel_template = ' {{x}}px {{y}}px 0 0 {{color}}'
26
+
27
+ def self.convert(image, options={})
28
+ box_shadows = Array.new
29
+ image.height.times do |y|
30
+ image.height.times do |x|
31
+ pixel = image.get_pixel(x, y)
32
+ if pixel != 0
33
+ box_shadows.push(Mustache.render @@pixel_template, {
34
+ x: x + options[:scale],
35
+ y: y + options[:scale],
36
+ color: ColorConverter.hex_to_rgba(pixel.to_s(16).rjust(8, '0'))
37
+ })
38
+ end
39
+ end
40
+ end
41
+ options[:box_shadows] = box_shadows.join(",\n")
42
+ options[:height] = image.height
43
+ options[:width] = image.width
44
+ Mustache.render @@template, options
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Picss
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: picss
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Mike Anderson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cucumber
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Why would you want this? Why wouldn't you?!
84
+ email:
85
+ - mike.anderson@space150.com
86
+ executables:
87
+ - picss
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - bin/picss
92
+ - lib/picss/color_converter.rb
93
+ - lib/picss/css_writer.rb
94
+ - lib/picss/version.rb
95
+ - lib/picss.rb
96
+ homepage: http://manderson.space150.com
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: 1.3.6
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.1.9
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Images are better in CSS
119
+ test_files: []