instamatic 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1abbaf57a3fba26920ecf16de4223f84229089d
4
+ data.tar.gz: ad297b260338099060510d872c492661cfbd09f6
5
+ SHA512:
6
+ metadata.gz: 09cc8ea0ec15dbd297f8afebef4b4dd1328eb421a7712ae8bf811b199634f097919606b4af421ab9209d30eb76a58f6e9594dbb9854ac086bbf610612ee7153a
7
+ data.tar.gz: 1788bfeccca55dd828cfdffeeba5c0d5cc3377d786c588c62d02882402584e43e21a1fd078f9971971b6415e40625777287965b8103e6375ae3b96d737811a30
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ .idea
12
+ .ruby-gemset
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in instamatic.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Andrew Neely
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Instamatic
2
+
3
+ Instamatic is a gem that lets you run a generator to create an image placement service in minutes.
4
+
5
+ Once your project is set up, just drop images (PNG files with transparency) into the `images/` folder and launch like any Sinatra app.
6
+
7
+ Add a config.ru file, and you're ready to push to heroku.
8
+
9
+ Requests to the root of your site land on an instruction page with a detailed explanation of how the URL scheme of the service works.
10
+
11
+ Other URLs are parsed by the route matcher against the following two schemes. Note: all params but the first are optional in reverse order from the end.
12
+
13
+ TL;DR:
14
+
15
+ `/some_image_name/width/height/hex_color_w_no_leading_hash/scale/`
16
+
17
+ e.g. http://www.rappersonthe.rocks/l_l_cool_j/800/600/ffc0cb/
18
+
19
+ or
20
+
21
+ `/width/height/hex_color_w_no_leading_hash/scale/`
22
+
23
+ e.g. http://www.rappersonthe.rocks/640/480/000000/200/
24
+
25
+ A working example of the homepage and service is available at http://www.rappersonthe.rocks
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'instamatic'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install instamatic
42
+
43
+ ## Usage
44
+
45
+ Getting started is easy!
46
+
47
+ 1. After installing the gem, run `setup_instamatic` to get a prompt to generate the `images/` folder and a `templates/` folder with erb templates for the homepage to copy-edit.
48
+ 2. Drop your images into `images/` and run the server with `rackup`, `shotgun`, or `ruby`.
49
+ 3. That's it!
50
+
51
+ <!--## Contributing-->
52
+
53
+ <!--Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/instamatic.-->
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'instamatic'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config.ru ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup
4
+ require 'instamatic'
5
+ run Instamatic::App
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'setup_instamatic_util'
4
+
5
+ Instamatic::SetupInstamaticUtil.copy_to_project!
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'instamatic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'instamatic'
8
+ spec.version = Instamatic::VERSION
9
+ spec.authors = ['Andrew Neely']
10
+ spec.email = ['aneely@gmail.com']
11
+
12
+ spec.summary = %q{It's an image placement service in a box!}
13
+ spec.description = %q{It's an image placement service in a box! Step 1: Install and run a generator. Step 2) Drop your images into the images directory. Step 3) Profit!}
14
+ spec.homepage = 'https://bitbucket.org/aneely/instamatic'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = ['setup_instamatic'] #spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib', 'utils']
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.11'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_dependency 'sinatra', '1.4.5'
33
+ spec.add_dependency 'mini_magick'
34
+ end
@@ -0,0 +1,182 @@
1
+ require 'sinatra'
2
+ require 'mini_magick'
3
+
4
+ module Instamatic
5
+ class App < Sinatra::Base
6
+ set :views, %w(templates)
7
+
8
+ helpers do
9
+ def find_template(views, name, engine, &block)
10
+ Array(views).each { |v| super(v, name, engine, &block) }
11
+ end
12
+
13
+ def valid_hex_color?(color)
14
+ match = color.match(/^#([0-9a-fA-F]{6}){1,2}$/)
15
+
16
+ match.to_s.length > 0
17
+ end
18
+
19
+ def assign_image(file_name)
20
+ image_file = "images/#{file_name}.png"
21
+
22
+ if File.file?(image_file)
23
+ MiniMagick::Image.open(image_file)
24
+ else
25
+ MiniMagick::Image.open("images/#{random_image_name}.png")
26
+ end
27
+ end
28
+
29
+ def assign_width(width)
30
+ assign_dimension(width,1024)
31
+ end
32
+
33
+ def assign_height(height)
34
+ assign_dimension(height,768)
35
+ end
36
+
37
+ def assign_dimension(dimension, default)
38
+ sanitized = dimension.to_i
39
+
40
+ if sanitized > 0
41
+ [[2560, sanitized].min, 16].max
42
+ else
43
+ default
44
+ end
45
+ end
46
+
47
+ def assign_color(color)
48
+ if valid_hex_color?("##{color}")
49
+ "##{color}"
50
+ else
51
+ '#ffffff'
52
+ end
53
+ end
54
+
55
+ def assign_percent(percent)
56
+ sanitized = percent.to_i
57
+
58
+ if sanitized > 0
59
+ [[300, sanitized].min, 10].max
60
+ else
61
+ 100
62
+ end
63
+ end
64
+
65
+ def dimension_for_percent(dimension, percent)
66
+ if percent == 100
67
+ dimension
68
+ else
69
+ (dimension * (percent / 100.0)).to_i
70
+ end
71
+ end
72
+
73
+ def format_image(image, width, height, color, percent)
74
+ width = dimension_for_percent(width, percent)
75
+ height = dimension_for_percent(height, percent)
76
+
77
+ image.combine_options do |img|
78
+ img.thumbnail("#{width}x#{height}>")
79
+ img.background(color)
80
+ img.gravity('South')
81
+ img.extent("#{width}x#{height}")
82
+ end
83
+
84
+ image.format('jpg')
85
+ image.quality(90)
86
+ end
87
+
88
+ def image_file_names
89
+ file_paths = Dir['images/*']
90
+ file_paths.each { |file_path| file_path.gsub!('images/', '').gsub!('.png', '') }
91
+ end
92
+
93
+ def random_image_name
94
+ image_file_names.sample
95
+ end
96
+
97
+ def options_for_image_select
98
+ select_hash = {}
99
+
100
+ image_file_names.each do |file|
101
+ select_hash[file] = file.split('_').map { |name| name.capitalize }.join(' ')
102
+ end
103
+
104
+ select_hash
105
+ end
106
+
107
+ def response_image(image_name, width, height, color, percent)
108
+ image_name = params[:image] if image_name.nil?
109
+
110
+ image = assign_image("#{image_name}")
111
+ width = assign_width("#{width}")
112
+ height = assign_height("#{height}")
113
+ color = assign_color("#{color}")
114
+ percent = assign_percent("#{percent}")
115
+
116
+ format_image(image, width, height, color, percent)
117
+ content_type 'image/jpg'
118
+ image.to_blob
119
+ end
120
+ end
121
+
122
+ # defined route methods
123
+
124
+ get '/' do
125
+ @image_select_hash = options_for_image_select
126
+ @example_image = {
127
+ file: @image_select_hash.keys.last,
128
+ name: @image_select_hash.values.last
129
+ }
130
+
131
+ erb :index
132
+ end
133
+
134
+ post '/images' do
135
+ image = params[:image_input]
136
+ width = params[:width_input]
137
+ height = params[:height_input]
138
+ color = params[:color_input]
139
+ percent = params[:percent_input]
140
+
141
+ unless color.nil?
142
+ color.gsub!('#','').downcase!
143
+ end
144
+
145
+ redirect("/#{image}/#{width}/#{height}/#{color}/#{percent}/")
146
+ end
147
+
148
+ get /^\/(\d+)\/(\d+)\/([a-fA-F0-9]{6}){1,2}\b\/(\d+)\/*/ do |width, height, hex_color, percent|
149
+
150
+ response_image(nil, width, height,hex_color, percent)
151
+
152
+ end
153
+
154
+ get /^\/(\d+)\/(\d+)\/([a-fA-F0-9]{6}){1,2}\b\/*/ do |width, height, hex_color|
155
+
156
+ response_image(nil, width, height, hex_color, nil)
157
+
158
+ end
159
+
160
+ get /^\/(\d+)\/(\d+)\/*/ do |width, height|
161
+
162
+ response_image(nil, width, height, nil, nil)
163
+
164
+ end
165
+
166
+ get '/?:image?/?:width?/?:height?/?:color?/?:percent?/?' do
167
+
168
+ response_image(params[:images], params[:width], params[:height], params[:color], params[:percent])
169
+
170
+ end
171
+
172
+ # route methods for undefined API requests
173
+
174
+ not_found do
175
+ error 400
176
+ end
177
+
178
+ error 401 do
179
+ "{'error':'unauthorized', 'message':'You are not authorized to access this resource.'}"
180
+ end
181
+ end
182
+ end
Binary file
@@ -0,0 +1 @@
1
+ $('.color').colorPicker();
@@ -0,0 +1,4 @@
1
+ /*! tinyColorPicker - v1.0.0 2015-12-15 */
2
+
3
+ window.Colors=function(a,b){"use strict";function c(a,c,d,f,g){if("string"==typeof c){var c=t.txt2color(c);d=c.type,n[d]=c[d],g=g!==b?g:c.alpha}else if(c)for(var h in c)a[d][h]=k(c[h]/l[d][h][1],0,1);return g!==b&&(a.alpha=k(+g,0,1)),e(d,f?a:b)}function d(a,b,c){var d=m.options.grey,e={};return e.RGB={r:a.r,g:a.g,b:a.b},e.rgb={r:b.r,g:b.g,b:b.b},e.alpha=c,e.equivalentGrey=Math.round(d.r*a.r+d.g*a.g+d.b*a.b),e.rgbaMixBlack=i(b,{r:0,g:0,b:0},c,1),e.rgbaMixWhite=i(b,{r:1,g:1,b:1},c,1),e.rgbaMixBlack.luminance=h(e.rgbaMixBlack,!0),e.rgbaMixWhite.luminance=h(e.rgbaMixWhite,!0),m.options.customBG&&(e.rgbaMixCustom=i(b,m.options.customBG,c,1),e.rgbaMixCustom.luminance=h(e.rgbaMixCustom,!0),m.options.customBG.luminance=h(m.options.customBG,!0)),e}function e(a,b){var c,e,k,o=b||n,p=t,q=m.options,r=l,s=o.RND,u="",v="",w={hsl:"hsv",rgb:a},x=s.rgb;if("alpha"!==a){for(var y in r)if(!r[y][y]){a!==y&&(v=w[y]||"rgb",o[y]=p[v+"2"+y](o[v])),s[y]||(s[y]={}),c=o[y];for(u in c)s[y][u]=Math.round(c[u]*r[y][u][1])}x=s.rgb,o.HEX=p.RGB2HEX(x),o.equivalentGrey=q.grey.r*o.rgb.r+q.grey.g*o.rgb.g+q.grey.b*o.rgb.b,o.webSave=e=f(x,51),o.webSmart=k=f(x,17),o.saveColor=x.r===e.r&&x.g===e.g&&x.b===e.b?"web save":x.r===k.r&&x.g===k.g&&x.b===k.b?"web smart":"",o.hueRGB=t.hue2RGB(o.hsv.h),b&&(o.background=d(x,o.rgb,o.alpha))}var z,A,B,C=o.rgb,D=o.alpha,E="luminance",F=o.background;return z=i(C,{r:0,g:0,b:0},D,1),z[E]=h(z,!0),o.rgbaMixBlack=z,A=i(C,{r:1,g:1,b:1},D,1),A[E]=h(A,!0),o.rgbaMixWhite=A,q.customBG&&(B=i(C,F.rgbaMixCustom,D,1),B[E]=h(B,!0),B.WCAG2Ratio=j(B[E],F.rgbaMixCustom[E]),o.rgbaMixBGMixCustom=B,B.luminanceDelta=Math.abs(B[E]-F.rgbaMixCustom[E]),B.hueDelta=g(F.rgbaMixCustom,B,!0)),o.RGBLuminance=h(x),o.HUELuminance=h(o.hueRGB),q.convertCallback&&q.convertCallback(o,a),o}function f(a,b){var c={},d=0,e=b/2;for(var f in a)d=a[f]%b,c[f]=a[f]+(d>e?b-d:-d);return c}function g(a,b,c){return(Math.max(a.r-b.r,b.r-a.r)+Math.max(a.g-b.g,b.g-a.g)+Math.max(a.b-b.b,b.b-a.b))*(c?255:1)/765}function h(a,b){for(var c=b?1:255,d=[a.r/c,a.g/c,a.b/c],e=m.options.luminance,f=d.length;f--;)d[f]=d[f]<=.03928?d[f]/12.92:Math.pow((d[f]+.055)/1.055,2.4);return e.r*d[0]+e.g*d[1]+e.b*d[2]}function i(a,c,d,e){var f={},g=d!==b?d:1,h=e!==b?e:1,i=g+h*(1-g);for(var j in a)f[j]=(a[j]*g+c[j]*h*(1-g))/i;return f.a=i,f}function j(a,b){var c=1;return c=a>=b?(a+.05)/(b+.05):(b+.05)/(a+.05),Math.round(100*c)/100}function k(a,b,c){return a>c?c:b>a?b:a}var l={rgb:{r:[0,255],g:[0,255],b:[0,255]},hsv:{h:[0,360],s:[0,100],v:[0,100]},hsl:{h:[0,360],s:[0,100],l:[0,100]},alpha:{alpha:[0,1]},HEX:{HEX:[0,16777215]}},m={},n={},o={r:.298954,g:.586434,b:.114612},p={r:.2126,g:.7152,b:.0722},q=function(a){this.colors={RND:{}},this.options={color:"rgba(204, 82, 37, 0.8)",grey:o,luminance:p,valueRanges:l},r(this,a||{})},r=function(a,d){var e,f=a.options;s(a);for(var g in d)d[g]!==b&&(f[g]=d[g]);e=f.customBG,f.customBG="string"==typeof e?t.txt2color(e).rgb:e,n=c(a.colors,f.color,b,!0)},s=function(a){m!==a&&(m=a,n=a.colors)};q.prototype.setColor=function(a,d,f){return s(this),a?c(this.colors,a,d,b,f):(f!==b&&(this.colors.alpha=k(f,0,1)),e(d))},q.prototype.setCustomBackground=function(a){return s(this),this.options.customBG="string"==typeof a?t.txt2color(a).rgb:a,c(this.colors,b,"rgb")},q.prototype.saveAsBackground=function(){return s(this),c(this.colors,b,"rgb",!0)};var t={txt2color:function(a){var b={},c=a.replace(/(?:#|\)|%)/g,"").split("("),d=(c[1]||"").split(/,\s*/),e=c[1]?c[0].substr(0,3):"rgb",f="";if(b.type=e,b[e]={},c[1])for(var g=3;g--;)f=e[g]||e.charAt(g),b[e][f]=+d[g]/l[e][f][1];else b.rgb=t.HEX2rgb(c[0]);return b.alpha=d[3]?+d[3]:1,b},RGB2HEX:function(a){return((a.r<16?"0":"")+a.r.toString(16)+(a.g<16?"0":"")+a.g.toString(16)+(a.b<16?"0":"")+a.b.toString(16)).toUpperCase()},HEX2rgb:function(a){return a=a.split(""),{r:parseInt(a[0]+a[a[3]?1:0],16)/255,g:parseInt(a[a[3]?2:1]+(a[3]||a[1]),16)/255,b:parseInt((a[4]||a[2])+(a[5]||a[2]),16)/255}},hue2RGB:function(a){var b=6*a,c=~~b%6,d=6===b?0:b-c;return{r:Math.round(255*[1,1-d,0,0,d,1][c]),g:Math.round(255*[d,1,1,1-d,0,0][c]),b:Math.round(255*[0,0,d,1,1,1-d][c])}},rgb2hsv:function(a){var b,c,d,e=a.r,f=a.g,g=a.b,h=0;return g>f&&(f=g+(g=f,0),h=-1),c=g,f>e&&(e=f+(f=e,0),h=-2/6-h,c=Math.min(f,g)),b=e-c,d=e?b/e:0,{h:1e-15>d?n&&n.hsl&&n.hsl.h||0:b?Math.abs(h+(f-g)/(6*b)):0,s:e?b/e:n&&n.hsv&&n.hsv.s||0,v:e}},hsv2rgb:function(a){var b=6*a.h,c=a.s,d=a.v,e=~~b,f=b-e,g=d*(1-c),h=d*(1-f*c),i=d*(1-(1-f)*c),j=e%6;return{r:[d,h,g,g,i,d][j],g:[i,d,d,h,g,g][j],b:[g,g,i,d,d,h][j]}},hsv2hsl:function(a){var b=(2-a.s)*a.v,c=a.s*a.v;return c=a.s?1>b?b?c/b:0:c/(2-b):0,{h:a.h,s:a.v||c?c:n&&n.hsl&&n.hsl.s||0,l:b/2}},rgb2hsl:function(a,b){var c=t.rgb2hsv(a);return t.hsv2hsl(b?c:n.hsv=c)},hsl2rgb:function(a){var b=6*a.h,c=a.s,d=a.l,e=.5>d?d*(1+c):d+c-c*d,f=d+d-e,g=e?(e-f)/e:0,h=~~b,i=b-h,j=e*g*i,k=f+j,l=e-j,m=h%6;return{r:[e,l,f,f,k,e][m],g:[k,e,e,l,f,f][m],b:[f,f,k,e,e,l][m]}}};return q}(window),function(a,b,c,d){"use strict";function e(a){return a.value||a.getAttribute("value")||b(a).css("background-color")||"#fff"}function f(a){return a=a.originalEvent&&a.originalEvent.touches?a.originalEvent.touches[0]:a,a.originalEvent?a.originalEvent:a}function g(a){return b(a.find(s.doRender)[0]||a[0])}function h(c){var d=b(this),f=d.offset(),h=b(a),j=s.gap;c?(t=g(d),t._colorMode=t.data("colorMode"),q.$trigger=d,(u||i()).css({left:(u[0]._left=f.left)-((u[0]._left=u[0]._left+u[0]._width-(h.scrollLeft()+h.width()))+j>0?u[0]._left+j:0),top:(u[0]._top=f.top+d.outerHeight())-((u[0]._top=u[0]._top+u[0]._height-(h.scrollTop()+h.height()))+j>0?u[0]._top+j:0)}).show(s.animationSpeed,function(){c!==!0&&(y._width=y.width(),v._width=v.width(),v._height=v.height(),r.setColor(e(t[0])),n(!0))})):b(u).hide(s.animationSpeed,function(){t.blur(),n(!1),q.$trigger=null})}function i(){return b("head").append('<style type="text/css">'+(s.css||J)+(s.cssAddon||"")+"</style>"),q.$UI=u=b(I).css({margin:s.margin}).appendTo("body").show(0,function(){var a=b(this);F=s.GPU&&a.css("perspective")!==d,v=b(".cp-xy-slider",this),w=b(".cp-xy-cursor",this),x=b(".cp-z-cursor",this),y=b(".cp-alpha",this).toggle(!!s.opacity),z=b(".cp-alpha-cursor",this),s.buildCallback.call(q,a),a.prepend("<div>").children().eq(0).css("width",a.children().eq(0).width()),this._width=this.offsetWidth,this._height=this.offsetHeight}).hide().on(D,".cp-xy-slider,.cp-z-slider,.cp-alpha",j)}function j(a){var c=this.className.replace(/cp-(.*?)(?:\s*|$)/,"$1").replace("-","_");a.preventDefault&&a.preventDefault(),a.returnValue=!1,t._offset=b(this).offset(),(c="xy_slider"===c?k:"z_slider"===c?l:m)(a),n(),A.on(E,function(){A.off(".a")}).on(C,function(a){c(a),n()})}function k(a){var b=f(a),c=b.pageX-t._offset.left,d=b.pageY-t._offset.top;r.setColor({s:c/v._width*100,v:100-d/v._height*100},"hsv")}function l(a){var b=f(a).pageY-t._offset.top;r.setColor({h:360-b/v._height*360},"hsv")}function m(a){var b=f(a).pageX-t._offset.left,c=b/y._width;r.setColor({},"rgb",c)}function n(a){var b=r.colors,c=b.hueRGB,e=b.RND.rgb,f=b.RND.hsl,g="#222",h="#ddd",i=t._colorMode,j=1!==b.alpha,k=G(100*b.alpha)/100,l=e.r+", "+e.g+", "+e.b,m="HEX"!==i||j?"rgb"===i||"HEX"===i&&j?j?"rgba("+l+", "+k+")":"rgb("+l+")":"hsl"+(j?"a(":"(")+f.h+", "+f.s+"%, "+f.l+"%"+(j?", "+k:"")+")":"#"+b.HEX,n=b.HUELuminance>.22?g:h,p=b.rgbaMixBlack.luminance>.22?g:h,q=(1-b.hsv.h)*v._height,s=b.hsv.s*v._width,u=(1-b.hsv.v)*v._height,A=k*y._width,B=F?"translate3d":"",C=t[0].value,D=t[0].hasAttribute("value")&&""===C&&a!==d;v._css={backgroundColor:"rgb("+c.r+","+c.g+","+c.b+")"},w._css={transform:B+"("+s+"px, "+u+"px, 0)",left:F?"":s,top:F?"":u,borderColor:b.RGBLuminance>.22?g:h},x._css={transform:B+"(0, "+q+"px, 0)",top:F?"":q,borderColor:"transparent "+n},y._css={backgroundColor:"rgb("+l+")"},z._css={transform:B+"("+A+"px, 0, 0)",left:F?"":A,borderColor:p+" transparent"},t._css={backgroundColor:D?"":m,color:D?"":b.rgbaMixBGMixCustom.luminance>.22?g:h},t.text=D?"":C!==m?m:"",a!==d?o(a):H(o)}function o(a){v.css(v._css),w.css(w._css),x.css(x._css),y.css(y._css),z.css(z._css),s.doRender&&t.css(t._css),t.text&&t.val(t.text),s.renderCallback.call(q,t,"boolean"==typeof a?a:d)}var p,q,r,s,t,u,v,w,x,y,z,A=b(document),B="",C="touchmove.a mousemove.a pointermove.a",D="touchstart.a mousedown.a pointerdown.a",E="touchend.a mouseup.a pointerup.a",F=!1,G=Math.round,H=a.requestAnimationFrame||a.webkitRequestAnimationFrame||function(a){a()},I='<div class="cp-color-picker"><div class="cp-z-slider"><div class="cp-z-cursor"></div></div><div class="cp-xy-slider"><div class="cp-white"></div><div class="cp-xy-cursor"></div></div><div class="cp-alpha"><div class="cp-alpha-cursor"></div></div></div>',J=".cp-color-picker{position:absolute;overflow:hidden;padding:6px 6px 0;background-color:#444;color:#bbb;font-family:Arial,Helvetica,sans-serif;font-size:12px;font-weight:400;cursor:default;border-radius:5px}.cp-color-picker>div{position:relative;overflow:hidden}.cp-xy-slider{float:left;height:128px;width:128px;margin-bottom:6px;background:linear-gradient(to right,#FFF,rgba(255,255,255,0))}.cp-white{height:100%;width:100%;background:linear-gradient(rgba(0,0,0,0),#000)}.cp-xy-cursor{position:absolute;top:0;width:10px;height:10px;margin:-5px;border:1px solid #fff;border-radius:100%;box-sizing:border-box}.cp-z-slider{float:right;margin-left:6px;height:128px;width:20px;background:linear-gradient(red 0,#f0f 17%,#00f 33%,#0ff 50%,#0f0 67%,#ff0 83%,red 100%)}.cp-z-cursor{position:absolute;margin-top:-4px;width:100%;border:4px solid #fff;border-color:transparent #fff;box-sizing:border-box}.cp-alpha{clear:both;width:100%;height:16px;margin:6px 0;background:linear-gradient(to right,#444,rgba(0,0,0,0))}.cp-alpha-cursor{position:absolute;margin-left:-4px;height:100%;border:4px solid #fff;border-color:#fff transparent;box-sizing:border-box}",K=function(a){r=this.color=new c(a),s=r.options};return K.prototype={render:n,toggle:h},b.fn.colorPicker=function(c){var d=function(){};return c=b.extend({animationSpeed:150,GPU:!0,doRender:!0,customBG:"#FFF",opacity:!0,renderCallback:d,buildCallback:d,body:document.body,scrollResize:!0,gap:4},c),!q&&c.scrollResize&&b(a).on("resize.a scroll.a",function(){q.$trigger&&q.toggle.call(q.$trigger[0],!0)}),p=p?p.add(this):this,p.colorPicker=q||(q=new K(c)),B+=(B?", ":"")+this.selector,b(c.body).off(".a").on(D,function(a){var c=b(a.target);-1!==b.inArray(c.closest(B)[0],p)||c.closest(u).length||p.colorPicker.$trigger&&h()}).on("focusin.a click.a",B,h).on("change.a",B,function(){r.setColor(this.value||"#FFF"),p.colorPicker.render(!0)}),this.each(function(){var a=e(this),d=a.split("("),f=g(b(this));f.data("colorMode",d[1]?d[0].substr(0,3):"HEX").attr("readonly",s.preventFocus),c.doRender&&f.css({"background-color":a,color:function(){return r.setColor(a).rgbaMixBGMixCustom.luminance>.22?"#222":"#ddd"}})})},b.fn.colorPicker.destroy=function(){b(q.color.options.body).off(".a"),q.toggle(!1),p=null,B=""},b}(window,jQuery,Colors);
4
+ //# sourceMappingURL=jqColorPicker.js.map
@@ -0,0 +1,3 @@
1
+ body {
2
+ padding-top: 50px;
3
+ }
@@ -0,0 +1,3 @@
1
+ module Instamatic
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,136 @@
1
+ <div class="col-md-6">
2
+ <h3>Use the Image Form</h3>
3
+
4
+ <div class="panel panel-default">
5
+ <div class="panel-body">
6
+ <h4>Click Your Way to Success</h4>
7
+
8
+ <p>You can also use this convenient form to set the options and return a picture:</p>
9
+ <form action="/images" method="post">
10
+ <div class="form-group">
11
+ <label for="imageInput">Image</label>
12
+ <select class="form-control" id="imageInput" name="image_input">
13
+ <% if @image_select_hash %>
14
+ <% @image_select_hash.each do |file, name| %>
15
+ <option value="<%= file %>"><%= name %></option>
16
+ <% end %>
17
+ <% end %>
18
+ </select>
19
+ </div>
20
+ <div class="form-group">
21
+ <label for="widthInput">Width in Pixels</label>
22
+ <input type="number" class="form-control" id="widthInput" name="width_input" value="1024" min="16" max="2560">
23
+ </div>
24
+ <div class="form-group">
25
+ <label for="heightInput">Height in Pixels</label>
26
+ <input type="number" class="form-control" id="heightInput" name="height_input" value="768" min="16" max="2560">
27
+ </div>
28
+ <div class="form-group">
29
+ <label for="colorInput">Background Color</label>
30
+ <input type="text" class="form-control color no-alpha" id="colorInput" name="color_input" value="#FFFFFF">
31
+ </div>
32
+ <div class="form-group">
33
+ <label for="percentInput">Scale in Percent</label>
34
+ <input type="number" class="form-control" id="percentInput" name="percent_input" value="100" min="25" max="300" step="25">
35
+ </div>
36
+ <button type="submit" class="btn btn-default">Submit</button>
37
+ </form>
38
+ </div>
39
+ </div>
40
+ </div>
41
+
42
+ <div class="col-md-6">
43
+ <h3>Use the URL API</h3>
44
+
45
+ <div class="panel panel-default">
46
+ <div class="panel-body">
47
+
48
+ <h4>URL Quick Start</h4>
49
+
50
+ <p>There are two patterns you can use to build out an image from the URL, one with a named image and one without.</p>
51
+
52
+ <p>An example of a valid image URL with a named image would be:</p>
53
+ <div class="well well-sm"><a href="/<%= @example_image[:file]%>/800/600/ffc0cb/" title="example link">/<%= @example_image[:file]%>/800/600/ffc0cb/</a></div>
54
+ <p>This link returns an 800x600 pixel image of <%= @example_image[:name]%> with a solid pink background color. You can find a list of valid parameters <a href="#parameter-values" title="values link">below</a>.</p>
55
+
56
+ <p>Another example of a valid URL without one would be:</p>
57
+ <div class="well well-sm"><a href="/640/480" title="example link">/640/480</a></div>
58
+ <p>This link returns a randomly chosen 640x480 pixel with a white background color.</p>
59
+
60
+ <hr>
61
+
62
+ <p>Yet another valid URL would be:</p>
63
+ <div class="well well-sm"><a href="/640/480/000000/200/" title="example link">/640/480/000000/200/</a></div>
64
+ <p>This link returns a randomly chosen 1280x960 pixel with a black background color. This could be sized to 50% to create a retina-friendly image</p>
65
+
66
+ <hr>
67
+
68
+ <h4>URL Parameters</h4>
69
+
70
+ <p>The URL parameters are parsed in order to customize your image as follows:</p>
71
+ <div class="well well-sm"><strong>/:image/:width/:height/:color/:scale/</strong></div>
72
+ <p>or</p>
73
+ <div class="well well-sm"><strong>/:width/:height/:color/:scale/</strong></div>
74
+
75
+ <hr>
76
+
77
+ <h4 id="parameter-values">Valid Parameter Values</h4>
78
+
79
+ <p>Valid values for the URL parameters are listed below</p>
80
+ <dl class="padded-dl">
81
+ <dt>Image</dt>
82
+ <dd>
83
+ <ul>
84
+ <% if @image_select_hash %>
85
+ <% @image_select_hash.each do |file, name| %>
86
+ <li><code><%= file %></code></li>
87
+ <% end %>
88
+ <% end %>
89
+ </ul>
90
+ </dd>
91
+ <dt>Width & Height</dt>
92
+ <dd>
93
+ Any positive integer between <code>16</code> and <code>2560</code>
94
+ </dd>
95
+ <dt>Color</dt>
96
+ <dd>
97
+ Any valid hex web color without the pound sign in front of it
98
+ </dd>
99
+ <dt>Scale</dt>
100
+ <dd>
101
+ Any positive integer from <code>25</code> to <code>300</code>; the default is <code>100</code>
102
+ </dd>
103
+ </dl>
104
+
105
+ <hr>
106
+
107
+ <h4>Optional Values</h4>
108
+
109
+ <ul>
110
+ <li>parameters are parsed in order from first to last</li>
111
+ <li>all parameters but the first can be omitted in reverse order</li>
112
+ <li>omitted parameters will assume their default values</li>
113
+ <li>the trailing slash at the end of the URL is optional</li>
114
+ </ul>
115
+
116
+ <hr>
117
+
118
+ <h4>Default Values</h4>
119
+
120
+ <dl class="dl-horizontal">
121
+ <dt>Image</dt>
122
+ <dd>a randomly chosen image</dd>
123
+ <dt>Width</dt>
124
+ <dd><code>1024</code></dd>
125
+ <dt>Height</dt>
126
+ <dd><code>768</code></dd>
127
+ <dt>Color</dt>
128
+ <dd><code>ffffff</code></dd>
129
+ <dt>Scale</dt>
130
+ <dd><code>100</code></dd>
131
+ </dl>
132
+ </div>
133
+ </div>
134
+
135
+ </div>
136
+ </div>
@@ -0,0 +1,53 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <title>Instamatic</title>
8
+ <!-- Latest compiled and minified CSS -->
9
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
10
+ <!-- Optional theme -->
11
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
12
+ <link rel="stylesheet" href="styles/app.css">
13
+ <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
14
+ <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
15
+ <!--[if lt IE 9]>
16
+ <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
17
+ <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
18
+ <![endif]-->
19
+ </head>
20
+ <body>
21
+ <nav class="navbar navbar-inverse navbar-fixed-top">
22
+ <div class="container">
23
+ <div class="navbar-header">
24
+ <!--<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">-->
25
+ <!--<span class="sr-only">Toggle navigation</span>-->
26
+ <!--<span class="icon-bar"></span>-->
27
+ <!--<span class="icon-bar"></span>-->
28
+ <!--<span class="icon-bar"></span>-->
29
+ <!--</button>-->
30
+ <a class="navbar-brand" href="#">Instamatic - Just Add Pictures</a>
31
+ </div>
32
+ <!--<div id="navbar" class="collapse navbar-collapse">-->
33
+ <!--<ul class="nav navbar-nav">-->
34
+ <!--<li class="active"><a href="#">Home</a></li>-->
35
+ <!--<li><a href="#about">About</a></li>-->
36
+ <!--<li><a href="#contact">Contact</a></li>-->
37
+ <!--</ul>-->
38
+ <!--</div>-->
39
+ <!--/.nav-collapse -->
40
+ </div>
41
+ </nav>
42
+ <div class="container">
43
+ <%= yield %>
44
+ </div>
45
+
46
+ <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
47
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" crossorigin="anonymous"></script>
48
+ <!-- Latest compiled and minified JavaScript -->
49
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
50
+ <script src="scripts/jqColorPicker.min.js"></script>
51
+ <script src="scripts/app.js"></script>
52
+ </body>
53
+ </html>
data/lib/instamatic.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'instamatic/version'
2
+
3
+ module Instamatic
4
+ autoload :App, 'instamatic/app'
5
+ end
@@ -0,0 +1,44 @@
1
+ require 'fileutils'
2
+
3
+ module Instamatic
4
+ class SetupInstamaticUtil
5
+ def self.copy_to_project!
6
+ puts "Generate MVP Photo Placement Site?\nType ['Y/y'] to proceed\nType anything else to cancel"
7
+ proceed = gets.chomp
8
+
9
+ if proceed.downcase == 'y'
10
+ copy_template_and_image_files
11
+ puts "\nAll done!"
12
+ puts "Add png files with transparency in the images folder and run the server to get started\n\n"
13
+ end
14
+ end
15
+
16
+ def self.copy_template_and_image_files
17
+ project_pwd = FileUtils.pwd
18
+ lib_path = File.expand_path('../../lib', __FILE__)
19
+
20
+ # TODO use this for a full generate-everything setup
21
+ # FileUtils.copy_entry(lib_path, project_pwd) # this copies everything in lib
22
+
23
+ templates_source = "#{lib_path}/instamatic/views/"
24
+ templates_dest = "#{project_pwd}/templates"
25
+
26
+ #puts "#{Dir.glob("#{templates_source}/*")}"
27
+
28
+ FileUtils.cp_r(templates_source, templates_dest)
29
+
30
+ images_source = "#{lib_path}/instamatic/images/"
31
+ images_dest = "#{project_pwd}/images"
32
+
33
+ FileUtils.cp_r(images_source, images_dest)
34
+
35
+ config_ru_path = "#{File.expand_path('../..', __FILE__)}/config.ru"
36
+ config_ru_dest = "#{project_pwd}/config.ru"
37
+
38
+ puts "config_ru_path: #{config_ru_path}"
39
+ puts "config_ru_dest: #{config_ru_dest}"
40
+
41
+ FileUtils.cp_r(config_ru_path, config_ru_dest)
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instamatic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Neely
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.4.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.4.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: mini_magick
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'It''s an image placement service in a box! Step 1: Install and run a
70
+ generator. Step 2) Drop your images into the images directory. Step 3) Profit!'
71
+ email:
72
+ - aneely@gmail.com
73
+ executables:
74
+ - setup_instamatic
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - config.ru
86
+ - exe/setup_instamatic
87
+ - instamatic.gemspec
88
+ - lib/instamatic.rb
89
+ - lib/instamatic/app.rb
90
+ - lib/instamatic/images/l_l_cool_j.png
91
+ - lib/instamatic/public/favicon.ico
92
+ - lib/instamatic/public/scripts/app.js
93
+ - lib/instamatic/public/scripts/jqColorPicker.min.js
94
+ - lib/instamatic/public/styles/app.css
95
+ - lib/instamatic/version.rb
96
+ - lib/instamatic/views/index.erb
97
+ - lib/instamatic/views/layout.erb
98
+ - utils/setup_instamatic_util.rb
99
+ homepage: https://bitbucket.org/aneely/instamatic
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ allowed_push_host: https://rubygems.org
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ - utils
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.6
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: It's an image placement service in a box!
125
+ test_files: []