project_madurai 0.0.7 → 0.0.8

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/README.md CHANGED
@@ -1,9 +1,27 @@
1
1
  # ProjectMadurai
2
2
 
3
- TODO: Write a gem description
3
+ http://projectmadurai.org/pmworks.html
4
+
5
+ Project madurai takes title and author of above url. it will create cover page image for each title and author.
6
+
7
+ ## How it works
8
+
9
+ It takes all title and author from above url using Nokogiri. For each title and author, it create html file and take screenshot with help of phantomjs
10
+
11
+ Previously I used RMagick ( or other image processing tool ) to create image. Font was not rendered properly with rmagick. See sample before.
12
+
13
+ If you faced same issue and you cracked it. Please guide us at sathia2704@gmail.com
14
+
4
15
 
5
16
  ## Installation
6
17
 
18
+ ### Installing Phantomjs. This is required*
19
+
20
+ Check how to install from below link
21
+ http://phantomjs.org/download.html
22
+
23
+ ### Install project_madurai gem
24
+
7
25
  $ gem install project_madurai
8
26
 
9
27
  ## Usage
@@ -14,6 +32,20 @@ TODO: Write a gem description
14
32
 
15
33
  $ project_madurai extract --image /path_of_image
16
34
 
35
+
36
+ ## Demo
37
+
38
+ #### Previous version with RMagick
39
+
40
+ ![alt text](public/sample1.jpg "Demo")
41
+
42
+ #### Current version with PhantomJs
43
+
44
+ ![alt text](public/sample2.jpg "Demo")
45
+
46
+
47
+
48
+
17
49
  ## Contributing
18
50
 
