-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from masood-anwer/master
Aspose.Imaging Java for Ruby - merged
- Loading branch information
Showing
69 changed files
with
1,541 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2001-2015 Aspose Pty Ltd | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Aspose_Imaging_Java_for_Ruby | ||
Aspose.Imaging Java for Ruby is a Ruby gem that demonstrates / provides the Aspose.Imaging for Java API usage examples in Ruby by using Rjb - Ruby Java Bridge. | ||
|
||
## Installation | ||
|
||
Execute following command. | ||
|
||
$ gem install asposeimagingjava | ||
|
||
To download Aspose.Imaging for Java API to be used with these examples through RJB, Please navigate to: | ||
|
||
http://www.aspose.com/community/files/72/java-components/aspose.imaging-for-java/default.aspx | ||
|
||
Note: Create jars folder at root of the gem folder and copy downloaded Aspose.Imaging for java component into it. | ||
|
||
For most complete documentation of the project, check Aspose.OCR Java for Ruby confluence wiki link: | ||
|
||
http://www.aspose.com/docs/display/imagingjava/1.+Aspose.Imaging+Java+For+Ruby | ||
|
||
## Usage | ||
|
||
You can export image to different formats using following example code. | ||
|
||
```ruby | ||
require File.dirname(File.dirname(File.dirname(__FILE__))) + '/lib/asposeimagingjava' | ||
include Asposeimagingjava | ||
include Asposeimagingjava::ExportImageToDifferentFormats | ||
initialize_aspose_imaging | ||
``` | ||
Lets understand the above code | ||
* The first line makes sure that the Aspose.Imaging is loaded and available | ||
* Include the files that are required to access the Aspose.Imaging | ||
* Initialize the libraries. The aspose JAVA classes are loaded from the path provided in the aspose.yml file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "bundler/gem_tasks" | ||
|
27 changes: 27 additions & 0 deletions
27
Plugins/Aspose_Imaging_Java_for_Ruby/asposeimagingjava.gemspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'asposeimagingjava/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'asposeimagingjava' | ||
spec.version = Asposeimagingjava::VERSION | ||
spec.authors = ['Aspose Marketplace'] | ||
spec.email = ['marketplace@aspose.com'] | ||
spec.summary = %q{A Ruby gem to work with Aspose.Imaging for Java libraries} | ||
spec.description = %q{AsposeImagingJava is a Ruby gem that helps developers create, edit, draw or convert images using Aspose.Imaging for Java libraries} | ||
spec.homepage = 'https://github.com/asposeimaging/Aspose_Imaging_Java/tree/master/Plugins/Aspose_Imaging_Java_for_Ruby' | ||
spec.license = 'MIT' | ||
|
||
spec.files = `git ls-files`.split($/) | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_development_dependency 'bundler', '~> 1.7' | ||
spec.add_development_dependency 'rake', '~> 10.0' | ||
spec.add_development_dependency 'rspec' | ||
|
||
spec.add_dependency 'rjb', '~> 1.5.2' | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
jar_dir: ../asposeimagingjava/jars | ||
license_path: ../asposeimagingjava/license/path | ||
jvm_args: -Xms512m -Xmx1G | ||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
71 changes: 71 additions & 0 deletions
71
Plugins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require_relative 'asposeimagingjava/version' | ||
require_relative 'asposeimagingjava/asposeimaging' | ||
require 'logger' | ||
require 'rjb' | ||
|
||
module Asposeimagingjava | ||
|
||
class << self | ||
attr_accessor :aspose_imaging_config | ||
end | ||
|
||
def initialize_aspose_imaging | ||
aspose_jars_dir = Asposeimagingjava.aspose_imaging_config ? Asposeimagingjava.aspose_imaging_config['jar_dir'] : nil | ||
aspose_license_path = Asposeimagingjava.aspose_imaging_config ? Asposeimagingjava.aspose_imaging_config['license_path'] : nil | ||
jvm_args = Asposeimagingjava.aspose_imaging_config ? Asposeimagingjava.aspose_imaging_config['jvm_args'] : nil | ||
|
||
load_aspose_jars(aspose_jars_dir, jvm_args) | ||
load_aspose_license(aspose_license_path) | ||
end | ||
|
||
def load_aspose_license(aspose_license_path) | ||
if aspose_license_path && File.exist?(aspose_license_path) | ||
set_license(File.join(aspose_license_path)) | ||
else | ||
logger = Logger.new(STDOUT) | ||
logger.level = Logger::WARN | ||
logger.warn('Using the non licensed aspose jar. Please specify path to your aspose license directory in config/aspose.yml file!') | ||
end | ||
end | ||
|
||
def load_aspose_jars(aspose_jars_dir, jvm_args) | ||
if aspose_jars_dir && File.exist?(aspose_jars_dir) | ||
jardir = File.join(aspose_jars_dir, '**', '*.jar') | ||
else | ||
jardir = File.join(File.dirname(File.dirname(__FILE__)), 'jars', '**', '*.jar') | ||
end | ||
|
||
if jvm_args | ||
args = jvm_args.split(' ') << '-Djava.awt.headless=true' | ||
logger = Logger.new(STDOUT) | ||
logger.level = Logger::DEBUG | ||
logger.debug("JVM args : #{args}") | ||
Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=args) | ||
else | ||
Rjb::load(classpath = Dir.glob(jardir).join(':'), jvmargs=['-Djava.awt.headless=true']) | ||
end | ||
|
||
end | ||
|
||
def input_file(file) | ||
Rjb::import('java.io.FileInputStream').new(file) | ||
end | ||
|
||
def set_license(aspose_license_file) | ||
begin | ||
fstream = input_file(aspose_license_file) | ||
license = Rjb::import('com.aspose.api.License').new() | ||
license.setLicense(fstream) | ||
rescue Exception => ex | ||
logger = Logger.new(STDOUT) | ||
logger.level = Logger::ERROR | ||
logger.error("Could not load the license file : #{ex}") | ||
fstream.close() if fstream | ||
end | ||
end | ||
|
||
def self.configure_aspose_imaging config | ||
Asposeimagingjava.aspose_imaging_config = config | ||
end | ||
|
||
end |
5 changes: 5 additions & 0 deletions
5
Plugins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava/asposeimaging.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require_relative 'images' | ||
require_relative 'drawing' | ||
require_relative 'metafiles' | ||
require_relative 'psd' | ||
require_relative 'djvu' |
5 changes: 5 additions & 0 deletions
5
Plugins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava/djvu.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require_relative 'djvu/convertingdjvutopdf' | ||
require_relative 'djvu/convertingdjvutotiff' | ||
require_relative 'djvu/convertingrangeofdjvupages' | ||
require_relative 'djvu/convertingrangeofdjvupagestoseparateimages' | ||
require_relative 'djvu/convertingspecificportionofdjvupage' |
29 changes: 29 additions & 0 deletions
29
Plugins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava/djvu/convertingdjvutopdf.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Asposeimagingjava | ||
module ConvertingDjVuToPdf | ||
def initialize() | ||
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/' | ||
|
||
# Load an existing image (of type bmp) in an instance of Image class | ||
image = Rjb::import('com.aspose.imaging.Image').load(data_dir + "demo.djvu") | ||
|
||
# Create an instance of PdfOptions | ||
export_options = Rjb::import('com.aspose.imaging.imageoptions.PdfOptions').new | ||
|
||
# Initialize the metadata for Pdf document | ||
export_options.setPdfDocumentInfo(Rjb::import('com.aspose.imaging.fileformats.pdf.PdfDocumentInfo').new) | ||
|
||
# Create an instance of IntRange and initialize it with the range of DjVu pages to be exported | ||
#range = Rjb::import('com.aspose.imaging.IntRange').new(0, 5) # Export first 5 pages | ||
range = Array[0,1,2,3,4] | ||
|
||
# Initialize an instance of DjvuMultiPageOptions with range of DjVu pages to be exported | ||
export_options.setMultiPageOptions(Rjb::import('com.aspose.imaging.imageoptions.DjvuMultiPageOptions').new(range)) | ||
|
||
# Save the result in PDF format | ||
image.save(data_dir + "djvu.pdf", export_options) | ||
|
||
# Display Status. | ||
puts "Converted DjVu to PDF successfully!" | ||
end | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
Plugins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava/djvu/convertingdjvutotiff.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Asposeimagingjava | ||
module ConvertingDjVuToTiff | ||
def initialize() | ||
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/' | ||
|
||
# Load an existing image (of type bmp) in an instance of Image class | ||
image = Rjb::import('com.aspose.imaging.Image').load(data_dir + "demo.djvu") | ||
|
||
# Create an instance of TiffOptions & use preset options for Black n While with Deflate compression | ||
tiff_expected_format = Rjb::import('com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat') | ||
export_options = Rjb::import('com.aspose.imaging.imageoptions.TiffOptions').new(tiff_expected_format.TiffDeflateBW) | ||
|
||
# Initialize an instance of DjvuMultiPageOptions | ||
export_options.setMultiPageOptions(Rjb::import('com.aspose.imaging.imageoptions.DjvuMultiPageOptions').new) | ||
|
||
# Save the result in PDF format | ||
image.save(data_dir + "djvu.tiff", export_options) | ||
|
||
# Display Status. | ||
puts "Converted DjVu to Tiff successfully!" | ||
end | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
...ins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava/djvu/convertingrangeofdjvupages.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Asposeimagingjava | ||
module ConvertingRangeOfDjVuPages | ||
def initialize() | ||
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/' | ||
|
||
# Load an existing image (of type bmp) in an instance of Image class | ||
image = Rjb::import('com.aspose.imaging.Image').load(data_dir + "demo.djvu") | ||
|
||
# Create an instance of TiffOptions & use preset options for Black n While with Deflate compression | ||
tiff_expected_format = Rjb::import('com.aspose.imaging.fileformats.tiff.enums.TiffExpectedFormat') | ||
export_options = Rjb::import('com.aspose.imaging.imageoptions.TiffOptions').new(tiff_expected_format.TiffDeflateBW) | ||
|
||
# Create an instance of IntRange and initialize it with range of pages to be exported | ||
range = [0, 1] #Export first 2 pages | ||
|
||
# Initialize an instance of DjvuMultiPageOptions | ||
export_options.setMultiPageOptions(Rjb::import('com.aspose.imaging.imageoptions.DjvuMultiPageOptions').new(range)) | ||
|
||
# Save the result in PDF format | ||
image.save(data_dir + "PagesRange.tiff", export_options) | ||
|
||
# Display Status. | ||
puts "Converted range of DjVu pages successfully!" | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
...ng_Java_for_Ruby/lib/asposeimagingjava/djvu/convertingrangeofdjvupagestoseparateimages.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Asposeimagingjava | ||
module ConvertingRangeOfDjVuPagesToSeparateImages | ||
def initialize() | ||
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/' | ||
|
||
# Load an existing image (of type bmp) in an instance of Image class | ||
image = Rjb::import('com.aspose.imaging.Image').load(data_dir + "demo.djvu") | ||
|
||
# Create an instance of BmpOptions | ||
export_options = Rjb::import('com.aspose.imaging.imageoptions.BmpOptions').new | ||
|
||
# Set BitsPerPixel for resultant images | ||
export_options.setBitsPerPixel(32) | ||
|
||
# Create an instance of IntRange and initialize it with range of pages to be exported | ||
range = [0, 1] #Export first 2 pages | ||
|
||
i = 0 | ||
while i < 2 | ||
# Save each page in separate file, as BMP do not support layering | ||
export_options.setMultiPageOptions(Rjb::import('com.aspose.imaging.imageoptions.DjvuMultiPageOptions').new(i)) | ||
image.save(data_dir + "djvupages#{i}.bmp", export_options) | ||
i +=1 | ||
end | ||
|
||
# Display Status. | ||
puts "Converted range of DjVu pages to separate images successfully!" | ||
end | ||
end | ||
end |
32 changes: 32 additions & 0 deletions
32
...e_Imaging_Java_for_Ruby/lib/asposeimagingjava/djvu/convertingspecificportionofdjvupage.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Asposeimagingjava | ||
module ConvertingSpecificPortionOfDjvuPage | ||
def initialize() | ||
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/' | ||
|
||
# Load an existing image (of type bmp) in an instance of Image class | ||
image = Rjb::import('com.aspose.imaging.Image').load(data_dir + "demo.djvu") | ||
|
||
# Create an instance of PngOptions | ||
export_options = Rjb::import('com.aspose.imaging.imageoptions.PngOptions').new | ||
|
||
# Set ColorType to Grayscale | ||
export_options.setColorType(Rjb::import('com.aspose.imaging.fileformats.png.PngColorType').Grayscale) | ||
|
||
# Create an instance of Rectangle and specify the portion on DjVu page | ||
export_area = Rjb::import('com.aspose.imaging.Rectangle').new(20, 20, 500, 500) | ||
|
||
# Specify the DjVu page index | ||
export_page_index = 2 | ||
|
||
# Initialize an instance of DjvuMultiPageOptions | ||
# while passing index of DjVu page index and instance of Rectangle covering the area to be exported | ||
export_options.setMultiPageOptions(Rjb::import('com.aspose.imaging.imageoptions.DjvuMultiPageOptions').new(export_page_index, export_area)) | ||
|
||
# Save the result in PDF format | ||
image.save(data_dir + "SpecificPagePortion.png", export_options) | ||
|
||
# Display Status. | ||
puts "Converted specific page portion DjVu page to image successfully!" | ||
end | ||
end | ||
end |
6 changes: 6 additions & 0 deletions
6
Plugins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava/drawing.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require_relative 'drawing/drawingimagesusingcorefunctionality' | ||
require_relative 'drawing/drawingimagesusinggraphics' | ||
require_relative 'drawing/drawinglines' | ||
require_relative 'drawing/drawingellipse' | ||
require_relative 'drawing/drawingrectangle' | ||
require_relative 'drawing/drawingarc' |
37 changes: 37 additions & 0 deletions
37
Plugins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava/drawing/drawingarc.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Asposeimagingjava | ||
module DrawingArc | ||
def initialize() | ||
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/' | ||
|
||
# Create an instance of BmpOptions and set its various properties | ||
create_options = Rjb::import('com.aspose.imaging.imageoptions.BmpOptions').new | ||
create_options.setBitsPerPixel(32) | ||
|
||
# Define the source property for the instance of BmpOptions | ||
create_options.setSource(Rjb::import('com.aspose.imaging.sources.StreamSource').new(Rjb::import('java.io.ByteArrayInputStream').new(Array.new))) | ||
|
||
# Create an instance of Image | ||
image = Rjb::import('com.aspose.imaging.Image').create(create_options,100,100) | ||
|
||
# Create an instance of Color | ||
color = Rjb::import('com.aspose.imaging.Color') | ||
|
||
# Create an instance of Pen | ||
pen = Rjb::import('com.aspose.imaging.Pen') | ||
|
||
# Create and initialize an instance of Graphics class | ||
graphic = Rjb::import('com.aspose.imaging.Graphics').new(image) | ||
|
||
# Clear the image surface with Yellow color | ||
graphic.clear(color.getYellow()) | ||
|
||
# Draw arc to screen. | ||
graphic.drawArc(pen.new(color.getBlack()), 0, 0, 100, 200, 45, 270) | ||
|
||
# Save all changes. | ||
image.save(data_dir + "DrawArcExample.bmp") | ||
|
||
puts "Arc have been drawn in image successfully!" | ||
end | ||
end | ||
end |
Oops, something went wrong.