placeholder_image 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.
Files changed (3) hide show
  1. data/README.md +58 -0
  2. data/lib/placeholder_image.rb +45 -0
  3. metadata +65 -0
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ placeholder_image
2
+ =================
3
+
4
+ A gem to generate placeholder images (via data URI) of any (reasonable) size, color (that ImageMagick supports), and text color.
5
+
6
+ SYNOPSIS
7
+ ========
8
+
9
+ In a view:
10
+ <%= placeholder_image_tag :width => 200, :height => 100, :color => :navy, :text_color => :orange %>
11
+
12
+ or for the simplest cases:
13
+ <%= placeholder_image_tag "200x100" # widthxheight %>
14
+
15
+ REQUIREMENTS
16
+ ============
17
+
18
+ rmagick - `sudo gem install rmagick`
19
+
20
+ INSTALLATION
21
+ ============
22
+
23
+ sudo gem install placeholder_image
24
+
25
+ then in your environment.rb:
26
+ config.gem 'placeholder_image', :source => 'http://gemcutter.org'
27
+
28
+ TODO
29
+ ====
30
+
31
+ IE support - If I wait long enough, IE will support me instead. Until then, there's no IE support.
32
+
33
+
34
+ LICENSE
35
+ =======
36
+
37
+ (The MIT License)
38
+
39
+ Copyright (c) 2010 Michael Dungan
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ require 'RMagick'
2
+ require 'rvg/rvg'
3
+
4
+ module PlaceholderImage
5
+ def placeholder_image_tag(*args)
6
+ "<img src='#{placeholder_image_url(*args)}' />"
7
+ end
8
+
9
+ private
10
+
11
+ def placeholder_image_url(*args)
12
+ "data:image/png;base64,#{placeholder_image_data(*args)}"
13
+ end
14
+
15
+ def placeholder_image_data(*args)
16
+ if args.first.is_a? String
17
+ width, height = args.shift.downcase.split('x').map(&:to_i)
18
+ end
19
+
20
+ options = args.shift || {}
21
+
22
+ width ||= options[:width].to_i
23
+ height ||= options[:height].to_i
24
+ color = options.key?(:color) ? options[:color].to_s : "grey69"
25
+ text_color = options.key?(:text_color) ? options[:text_color].to_s : "black"
26
+
27
+ rvg = Magick::RVG.new(width, height).viewbox(0, 0, width, height) do |canvas|
28
+ canvas.background_fill = color
29
+ end
30
+
31
+ img = rvg.draw
32
+
33
+ img.format = "png"
34
+
35
+ drawable = Magick::Draw.new
36
+ drawable.pointsize = width / 10
37
+ drawable.fill = text_color
38
+ drawable.gravity = Magick::CenterGravity
39
+ drawable.annotate(img, 0, 0, 0, 0, "#{width} x #{height}")
40
+
41
+ [img.to_blob].pack("m")
42
+ end
43
+ end
44
+
45
+ ActionView::Base.send(:include, PlaceholderImage)
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: placeholder_image
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Dungan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-26 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rmagick
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "2.0"
24
+ version:
25
+ description: Generate placeholder images of various sizes, colors, and text colors.
26
+ email: mpd@jesters-court.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.md
33
+ files:
34
+ - lib/placeholder_image.rb
35
+ - README.md
36
+ has_rdoc: true
37
+ homepage: http://github.com/xxx/placeholder_image
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.5
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Generate placeholder images of various sizes
64
+ test_files: []
65
+