19
51
  1. Fork it ( https://github.com/[my-github-username]/project_madurai/fork )
@@ -1,35 +1,22 @@
1
- require "RMagick"
1
+ require_relative '../html_generator/html'
2
2
  module CoverPageGenerator
3
3
  class Image
4
- def initialize file_name, title, author
4
+ def initialize file_name, title, author, image_index
5
5
  @file_name = file_name || "public/image.jpg"
6
6
  @title = title
7
7
  @author = author
8
- public_folder = File.expand_path('../../../public', __FILE__)
9
- @font = "#{public_folder}/ta.ttf"
8
+ @public_folder = File.expand_path('../../../public', __FILE__)
9
+ @font = "#{@public_folder}/tam.ttf"
10
+ @html_content = HtmlGenerator::Html.new(@title, @author, @font, @file_name)
11
+ @html_file = File.open("#{@public_folder}/html_files/1.html", "w")
12
+ @image_index = image_index
10
13
  end
11
14
 
12
15
  def generate
13
- pwd = Dir.pwd
14
- img = Magick::ImageList.new(@file_name)
15
- canvas = Magick::ImageList.new
16
- canvas.new_image(450, 700, Magick::TextureFill.new(img))
17
- text = Magick::Draw.new
18
- text.encoding = "Unicode"
19
- text.font = @font
20
- text.gravity = Magick::CenterGravity
21
- @title = @title.scan(/\S.{0,30}\S(?=\s|$)|\S+/).join("\n")
22
- text.annotate(canvas, 450,300,0,0, @title) {
23
- self.fill = '#fff'
24
- self.pointsize = 30
25
- }
26
- text.annotate(canvas, 450,500,0,0, @author) {
27
- self.fill = '#fff'
28
- self.pointsize = 22
29
- }
30
- titlize = @title.gsub(" ", "_").gsub("/", "_").gsub("\n", "_")
31
- puts "Generating '#{(pwd + "/project_madurai/" + titlize + ".jpg")}'"
32
- canvas.write(pwd + "/project_madurai/" + titlize + ".jpg")
16
+ @html_file.write(@html_content.to_html)
17
+ @html_file.close
18
+ system("phantomjs #{@public_folder}/phantomjs/rasterize.js #{@public_folder}/html_files/1.html project_madurai/#{@image_index}.jpg '450px*700px'")
19
+ "Generating project/madurai/#{@image_index}.jpg => @{title}"
33
20
  end
34
21
  end
35
22
  end
@@ -0,0 +1,34 @@
1
+ module HtmlGenerator
2
+ class Html
3
+ def initialize title, author, font, bg
4
+ @title = title
5
+ @author = author
6
+ @font = font
7
+ @bg = bg
8
+ end
9
+
10
+ def to_html
11
+ <<-EOM
12
+ <!DOCTYPE html>
13
+ <html>
14
+ <head>
15
+ <meta charset="UTF-8">
16
+ <title>#{@title}</title>
17
+ <style>
18
+ @font-face {
19
+ font-family: 'TamilFont';
20
+ url('#{@font}') format('truetype')
21
+ }
22
+ </style>
23
+ </head>
24
+ <body style='background:url(#{@bg}) no-repeat;text-align:center;color:#fff'>
25
+ <div style='padding:10px'>
26
+ <h1 style="font-weight:bold">#{@title}</h1>
27
+ <p style='position:absolute;width:100%;bottom:100px;font-size:25px;color:#a00'>#{@author}</p>
28
+ </div>
29
+ </body>
30
+ </html>
31
+ EOM
32
+ end
33
+ end
34
+ end
@@ -9,8 +9,14 @@ class Extractor
9
9
  def start
10
10
  details = ProjectMadurai::MetaData.new.list
11
11
  Dir.mkdir("project_madurai") rescue true
12
+ image_index = 1
12
13
  details.each do |detail|
13
- CoverPageGenerator::Image.new(@image, detail[:title], detail[:author]).generate
14
+ begin
15
+ puts CoverPageGenerator::Image.new(@image, detail[:title], detail[:author], image_index).generate
16
+ image_index+=1
17
+ rescue Interrupt
18
+ puts "Bye"
19
+ end
14
20
  end
15
21
  end
16
22
  end
@@ -1,3 +1,3 @@
1
1
  module ProjectMadurai
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>திருவாசகம் - 2 (11-51)</title>
6
+ <style>
7
+ @font-face {
8
+ font-family: 'TamilFont';
9
+ url('/Users/sathia/Developer/projectmadurai/project_madurai/public/tam.ttf') format('truetype')
10
+ }
11
+ </style>
12
+ </head>
13
+ <body style='background:url(/Users/sathia/Developer/projectmadurai/project_madurai/public/image.jpg) no-repeat;text-align:center;color:#fff'>
14
+ <div style='padding:10px'>
15
+ <h1 style="font-weight:bold">திருவாசகம் - 2 (11-51)</h1>
16
+ <p style='position:absolute;width:100%;bottom:100px;font-size:25px;color:#a00'>மாணிக்க வாசகர்</p>
17
+ </div>
18
+ </body>
19
+ </html>
@@ -0,0 +1,48 @@
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
+ console.log(' image (png/jpg output) examples: "1920px" entire page, window width 1920px');
9
+ console.log(' "800px*600px" window, clipped to 800x600');
10
+ phantom.exit(1);
11
+ } else {
12
+ address = system.args[1];
13
+ output = system.args[2];
14
+ page.viewportSize = { width: 600, height: 600 };
15
+ if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
16
+ size = system.args[3].split('*');
17
+ page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
18
+ : { format: system.args[3], orientation: 'portrait', margin: '1cm' };
19
+ } else if (system.args.length > 3 && system.args[3].substr(-2) === "px") {
20
+ size = system.args[3].split('*');
21
+ if (size.length === 2) {
22
+ pageWidth = parseInt(size[0], 10);
23
+ pageHeight = parseInt(size[1], 10);
24
+ page.viewportSize = { width: pageWidth, height: pageHeight };
25
+ page.clipRect = { top: 0, left: 0, width: pageWidth, height: pageHeight };
26
+ } else {
27
+ console.log("size:", system.args[3]);
28
+ pageWidth = parseInt(system.args[3], 10);
29
+ pageHeight = parseInt(pageWidth * 3/4, 10); // it's as good an assumption as any
30
+ console.log ("pageHeight:",pageHeight);
31
+ page.viewportSize = { width: pageWidth, height: pageHeight };
32
+ }
33
+ }
34
+ if (system.args.length > 4) {
35
+ page.zoomFactor = system.args[4];
36
+ }
37
+ page.open(address, function (status) {
38
+ if (status !== 'success') {
39
+ console.log('Unable to load the address!');
40
+ phantom.exit();
41
+ } else {
42
+ window.setTimeout(function () {
43
+ page.render(output);
44
+ phantom.exit();
45
+ }, 200);
46
+ }
47
+ });
48
+ }
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: project_madurai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-13 00:00:00.000000000 Z
12
+ date: 2014-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -107,12 +107,17 @@ files:
107
107
  - Rakefile
108
108
  - bin/project_madurai
109
109
  - lib/cover_page_generator/image.rb
110
+ - lib/html_generator/html.rb
110
111
  - lib/project_madurai.rb
111
112
  - lib/project_madurai/meta_data.rb
112
113
  - lib/project_madurai/version.rb
113
114
  - project_madurai.gemspec
115
+ - public/html_files/1.html
114
116
  - public/image.jpg
115
- - public/ta.ttf
117
+ - public/phantomjs/rasterize.js
118
+ - public/sample1.jpg
119
+ - public/sample2.jpg
120
+ - public/tam.ttf
116
121
  homepage: ''
117
122
  licenses:
118
123
  - GPLV3
Binary file