capture_image 0.0.1 → 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capture_image.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 muhammad-irfan-confz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # CaptureImage
2
+
3
+ It's create the image of given url, uses Phantomjs at backend to create image
4
+
5
+ http://phantomjs.org/
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'capture_image'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capture_image
20
+
21
+
22
+
23
+ ## Authors
24
+
25
+ https://github.com/muhammad-irfan-confiz
26
+
27
+
28
+
29
+ ## Usage
30
+
31
+ Just create the form tag and pass the url as text field i.e.
32
+
33
+ <%=form_tag ( { controller: "home", action: "capture_image" } ) do%>
34
+ <%= text_field_tag "url", nil %>
35
+ <%= submit_tag :create%>
36
+ <%end%>
37
+
38
+ Pass the url to Rack to create the image i.e.
39
+
40
+ req = Rack::Request.new(params[:url])
41
+
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capture_image/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capture_image"
8
+ spec.version = CaptureImage::VERSION
9
+ spec.authors = ["muhammad-irfan-confiz"]
10
+ spec.email = ["muhammad.irfan@confiz.com"]
11
+ spec.description = %q{it uses phantomjs at backend to create an image of given url on middleware level }
12
+ spec.summary = %q{it creates an image of given url using middleware}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "phantomjs", "~> 1.8.1"
24
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capture_image/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capture_image"
8
+ spec.version = CaptureImage::VERSION
9
+ spec.authors = ["muhammad-irfan-confiz"]
10
+ spec.email = ["muhammad.irfan@confiz.com"]
11
+ spec.description = %q{it uses phantomjs at backend to create an image of given url on middleware level }
12
+ spec.summary = %q{it creates an image of given url using middleware}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "phantomjs", "~> 1.8.1"
24
+ end
@@ -0,0 +1,22 @@
1
+ require 'phantomjs'
2
+ class CaptureImage
3
+ # Your code goes here...
4
+
5
+ def initilize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ req = Rack::Request.new(env)
11
+ if req.params["url"].present?
12
+ system('phantomjs /lib/phantomjs_rasterize/rasterize.js' + " " + req.params["url"] + " " + 'image.png')
13
+ req.params["url"]= nil
14
+ end
15
+ @app.call(env)
16
+ end
17
+
18
+ def self.test
19
+ system('phantomjs /lib/phantomjs_rasterize/rasterize.js http://www.google.com image.png')
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'phantomjs'
2
+ class CaptureImage
3
+ # Your code goes here...
4
+
5
+ def initilize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ req = Rack::Request.new(env)
11
+ if req.params["url"].present?
12
+ system('phantomjs /lib/phantomjs_rasterize/rasterize.js' + " " + req.params["url"] + " " + 'image.png')
13
+ req.params["url"]= nil
14
+ end
15
+ @app.call(env)
16
+ end
17
+
18
+ def self.test
19
+ 'phantomjs /lib/phantomjs_rasterize/rasterize.js http://www.google.com image.png'
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ module CaptureImage
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,32 @@
1
+ var page = require('webpage').create(),
2
+ system = require('system'),
3
+ address, output, size;
4
+
5
+ if (system.args.length < 3 || system.args.length > 5) {
6
+ console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
7
+ console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
8
+ phantom.exit(1);
9
+ } else {
10
+ address = system.args[1];
11
+ output = system.args[2];
12
+ page.viewportSize = { width: 600, height: 600 };
13
+ if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
14
+ size = system.args[3].split('*');
15
+ page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
16
+ : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
17
+ }
18
+ if (system.args.length > 4) {
19
+ page.zoomFactor = system.args[4];
20
+ }
21
+ page.open(address, function (status) {
22
+ if (status !== 'success') {
23
+ console.log('Unable to load the address!');
24
+ phantom.exit();
25
+ } else {
26
+ window.setTimeout(function () {
27
+ page.render(output);
28
+ phantom.exit();
29
+ }, 200);
30
+ }
31
+ });
32
+ }
@@ -0,0 +1,32 @@
1
+ var page = require('webpage').create(),
2
+ system = require('system'),
3
+ address, output, size;
4
+
5
+ if (system.args.length < 3 || system.args.length > 5) {
6
+ console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
7
+ console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
8
+ phantom.exit(1);
9
+ } else {
10
+ address = system.args[1];
11
+ output = system.args[2];
12
+ page.viewportSize = { width: 600, height: 600 };
13
+ if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
14
+ size = system.args[3].split('*');
15
+ page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
16
+ : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
17
+ }
18
+ if (system.args.length > 4) {
19
+ page.zoomFactor = system.args[4];
20
+ }
21
+ page.open(address, function (status) {
22
+ if (status !== 'success') {
23
+ console.log('Unable to load the address!');
24
+ phantom.exit();
25
+ } else {
26
+ window.setTimeout(function () {
27
+ page.render(output);
28
+ phantom.exit();
29
+ }, 200);
30
+ }
31
+ });
32
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capture_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -66,7 +66,19 @@ email:
66
66
  executables: []
67
67
  extensions: []
68
68
  extra_rdoc_files: []
69
- files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - capture_image.gemspec
76
+ - capture_image.gemspec~
77
+ - lib/capture_image.rb
78
+ - lib/capture_image.rb~
79
+ - lib/capture_image/version.rb
80
+ - lib/phantomjs_rasterize/rasterize.js
81
+ - lib/phantomjs_rasterize/rasterize.js~
70
82
  homepage: ''
71
83
  licenses:
72
84
  - MIT