compass-photoshop-gradient-overlay 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ require 'compass'
2
+
3
+ # This tells Compass what your Compass extension is called, and where to find
4
+ # its files
5
+ extension_path = File.expand_path(File.join(File.dirname(__FILE__), ".."))
6
+ Compass::Frameworks.register('compass-photoshop-gradient-overlay', :path => extension_path)
@@ -0,0 +1,142 @@
1
+ // Photoshop-style blend modes
2
+ // --------------------------------------------------
3
+
4
+ // Blending algorithms adapted from:
5
+ // http://jswidget.com/blog/category/image-blending-algorithm/
6
+
7
+ // Explanation of blend modes taken from:;
8
+ // https://dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html
9
+
10
+
11
+ // The source color is multiplied by the destination color and replaces the destination. The resultant color is always at least as dark as either the source or destination color. Multiplying any color with black results in black. Multiplying any color with white preserves the original color.
12
+ @function blend--multiply($background-color, $foreground-color) {
13
+ @return $foreground-color * $background-color / 255;
14
+ }
15
+
16
+
17
+ // Multiplies the complements of the backdrop and source color values, then complements the result. The result color is always at least as light as either of the two constituent colors. Screening any color with white produces white; screening with black leaves the original color unchanged. The effect is similar to projecting multiple photographic slides simultaneously onto a single screen.
18
+ @function blend--screen($background-color, $foreground-color) {
19
+ @return $foreground-color + $background-color - $foreground-color * $background-color / 255;
20
+ }
21
+
22
+
23
+ // Multiplies or screens the colors, depending on the backdrop color value. Source colors overlay the backdrop while preserving its highlights and shadows. The backdrop color is not replaced but is mixed with the source color to reflect the lightness or darkness of the backdrop.
24
+ @function blend--overlay($background-color, $foreground-color) {
25
+ @return if($background-color < 128, 2 * $foreground-color * $background-color / 255, 255 - 2 * (255 - $foreground-color) * (255 - $background-color) / 255);
26
+ }
27
+
28
+
29
+ // Darkens or lightens the colors, depending on the source color value. The effect is similar to shining a diffused spotlight on the backdrop.
30
+ @function blend--soft-light($v1, $v2) {
31
+ @return if($v1 > 127.5, $v2 + (255 - $v2) * (($v1 - 127.5) / 127.5) * (0.5 - abs($v2-127.5)/255), $v2 - $v2 * ((127.5 - $v1) / 127.5) * (0.5 - abs($v2-127.5)/255));
32
+ }
33
+
34
+
35
+ // Multiplies or screens the colors, depending on the source color value. The effect is similar to shining a harsh spotlight on the backdrop.
36
+ @function blend--hard-light($v1, $v2) {
37
+ @return if($v1 > 127.5, $v2 + (255 - $v2) * (($v1 - 127.5) / 127.5), $v2 * $v1 / 127.5);
38
+ }
39
+
40
+ // Linear Color Dodge
41
+ @function blend--linear-color-dodge($v1, $v2) {
42
+ @return min($v1 + $v2, 255);
43
+ }
44
+
45
+
46
+ // Linear Color Burn
47
+ @function blend--linear-color-burn($v1, $v2) {
48
+ @return if($v1 + $v2 < 255, 0, $v1 + $v2 - 255);
49
+ }
50
+
51
+
52
+ // Selects the darker of the backdrop and source colors. The backdrop is replaced with the source where the source is darker; otherwise, it is left unchanged.
53
+ @function blend--darken($v1, $v2) {
54
+ @return min($v1,$v2);
55
+ }
56
+
57
+
58
+ // Selects the lighter of the backdrop and source colors. The backdrop is replaced with the source where the source is lighter; otherwise, it is left unchanged.
59
+ @function blend--lighten($v1, $v2) {
60
+ @return max($v1,$v2);
61
+ }
62
+
63
+
64
+ // Subtracts the darker of the two constituent colors from the lighter color. Painting with white inverts the backdrop color; painting with black produces no change.
65
+ @function blend--difference($v1, $v2) {
66
+ @return abs($v1 - $v2);
67
+ }
68
+
69
+
70
+ // Produces an effect similar to that of the Difference mode but lower in contrast. Painting with white inverts the backdrop color; painting with black produces no change.
71
+ @function blend--exclusion($v1, $v2) {
72
+ @return $v1 + $v2 - $v1 * $v2 / 127.5;
73
+ }
74
+
75
+
76
+ // Reflex
77
+ @function blend--reflex($v1, $v2) {
78
+ @return if($v1 == 255, $v1, min(255, ($v2 * $v2 / (255 - $v1))));
79
+ }
80
+
81
+
82
+ // Linear Light
83
+ @function blend--linear-light($v1, $v2) {
84
+ @return if($v1 < 128, blend--linear-burn($v2, (2 * $v1)), blend--linear-dodge($v2, (2 * ($v1 - 128))));
85
+ }
86
+
87
+
88
+ // Pin Light
89
+ @function blend--pin-light($v1, $v2) {
90
+ @return if($v1 < 128, blend--darken($v2, (2 * $v1)), blend--lighten($v2, (2 * ($v1 - 128))));
91
+ }
92
+
93
+
94
+ // Vivid Light
95
+ @function blend--vivid-light($v1, $v2) {
96
+ @return if($v1 < 128, blend--color-burn($v2, (2 * $v1)), blend--color-dodge($v2, (2 * ($v1 - 128))));
97
+ }
98
+
99
+
100
+ // Hard Mix
101
+ @function blend--hard-mix($v1, $v2) {
102
+ @return if(blend--vivid-light($v1,$v2) < 128, 0, 255);
103
+ }
104
+
105
+
106
+ // Mix two colors together
107
+ @function photoshop-blend($mode, $background-color, $foreground-color, $alpha:1) {
108
+ $red1: red($background-color);
109
+ $green1: green($background-color);
110
+ $blue1: blue($background-color);
111
+ $red2: red($foreground-color);
112
+ $green2: green($foreground-color);
113
+ $blue2: blue($foreground-color);
114
+
115
+ @if(unquote($mode) == multiply) {
116
+ @return rgba(
117
+ blend--multiply($red1, $red2),
118
+ blend--multiply($green1, $green2),
119
+ blend--multiply($blue1, $blue2),
120
+ $alpha
121
+ );
122
+ } @else if(unquote($mode) == screen) {
123
+ @return rgba(
124
+ blend--screen($red1, $red2),
125
+ blend--screen($green1, $green2),
126
+ blend--screen($blue1, $blue2),
127
+ $alpha
128
+ );
129
+ } @else if(unquote($mode) == overlay) {
130
+ @return rgba(
131
+ blend--overlay($red1, $red2),
132
+ blend--overlay($green1, $green2),
133
+ blend--overlay($blue1, $blue2),
134
+ $alpha
135
+ );
136
+ } @else {
137
+ @return rgba(
138
+ $foreground-color,
139
+ $alpha
140
+ );
141
+ }
142
+ }
@@ -0,0 +1,57 @@
1
+ @import "photoshop-blend-modes";
2
+
3
+ // Photoshop Gradient Overlay
4
+ // --------------------------
5
+ @function photoshop-gradient-overlay(
6
+ $bg-color,
7
+ $blend: normal,
8
+ $opacity: 100%,
9
+ $angle: 90deg,
10
+ $scale: 100%,
11
+ $gradient-colors: (#000, #fff),
12
+ $gradient-stops: (0%, 100%)
13
+ ) {
14
+
15
+ $css-angle: convert-angle($angle);
16
+ $color-stops: ();
17
+
18
+ @for $i from 1 through length($gradient-colors) {
19
+ $blended-color: photoshop-blend($blend, $bg-color, nth($gradient-colors, $i), percentage-to-decimal($opacity));
20
+ $stop: join($blended-color, stop-scale(nth($gradient-stops, $i), $scale), space);
21
+ $color-stops: append($color-stops, $stop, comma);
22
+ }
23
+ @return linear-gradient($css-angle, $color-stops);
24
+ }
25
+
26
+ // Adjust the color-stops based on the scale value
27
+ @function stop-scale($stop, $scale) {
28
+ $stop: percentage-to-decimal($stop);
29
+ $new-stop: 0;
30
+ $scale: percentage-to-decimal($scale);
31
+
32
+ @return $scale * $stop - (0.5 * ($scale - 1));
33
+ }
34
+
35
+ // Convert percentage units to decimal units
36
+ @function percentage-to-decimal($percentage) {
37
+ @if unit($percentage) == '%' {
38
+ $percentage: $percentage/100%;
39
+ }
40
+ @return $percentage;
41
+ }
42
+
43
+ // Attempt to convert a Photoshop angle to a CSS keyword.
44
+ // If a valid keyword isn't available, convert to a CSS angle (0deg = north in CSS; east in Photoshop)
45
+ @function convert-angle($angle) {
46
+ @if $angle == 0 {
47
+ @return left;
48
+ } @else if $angle == 90 {
49
+ @return bottom;
50
+ } @else if $angle == 180 {
51
+ @return right;
52
+ } @else if $angle == -90 {
53
+ @return top;
54
+ } @else {
55
+ @return $angle - 90deg;
56
+ }
57
+ }
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compass-photoshop-gradient-overlay
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Tim Hettler
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-05-23 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sass
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: compass
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: A compass extension to translate between Photoshop gradient overlays and CSS linear-gradients
49
+ email:
50
+ - me+github@timhettler.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - lib/compass-photoshop-gradient-overlay.rb
59
+ - stylesheets/_photoshop-blend-modes.scss
60
+ - stylesheets/_photoshop-gradient-overlay.scss
61
+ homepage: https://github.com/timhettler/compass-photoshop-gradient-overlay
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 23
84
+ segments:
85
+ - 1
86
+ - 3
87
+ - 6
88
+ version: 1.3.6
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.25
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: A compass extension to translate between Photoshop gradient overlays and CSS linear-gradients
96
+ test_files: []
97
+