lorempixel 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +15 -0
  2. data/bin/lorempixel +14 -0
  3. data/lib/lorempixel.rb +78 -0
  4. metadata +74 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YjM0MjkwMjJjMDNmNTVjYTliZDM5MDA4NDMwMTQ2YmFlNDZjMmRhNQ==
5
+ data.tar.gz: !binary |-
6
+ NDMwNWViNjdiNjI0YzVjMjNhY2E0YjM5NmQ0M2I1YzY5NDE1Y2Q3NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZmJmNmZiZDkyOGVkN2FkNTU4Y2MzZWQ2NmNkOTYzOWZmMGM5YTA1MmU1MjYw
10
+ Y2EyNTllMDZmOWQ5OWM2ZDA2MDI0YjNkYjdhMzg3YWE3YmJhMjFiZTg1MGRm
11
+ Mzg1NmFmYjY2MjVmYmJhNTI2NjY1Yjg2MzQ5NDU0NTM3NDY2NTY=
12
+ data.tar.gz: !binary |-
13
+ NjQ3ZjMyZGUwMGI1YzAyMzJkNGM3Y2VkNWExYmViZDViZWNhNWM0OTBmZTNm
14
+ ZjFhM2U0NzI2MzliMmMzZTcwNjkwM2NkZTMxMzJhNjFjNTI1Nzk4YjNlYjc3
15
+ ODRlNDc1MzE5ODMwMzgyNDM2OWMwOTdmZGE1ZGFmMzk1MTdmMzA=
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lorempixel'
4
+ require 'trollop'
5
+
6
+ opts = Trollop::options do
7
+ opt :amount, "Set number of images to create", :default => 10
8
+ opt :dir, "Set the directory to put the images in", :default => "images"
9
+ opt :height, "Set the height(eg 100) or height range (eg 100-500)", :default => "100-500"
10
+ opt :prefix, "Set the naming convention for images (alphanumeric and underscore only)", :default => "image_"
11
+ opt :width, "Set the width(eg 100) or width range (eg 100-500)", :default => "100-500"
12
+ end
13
+
14
+ Lorempixel.new(opts).create_images
@@ -0,0 +1,78 @@
1
+ require "httpclient"
2
+
3
+ class Lorempixel
4
+ attr_reader :amount, :dir, :prefix, :height, :width
5
+
6
+ def initialize args = {}
7
+ self.format_dimensions args
8
+ self.set_props args
9
+
10
+ unless File.directory?(@dir)
11
+ Dir.mkdir(@dir)
12
+ end
13
+ @dir = Dir.new(dir)
14
+ end
15
+
16
+ def format_dimensions args
17
+ [:height, :width].each do |v|
18
+ if args[v]
19
+ if args[v].respond_to?("split")
20
+ r = args[v].split("-")
21
+ args[v] = {
22
+ :min => r.first.chomp.to_i,
23
+ :max => r.last.chomp.to_i,
24
+ }
25
+ else
26
+ d = self.class.defaults
27
+ args[v][:min] = args[v][:min] || d[v][:min]
28
+ args[v][:max] = args[v][:max] || d[v][:max]
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def set_props args
35
+ self.class.defaults.each do |k, v|
36
+ v = args[k] || v
37
+ self.instance_variable_set("@#{k}", v)
38
+ end
39
+ end
40
+
41
+ def self.defaults
42
+ r = {
43
+ :amount => 10,
44
+ :prefix => "image_",
45
+ :height => {
46
+ :min => 100,
47
+ :max => 500
48
+ },
49
+ :width => {
50
+ :min => 100,
51
+ :max => 500
52
+ },
53
+ :dir => "images"
54
+ }
55
+ r
56
+ end
57
+
58
+ def create_images
59
+ (1..@amount).each do |i|
60
+ url = self.get_provider
61
+
62
+ i_num = "%0#{@amount.to_s.length}d" % i
63
+
64
+ HTTPClient.new
65
+ result = HTTPClient.get url
66
+ File.open(File.join(@dir, "#{@prefix}#{i_num}.png"), "w") do |f|
67
+ f.write(result.body)
68
+ end
69
+ end
70
+ end
71
+
72
+ def get_provider
73
+ height = rand(@height[:min]..@height[:max])
74
+ width = rand(@width[:min]..@width[:max])
75
+ "http://lorempixel.com/#{width}/#{height}/"
76
+ end
77
+
78
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lorempixel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sean Sehr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: trollop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: httpclient
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A Ruby gem for making dummy images from www.lorempixel.com
42
+ email: sean@seansehr.com
43
+ executables:
44
+ - lorempixel
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/lorempixel.rb
49
+ - bin/lorempixel
50
+ homepage: https://github.com/xeraseth/lorempixel_gem
51
+ licenses:
52
+ - MIT
53
+ metadata: {}
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubyforge_project:
70
+ rubygems_version: 2.1.11
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Dummy Image Generator
74
+ test_files: []