strokes 0.1
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/CHANGELOG.md +0 -0
- data/LICENSE +20 -0
- data/README.md +68 -0
- data/ROADMAP.md +14 -0
- data/lib/strokes.rb +10 -0
- data/lib/strokes/active_record.rb +70 -0
- data/lib/strokes/barcode.ps +17110 -0
- data/lib/strokes/barcode.rb +88 -0
- metadata +75 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'subexec'
|
|
2
|
+
|
|
3
|
+
module Strokes
|
|
4
|
+
|
|
5
|
+
VALID_SYMBOLS = [:qrcode, :code39, :code128, :ean8, :ean13, :isbn, :upca, :upce]
|
|
6
|
+
|
|
7
|
+
class Barcode
|
|
8
|
+
|
|
9
|
+
def initialize(symbol, content, options = '')
|
|
10
|
+
raise IllegalSymbolError, symbol.to_s unless VALID_SYMBOLS.include?(symbol.to_sym)
|
|
11
|
+
@symbol = symbol.to_sym
|
|
12
|
+
@content = content
|
|
13
|
+
@options = options
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# filename should include the full path
|
|
17
|
+
# options:
|
|
18
|
+
# - width: width of the resulting png
|
|
19
|
+
def save(filename, options = {})
|
|
20
|
+
ps = send(@symbol)
|
|
21
|
+
gs_options = [
|
|
22
|
+
"-dBATCH", "-dNOPAUSE", "-q", "-dTextAlphaBits=4", "-dSAFER",
|
|
23
|
+
"-sOutputFile=#{filename}",
|
|
24
|
+
"-sDEVICE=pnggray"
|
|
25
|
+
]
|
|
26
|
+
barcode_ps = "#{File.expand_path(File.dirname(__FILE__))}/barcode.ps"
|
|
27
|
+
sub = Subexec.run "gs #{gs_options.join(" ")} #{barcode_ps} -c '#{ps}'"
|
|
28
|
+
raise(GhostScriptError, sub.output) unless sub.exitstatus == 0
|
|
29
|
+
resize_method = (ps =~ /includetext/ ? "-scale" : "-sample")
|
|
30
|
+
im_options = [
|
|
31
|
+
"-trim",
|
|
32
|
+
"-bordercolor white",
|
|
33
|
+
"-border 10%",
|
|
34
|
+
options[:width] ? "#{resize_method} #{options[:width]}" : nil
|
|
35
|
+
].compact
|
|
36
|
+
sub = Subexec.run "mogrify #{im_options.join(' ')} #{filename}"
|
|
37
|
+
raise(ImageMagickError, sub.output) unless sub.exitstatus == 0
|
|
38
|
+
File.open(filename, 'r')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def ps_commands(code_options, options = {})
|
|
44
|
+
<<-PS
|
|
45
|
+
<</Orientation 1>> setpagedevice
|
|
46
|
+
#{options[:translate] || '100 680'} translate
|
|
47
|
+
#{options[:rotate] || '-90'} rotate
|
|
48
|
+
#{options[:scale] || '6 6'} scale
|
|
49
|
+
0 0 moveto (#{@content}) (#{code_options.join(' ')}) /#{@symbol} /uk.co.terryburton.bwipp findresource exec
|
|
50
|
+
showpage
|
|
51
|
+
PS
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def qrcode
|
|
55
|
+
ps_commands([@options], :translate => '0 750', :scale => '8 8')
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def upca
|
|
59
|
+
ps_commands(['includetext', @options])
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def upce
|
|
63
|
+
ps_commands(['includetext', @options])
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def isbn
|
|
67
|
+
ps_commands(['includetext', 'guardwhitespace', @options])
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def ean8
|
|
71
|
+
ps_commands(['includetext', 'guardwhitespace', @options])
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def ean13
|
|
75
|
+
ps_commands(['includetext', 'guardwhitespace', @options])
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def code39
|
|
79
|
+
ps_commands(['includetext', @options], :scale => '5 5')
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def code128
|
|
83
|
+
ps_commands(['includetext', @options], :scale => '4 4', :translate => '150 750')
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: strokes
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '0.1'
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Lars Kuhnt
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2011-11-07 00:00:00.000000000Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: subexec
|
|
16
|
+
requirement: &70111127081160 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70111127081160
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: rspec
|
|
27
|
+
requirement: &70111127080700 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70111127080700
|
|
36
|
+
description: Generates PNG images of barcodes (i.e. EAN13, QR-Code, ISBN)
|
|
37
|
+
email:
|
|
38
|
+
- lars.kuhnt@gmail.com
|
|
39
|
+
executables: []
|
|
40
|
+
extensions: []
|
|
41
|
+
extra_rdoc_files: []
|
|
42
|
+
files:
|
|
43
|
+
- lib/strokes/active_record.rb
|
|
44
|
+
- lib/strokes/barcode.ps
|
|
45
|
+
- lib/strokes/barcode.rb
|
|
46
|
+
- lib/strokes.rb
|
|
47
|
+
- LICENSE
|
|
48
|
+
- README.md
|
|
49
|
+
- CHANGELOG.md
|
|
50
|
+
- ROADMAP.md
|
|
51
|
+
homepage: http://github.com/larskuhnt/strokes
|
|
52
|
+
licenses: []
|
|
53
|
+
post_install_message:
|
|
54
|
+
rdoc_options: []
|
|
55
|
+
require_paths:
|
|
56
|
+
- lib
|
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
|
+
none: false
|
|
59
|
+
requirements:
|
|
60
|
+
- - ! '>='
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
|
+
none: false
|
|
65
|
+
requirements:
|
|
66
|
+
- - ! '>='
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: 1.3.6
|
|
69
|
+
requirements: []
|
|
70
|
+
rubyforge_project:
|
|
71
|
+
rubygems_version: 1.8.10
|
|
72
|
+
signing_key:
|
|
73
|
+
specification_version: 3
|
|
74
|
+
summary: Ruby wrapper for the awsome postscriptbarcode library
|
|
75
|
+
test_files: []
|