ruby-batik 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +71 -0
- data/Gemfile +4 -0
- data/README.rdoc +24 -0
- data/Rakefile +1 -0
- data/lib/ruby-batik/transcoder.rb +21 -0
- data/lib/ruby-batik/transcoders/abstract.rb +76 -0
- data/lib/ruby-batik/transcoders/jpeg.rb +16 -0
- data/lib/ruby-batik/transcoders/png.rb +21 -0
- data/lib/ruby-batik/transcoders/tiff.rb +15 -0
- data/lib/ruby-batik/version.rb +3 -0
- data/lib/ruby-batik.rb +10 -0
- data/ruby-batik.gemspec +22 -0
- metadata +77 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="jruby-1.6.5@ruby-batik"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
+
#
|
14
|
+
# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
|
15
|
+
#
|
16
|
+
# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
|
17
|
+
#
|
18
|
+
|
19
|
+
#
|
20
|
+
# First we attempt to load the desired environment directly from the environment
|
21
|
+
# file. This is very fast and efficient compared to running through the entire
|
22
|
+
# CLI and selector. If you want feedback on which environment was used then
|
23
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
24
|
+
#
|
25
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
26
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
27
|
+
then
|
28
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
29
|
+
|
30
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
31
|
+
then
|
32
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
33
|
+
fi
|
34
|
+
else
|
35
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
36
|
+
if ! rvm --create use "$environment_id"
|
37
|
+
then
|
38
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
39
|
+
return 1
|
40
|
+
fi
|
41
|
+
fi
|
42
|
+
|
43
|
+
#
|
44
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
45
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
46
|
+
# necessary.
|
47
|
+
#
|
48
|
+
# filename=".gems"
|
49
|
+
# if [[ -s "$filename" ]]
|
50
|
+
# then
|
51
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
52
|
+
# fi
|
53
|
+
|
54
|
+
# If you use bundler, this might be useful to you:
|
55
|
+
# if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
|
56
|
+
# then
|
57
|
+
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
|
58
|
+
# gem install bundler
|
59
|
+
# fi
|
60
|
+
# if [[ -s Gemfile ]] && command -v bundle
|
61
|
+
# then
|
62
|
+
# bundle install
|
63
|
+
# fi
|
64
|
+
|
65
|
+
if [[ $- == *i* ]] # check for interactive shells
|
66
|
+
then
|
67
|
+
echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
68
|
+
else
|
69
|
+
echo "Using: $GEM_HOME" # don't use colors in interactive shells
|
70
|
+
fi
|
71
|
+
|
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
=Batik
|
2
|
+
Batik (http://xmlgraphics.apache.org/batik/) is a Java-based toolkit for applications or applets that want to use images in the Scalable Vector Graphics (SVG) format for various purposes, such as display, generation or manipulation.
|
3
|
+
|
4
|
+
=Quick Start
|
5
|
+
Be sure to add your batik installation to the classpath.
|
6
|
+
|
7
|
+
==Rasterization
|
8
|
+
|
9
|
+
# Create a transcoder
|
10
|
+
transcoder = Batik::Transcoder.new
|
11
|
+
|
12
|
+
# Transcode an svg string to a string as a PNG
|
13
|
+
png = transcoder.to_png(svg_document)
|
14
|
+
|
15
|
+
# Transcode an svg string to a string as a JPEG
|
16
|
+
jpeg = transcoder.to_jpeg(svg_document)
|
17
|
+
|
18
|
+
# Transcode an svg string to a string as a PNG with some options
|
19
|
+
png = transcoder.to_png(svg_document, :dpi => 600, :indexed => 8)
|
20
|
+
|
21
|
+
# Transcode an svg string to a file
|
22
|
+
File.open('new.png', 'wb+') { |fp|
|
23
|
+
fp.write(transcoder.to_png(svg_document))
|
24
|
+
}
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Batik
|
2
|
+
class Transcoder
|
3
|
+
def initialize(options={})
|
4
|
+
@options = options
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_png(document, args={})
|
8
|
+
Transcoders::PNG.transcode(document, @options.merge(args))
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_jpeg(document, args={})
|
12
|
+
Transcoders::JPEG.transcode(document, @options.merge(args))
|
13
|
+
end
|
14
|
+
alias_method :to_jpg, :to_jpeg
|
15
|
+
|
16
|
+
def to_tiff(document, args={})
|
17
|
+
Transcoders::TIFF.transcode(document, @options.merge(args))
|
18
|
+
end
|
19
|
+
alias_method :to_tif, :to_tiff
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Batik
|
2
|
+
module Transcoders
|
3
|
+
import org.apache.batik.transcoder.TranscodingHints
|
4
|
+
import org.apache.batik.transcoder.TranscoderInput
|
5
|
+
import org.apache.batik.transcoder.TranscoderOutput
|
6
|
+
class Abstract
|
7
|
+
def self.java_types
|
8
|
+
{
|
9
|
+
:snapshot_time => Float,
|
10
|
+
:pixel_unit_to_millimeter => Float,
|
11
|
+
:max_height => Float,
|
12
|
+
:max_width => Float,
|
13
|
+
:height => Float,
|
14
|
+
:width => Float,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.default_options
|
19
|
+
{
|
20
|
+
:execute_onload => true, # true/false
|
21
|
+
:allowed_script_types => nil, # text/ecmascript, application/java-archive
|
22
|
+
:constrain_script_origin => nil, # true/false
|
23
|
+
:snapshot_time => nil,
|
24
|
+
:pixel_unit_to_millimeter => 0.264583, # Size of a px in millimeters
|
25
|
+
:user_stylesheet_uri => nil,
|
26
|
+
:alternate_stylesheet => nil,
|
27
|
+
:default_font_family => nil,
|
28
|
+
:media => nil,
|
29
|
+
:language => nil,
|
30
|
+
:max_height => nil,
|
31
|
+
:max_width => nil,
|
32
|
+
:height => nil,
|
33
|
+
:width => nil,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.transcode(document, options={})
|
38
|
+
options = default_options.merge(process_options(options.dup))
|
39
|
+
in_io = StringIO.new(document)
|
40
|
+
out_io = StringIO.new('','w+b')
|
41
|
+
|
42
|
+
transcoder = klass.new
|
43
|
+
options.each_pair do |key, val|
|
44
|
+
next if val.nil?
|
45
|
+
|
46
|
+
java_type = java_type_for(key)
|
47
|
+
transcoder.java_send(:addTranscodingHint,
|
48
|
+
[TranscodingHints::Key, java.lang.Object],
|
49
|
+
transcoder.class.const_get("key_#{key}".upcase),
|
50
|
+
val.to_java(java_type))
|
51
|
+
end
|
52
|
+
input = TranscoderInput.java_class.constructor(java.io.InputStream).new_instance(in_io.to_inputstream)
|
53
|
+
output = TranscoderOutput.java_class.constructor(java.io.OutputStream).new_instance(out_io.to_outputstream)
|
54
|
+
|
55
|
+
transcoder.transcode(input, output)
|
56
|
+
out_io.flush
|
57
|
+
out_io.rewind
|
58
|
+
out_io.read
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def self.process_options(options)
|
64
|
+
if dpi = options.delete(:dpi)
|
65
|
+
options[:pixel_unit_to_millimeter] = 25.4 / dpi
|
66
|
+
end
|
67
|
+
|
68
|
+
options
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.java_type_for(key)
|
72
|
+
java_types[key] ? eval("java.lang.#{java_types[key]}") : nil
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Batik
|
2
|
+
module Transcoders
|
3
|
+
import org.apache.batik.transcoder.image.JPEGTranscoder
|
4
|
+
class JPEG < Abstract
|
5
|
+
def self.klass; JPEGTranscoder; end
|
6
|
+
|
7
|
+
def self.java_types
|
8
|
+
super.merge({:quality => Float})
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.default_options
|
12
|
+
super.merge({:quality => 0.8})
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Batik
|
2
|
+
module Transcoders
|
3
|
+
import org.apache.batik.transcoder.image.PNGTranscoder
|
4
|
+
class PNG < Abstract
|
5
|
+
def self.klass; PNGTranscoder; end
|
6
|
+
|
7
|
+
def self.java_types
|
8
|
+
super.merge({:gamma => Float})
|
9
|
+
end
|
10
|
+
|
11
|
+
# Available options:
|
12
|
+
# indexed(Integer) => nil
|
13
|
+
# 8,4,2,1
|
14
|
+
# gamma(Float) => nil
|
15
|
+
#
|
16
|
+
def self.default_options
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Batik
|
2
|
+
module Transcoders
|
3
|
+
import org.apache.batik.transcoder.image.TIFFTranscoder
|
4
|
+
class TIFF < Abstract
|
5
|
+
def self.klass; TIFFTranscoder; end
|
6
|
+
|
7
|
+
# Available options:
|
8
|
+
# force_transparent_white(Boolean) => false
|
9
|
+
# compression_method(String) => "none"
|
10
|
+
def self.default_options
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/ruby-batik.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'batik'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
require 'ruby-batik/version'
|
6
|
+
require 'ruby-batik/transcoders/abstract'
|
7
|
+
require 'ruby-batik/transcoders/jpeg'
|
8
|
+
require 'ruby-batik/transcoders/png'
|
9
|
+
require 'ruby-batik/transcoders/tiff'
|
10
|
+
require 'ruby-batik/transcoder'
|
data/ruby-batik.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "ruby-batik/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "ruby-batik"
|
7
|
+
s.version = Batik::VERSION
|
8
|
+
s.authors = ["Kelley Reynolds"]
|
9
|
+
s.email = ["kelley.reynolds@rubyscale.com"]
|
10
|
+
s.homepage = "https://github.com/kreynolds/ruby-batik"
|
11
|
+
s.summary = %q{Wrapper for SVG Transcoding using Apache Batik}
|
12
|
+
s.description = %q{Wrapper for SVG Transcoding using Apache Batik}
|
13
|
+
|
14
|
+
s.rubyforge_project = "ruby-batik"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rspec"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-batik
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kelley Reynolds
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-12-23 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Wrapper for SVG Transcoding using Apache Batik
|
27
|
+
email:
|
28
|
+
- kelley.reynolds@rubyscale.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- .rvmrc
|
38
|
+
- Gemfile
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- lib/ruby-batik.rb
|
42
|
+
- lib/ruby-batik/transcoder.rb
|
43
|
+
- lib/ruby-batik/transcoders/abstract.rb
|
44
|
+
- lib/ruby-batik/transcoders/jpeg.rb
|
45
|
+
- lib/ruby-batik/transcoders/png.rb
|
46
|
+
- lib/ruby-batik/transcoders/tiff.rb
|
47
|
+
- lib/ruby-batik/version.rb
|
48
|
+
- ruby-batik.gemspec
|
49
|
+
homepage: https://github.com/kreynolds/ruby-batik
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
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: "0"
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project: ruby-batik
|
72
|
+
rubygems_version: 1.8.9
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Wrapper for SVG Transcoding using Apache Batik
|
76
|
+
test_files: []
|
77
|
+
|