picstapel 0.1.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: 88ce45ba22fe7186f952c5a3af02caa362aecd15
4
+ data.tar.gz: a460adf2092eadfe4ef30f461aaccd4ba8c1040b
5
+ SHA512:
6
+ metadata.gz: dca28556137c394ca1f976d1341c8330336045ac312bd097108baa9586d6e282e3327075616f3655d1a636560349f2e7da3de3babaa2c4915f5ac20a482b3916
7
+ data.tar.gz: 474b6bab4869980330b3e23e265c96658e8af43845241739adefc997dbc585ae31d782328668e2d42bebd8e8d39e784732fb6a496e5b1dc7dd125f6f7cedc919
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in picstapel.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
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.
@@ -0,0 +1,29 @@
1
+ # Picstapel
2
+
3
+ Picstapel is a Ruby command line gem to create a collage of images based on user supplied keywords.
4
+
5
+ ## Installation
6
+
7
+ install it as:
8
+
9
+ $ gem install picstapel
10
+
11
+ ## Usage
12
+
13
+ 1- After installing the gem, type picstapel in terminal and press enter.
14
+
15
+ $ picstapel
16
+
17
+ 2- The program will ask for up to 10 keywords separated by space. Input the keywords and press enter.
18
+ (If less than 10 keywords are supplied, random words will used from the dictionary.)
19
+
20
+ $ sunset niagra beach mountains nature landscape road dessert meadow river
21
+
22
+ 3- The program will ask for a filename at the end, input filename and press enter to create the Collage image on Desktop.
23
+
24
+
25
+
26
+ ## License
27
+
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
29
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "picstapel"
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
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../../lib/picstapel'
3
+
4
+ #Getting keywords from command line and generating an array of 10 keywords
5
+ keyword = Picstapel::Keyword.new
6
+ keywords = keyword.generate_keywords
7
+
8
+ #Creating an array of urls for keyword related images.
9
+ pic = Picstapel::Pic.new
10
+ url_list = pic.get_image_urls_for_keywords(keywords)
11
+
12
+ #Cropping images and adding to collage
13
+ collage = Picstapel::Collage.new
14
+ collage.create_collage(url_list,keywords)
15
+ collage.delete_images
16
+
17
+
18
+
@@ -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
@@ -0,0 +1,35 @@
1
+ module Picstapel
2
+ require 'rmagick'
3
+
4
+ class Collage
5
+ include Magick
6
+
7
+ def create_collage(url_list, keywords)
8
+ collage = Image.new(1500, 500)
9
+ x = y = 0;
10
+ # Crop images and add to collage
11
+ url_list.each_with_index do |val, index|
12
+ open(val) do|f|
13
+ File.open("lib/img/#{keywords[index]}.jpg","wb") do |file|
14
+ file.puts f.read
15
+ crop_img = Magick::Image.read(file.path).first.crop_resized(300, 250, gravity=Magick::CenterGravity)
16
+ collage.composite!(crop_img, x, y, OverCompositeOp)
17
+
18
+ x >= 1200 ? (x=0;y=250) : x+=300 # Increment x by 300 in first 4 iterations, then move to second row by incrementing y by the value of height
19
+ end
20
+ end
21
+ end
22
+ p 'Enter file name for collage'
23
+ img_name = gets.tr("\n",'')
24
+ img_name = 'Collage' if img_name.empty?
25
+
26
+ collage.write(ENV['HOME'] + "/Desktop/#{img_name}.png")
27
+ p "#{img_name}.png created on Desktop"
28
+ end
29
+
30
+ def delete_images
31
+ FileUtils.rm_rf Dir.glob("lib/img/*")
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,196 @@
1
+ art
2
+ ant
3
+ apple
4
+ arm
5
+ army
6
+ baby
7
+ bag
8
+ ball
9
+ band
10
+ basin
11
+ basket
12
+ bath
13
+ bed
14
+ bee
15
+ bell
16
+ berry
17
+ bird
18
+ blade
19
+ board
20
+ boat
21
+ bone
22
+ book
23
+ boot
24
+ bottle
25
+ box
26
+ boy
27
+ brain
28
+ brake
29
+ branch
30
+ brick
31
+ bridge
32
+ brush
33
+ bucket
34
+ bulb
35
+ button
36
+ cake
37
+ camera
38
+ card
39
+ carriage
40
+ cart
41
+ cat
42
+ chain
43
+ cheese
44
+ chest
45
+ chin
46
+ church
47
+ circle
48
+ clock
49
+ cloud
50
+ coat
51
+ collar
52
+ comb
53
+ cord
54
+ cow
55
+ cup
56
+ curtain
57
+ cushion
58
+ dog
59
+ door
60
+ drain
61
+ drawer
62
+ dress
63
+ drop
64
+ ear
65
+ egg
66
+ engine
67
+ eye
68
+ face
69
+ farm
70
+ feather
71
+ finger
72
+ fish
73
+ flag
74
+ floor
75
+ fly
76
+ foot
77
+ fork
78
+ fowl
79
+ frame
80
+ garden
81
+ girl
82
+ glove
83
+ goat
84
+ gun
85
+ hair
86
+ hammer
87
+ hand
88
+ hat
89
+ head
90
+ heart
91
+ hook
92
+ horn
93
+ horse
94
+ hospital
95
+ house
96
+ island
97
+ jewel
98
+ kettle
99
+ key
100
+ knee
101
+ knife
102
+ knot
103
+ leaf
104
+ leg
105
+ library
106
+ line
107
+ lip
108
+ lock
109
+ map
110
+ match
111
+ monkey
112
+ moon
113
+ mouth
114
+ muscle
115
+ nail
116
+ neck
117
+ needle
118
+ nerve
119
+ net
120
+ nose
121
+ nut
122
+ office
123
+ orange
124
+ oven
125
+ parcel
126
+ pen
127
+ pencil
128
+ picture
129
+ pig
130
+ pin
131
+ pipe
132
+ plane
133
+ plate
134
+ pocket
135
+ pot
136
+ potato
137
+ prison
138
+ pump
139
+ rail
140
+ rat
141
+ receipt
142
+ roof
143
+ root
144
+ sail
145
+ school
146
+ scissors
147
+ screw
148
+ seed
149
+ sheep
150
+ shelf
151
+ ship
152
+ shirt
153
+ shoe
154
+ skin
155
+ skirt
156
+ snake
157
+ sock
158
+ spade
159
+ sponge
160
+ spoon
161
+ spring
162
+ square
163
+ stamp
164
+ star
165
+ station
166
+ stem
167
+ stick
168
+ stocking
169
+ stomach
170
+ store
171
+ street
172
+ sun
173
+ table
174
+ tail
175
+ thread
176
+ throat
177
+ thumb
178
+ ticket
179
+ toe
180
+ tongue
181
+ tooth
182
+ town
183
+ train
184
+ tray
185
+ tree
186
+ trousers
187
+ umbrella
188
+ wall
189
+ watch
190
+ wheel
191
+ whip
192
+ whistle
193
+ window
194
+ wing
195
+ wire
196
+ worm
@@ -0,0 +1,22 @@
1
+ module Picstapel
2
+ class Keyword
3
+ dictionary_path = File.expand_path('../dictionary/words.txt', __FILE__)
4
+ @@words = File.readlines(dictionary_path)
5
+
6
+ def self.random_word
7
+ @@words[rand(@@words.size)].chomp
8
+ end
9
+
10
+ #generate keywords array
11
+ def generate_keywords
12
+ p 'Enter up to 10 keywords separated by space'
13
+ keywords = gets.tr('^A-Za-z0-9\s', ' ').split(' ')
14
+ p 'Fetching images...'
15
+ if keywords.length < 10
16
+ (10 - keywords.length).times { keywords << Keyword.random_word }
17
+ end
18
+ keywords[0..9]
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ module Picstapel
2
+
3
+ class Pic
4
+ require 'flickraw'
5
+ FlickRaw.api_key="413baed825d63f6607bc6c99e37c060e"
6
+ FlickRaw.shared_secret="54c6b931993fcaf5"
7
+
8
+ def get_image_urls_for_keywords(keywords)
9
+ url_list= []
10
+ keywords.each_with_index do |word, index|
11
+ #binding.pry
12
+ image = flickr.photos.search(tags: word, media: 'photos', per_page: 1, 'dimension_search_mode': 'min', 'height': 500, 'width': 500) #, extras: 'url_o'
13
+ unless image.first.nil?
14
+ url_list << "http://farm#{image.first.farm}.static.flickr.com/#{image.first.server}/#{image.first.id}_#{image.first.secret}.jpg"
15
+ else
16
+ keywords[index] = word = Keyword.random_word
17
+ redo
18
+ end
19
+ end
20
+ url_list
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,9 @@
1
+ require_relative "picstapel/version"
2
+
3
+ module Picstapel
4
+ require_relative 'keyword'
5
+ require_relative 'pic'
6
+ require_relative 'collage'
7
+ require 'pry'
8
+ require 'open-uri'
9
+ end
@@ -0,0 +1,3 @@
1
+ module Picstapel
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'picstapel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "picstapel"
8
+ spec.version = Picstapel::VERSION
9
+ spec.authors = ["Nauman Tahir"]
10
+ spec.email = ["nomibzu@gmail.com"]
11
+
12
+ spec.summary = %q{Collage generator.}
13
+ spec.description = %q{Enter up to 10 keywords and generate a collage by using images from Flickr.}
14
+ spec.homepage = "https://github.com/Nauman-nxvt/picstapel"
15
+ spec.license = "MIT"
16
+
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "bin/exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "rmagick"
26
+ spec.add_dependency "flickraw"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.13"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "pry"
31
+
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: picstapel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Nauman Tahir
8
+ autorequire:
9
+ bindir: bin/exe
10
+ cert_chain: []
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rmagick
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: flickraw
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
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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: Enter up to 10 keywords and generate a collage by using images from Flickr.
84
+ email:
85
+ - nomibzu@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/exe/picstapel
97
+ - bin/setup
98
+ - lib/collage.rb
99
+ - lib/dictionary/words.txt
100
+ - lib/keyword.rb
101
+ - lib/pic.rb
102
+ - lib/picstapel.rb
103
+ - lib/picstapel/version.rb
104
+ - picstapel.gemspec
105
+ homepage: https://github.com/Nauman-nxvt/picstapel
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Collage generator.
129
+ test_files: []