imgry 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/imgry/geometry.rb +1 -6
- data/lib/imgry/processor/image_voodoo.rb +21 -68
- data/lib/imgry/processor/img_scalr.rb +20 -52
- data/lib/imgry/processor/java_adapter.rb +90 -0
- data/lib/imgry/processor/mini_magick.rb +63 -19
- data/lib/imgry/processor.rb +24 -13
- data/lib/imgry/version.rb +1 -1
- data/lib/imgry.rb +27 -4
- data/spec/imgry/geometry_spec.rb +10 -7
- data/spec/imgry/imgry_spec.rb +36 -0
- data/spec/imgry/processor/image_voodoo_spec.rb +17 -15
- data/spec/imgry/processor/img_scalr_spec.rb +17 -16
- data/spec/imgry_spec.rb +18 -0
- metadata +26 -23
- data/spec/imgry/processor_spec.rb +0 -26
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A Ruby gem for fast image resizing/cropping designed for JRuby with MRI support.
|
4
4
|
|
5
|
-
Imgry provides an elegant interface and optimizations to third party libraries: Imgscalr, ImageVoodoo and MiniMagick. The library was designed to work as fast as possible under JRuby, and it does, from what we've seen it outperforms any other JRuby image resizing
|
5
|
+
Imgry provides an elegant interface and optimizations to third party libraries: Imgscalr, ImageVoodoo and MiniMagick. The library was designed to work as fast as possible under JRuby, and it does, from what we've seen it outperforms any other JRuby image resizing libraries, if it doesn't, please show us and let's improve it!
|
6
6
|
|
7
7
|
It's also convienient for teams that work between MRI and JRuby, working seamlessly across development/production app environments.
|
8
8
|
|
data/lib/imgry/geometry.rb
CHANGED
@@ -28,12 +28,7 @@ module Imgry
|
|
28
28
|
scale.call
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
# return [nil,nil] if new_width.nil? || new_width.nil?
|
33
|
-
|
34
|
-
# binding.pry
|
35
|
-
|
36
|
-
[new_width, new_height]
|
31
|
+
[new_width || orig_width, new_height || orig_height]
|
37
32
|
end
|
38
33
|
|
39
34
|
def scale_by_width(new_width, aspect_ratio)
|
@@ -1,90 +1,43 @@
|
|
1
1
|
module Imgry
|
2
2
|
module Processor
|
3
3
|
|
4
|
-
class ImageVoodoo <
|
5
|
-
|
6
|
-
def self.load_lib!
|
7
|
-
return if @lib_loaded
|
8
|
-
|
9
|
-
if RUBY_ENGINE != 'jruby'
|
10
|
-
raise 'The ImageVoodoo processor is only available on JRuby.'
|
11
|
-
end
|
12
|
-
|
13
|
-
begin
|
14
|
-
require 'image_voodoo'
|
15
|
-
rescue LoadError
|
16
|
-
raise 'Cannot load image_voodoo gem.'
|
17
|
-
end
|
18
|
-
|
19
|
-
# TODO...
|
20
|
-
# turn on opengl........
|
21
|
-
|
22
|
-
# Add-ons..
|
23
|
-
::ImageVoodoo.class_eval do
|
24
|
-
def src
|
25
|
-
@src
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
@lib_loaded = true
|
30
|
-
end
|
31
|
-
|
32
|
-
#-----
|
33
|
-
|
34
|
-
def load_image_blob!
|
4
|
+
class ImageVoodoo < JavaAdapter
|
5
|
+
def load_image!
|
35
6
|
begin
|
36
|
-
@
|
37
|
-
if @image_ref.src.nil?
|
38
|
-
raise InvalidImageError, "Image is either corrupt or unsupported."
|
39
|
-
end
|
7
|
+
@img = ::ImageVoodoo.new(ImageIO.read(@img_blob))
|
40
8
|
rescue => ex
|
41
9
|
raise InvalidImageError, ex.message
|
42
10
|
end
|
43
11
|
end
|
44
12
|
|
45
|
-
def
|
46
|
-
|
47
|
-
@image_ref = @image_ref.resize(*Geometry.scale(width, height, geometry))
|
48
|
-
end
|
49
|
-
|
50
|
-
def width
|
51
|
-
@image_ref.width
|
13
|
+
def src
|
14
|
+
@img.src
|
52
15
|
end
|
53
16
|
|
54
|
-
def
|
55
|
-
|
17
|
+
def resize!(geometry)
|
18
|
+
return if geometry.nil?
|
19
|
+
@img = @img.resize(*Geometry.scale(width, height, geometry))
|
56
20
|
end
|
57
21
|
|
58
|
-
def
|
59
|
-
# TODO
|
60
|
-
# that it is while coming in, and use that on the way out..
|
61
|
-
# we can use jpg by default..
|
62
|
-
@image_ref.bytes('jpg')
|
22
|
+
def crop!
|
23
|
+
# TODO
|
63
24
|
end
|
64
25
|
|
65
|
-
|
66
|
-
@image_ref
|
67
|
-
end
|
26
|
+
end
|
68
27
|
|
69
|
-
|
70
|
-
|
71
|
-
# [BMP, bmp, jpg, JPG, wbmp, jpeg, png, JPEG, PNG, WBMP, GIF, gif]
|
72
|
-
::ImageVoodoo::ImageIO.getReaderFormatNames.to_a
|
73
|
-
end
|
28
|
+
end
|
29
|
+
end
|
74
30
|
|
75
|
-
|
76
|
-
# Typical formats:
|
77
|
-
# [BMP, bmp, jpg, JPG, wbmp, jpeg, png, JPEG, PNG, WBMP, GIF, gif]
|
78
|
-
::ImageVoodoo::ImageIO.getWriterFormatNames.to_a
|
79
|
-
end
|
31
|
+
#---
|
80
32
|
|
81
|
-
|
82
|
-
|
83
|
-
@src_blob = nil
|
84
|
-
end
|
33
|
+
begin
|
34
|
+
require 'image_voodoo'
|
85
35
|
|
36
|
+
# Add-ons..
|
37
|
+
class ImageVoodoo
|
38
|
+
def src
|
39
|
+
@src
|
86
40
|
end
|
87
|
-
|
88
41
|
end
|
42
|
+
rescue LoadError
|
89
43
|
end
|
90
|
-
|
@@ -1,66 +1,34 @@
|
|
1
1
|
module Imgry
|
2
2
|
module Processor
|
3
3
|
|
4
|
-
class ImgScalr <
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
class ImgScalr < JavaAdapter
|
5
|
+
require 'java/imgscalr-lib-4.2.jar'
|
6
|
+
java_import org.imgscalr.Scalr
|
7
|
+
|
8
|
+
def load_image!
|
9
|
+
begin
|
10
|
+
@img = ImageIO.read(@img_blob)
|
11
|
+
rescue => ex
|
12
|
+
raise InvalidImageError, ex.message
|
11
13
|
end
|
12
|
-
|
13
|
-
self.class_eval do
|
14
|
-
include Java
|
15
|
-
|
16
|
-
require 'java/imgscalr-lib-4.2.jar'
|
17
|
-
|
18
|
-
java_import javax.imageio.ImageIO
|
19
|
-
java_import org.imgscalr.Scalr
|
20
|
-
java_import java.awt.image.BufferedImage
|
21
|
-
java_import java.io.ByteArrayInputStream
|
22
|
-
java_import java.io.ByteArrayOutputStream
|
23
|
-
end
|
24
|
-
|
25
|
-
@lib_loaded = true
|
26
|
-
end
|
27
|
-
|
28
|
-
#-----
|
29
|
-
|
30
|
-
def load_image_blob!
|
31
|
-
@img_blob = @img_blob.to_java_bytes if String === @img_blob
|
32
|
-
|
33
|
-
@image_ref = ImageIO.read(ByteArrayInputStream.new(@img_blob))
|
34
|
-
# TODO .. raise if bullshit... InvalidImageError...
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def resize!(width, height)
|
39
|
-
options = {}
|
40
|
-
method = options[:method] ? options[:method] : Scalr::Method::QUALITY
|
41
|
-
mode = options[:mode] ? options[:mode] : Scalr::Mode::FIT_EXACT
|
42
|
-
ops = options[:ops] ? options[:ops] : Scalr::OP_ANTIALIAS
|
43
|
-
|
44
|
-
@image_ref = Scalr.resize(@image_ref, method, mode, width, height, ops)
|
45
|
-
end
|
46
|
-
|
47
|
-
def width
|
48
|
-
@image_ref.width
|
49
14
|
end
|
50
15
|
|
51
|
-
def
|
52
|
-
@
|
16
|
+
def src
|
17
|
+
@img
|
53
18
|
end
|
54
19
|
|
55
|
-
def
|
56
|
-
|
20
|
+
def resize!(geometry)
|
21
|
+
new_width, new_height = Geometry.scale(width, height, geometry)
|
57
22
|
|
58
|
-
|
59
|
-
|
60
|
-
|
23
|
+
@img = Scalr.resize(@img,
|
24
|
+
Scalr::Method::QUALITY,
|
25
|
+
Scalr::Mode::FIT_EXACT,
|
26
|
+
new_width, new_height,
|
27
|
+
Scalr::OP_ANTIALIAS)
|
61
28
|
end
|
62
29
|
|
63
|
-
def
|
30
|
+
def crop!
|
31
|
+
# TODO
|
64
32
|
end
|
65
33
|
|
66
34
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Imgry
|
2
|
+
module Processor
|
3
|
+
|
4
|
+
class JavaAdapter < Adapter
|
5
|
+
include Java
|
6
|
+
|
7
|
+
java_import javax.imageio.ImageIO
|
8
|
+
java_import java.awt.image.BufferedImage
|
9
|
+
java_import java.io.ByteArrayInputStream
|
10
|
+
java_import java.io.ByteArrayOutputStream
|
11
|
+
|
12
|
+
# Turn on OpenGL .. benchmarks show that with or without
|
13
|
+
# GPU performance is improved
|
14
|
+
java.lang.System.setProperty('sun.java2d.opengl', 'true')
|
15
|
+
|
16
|
+
def self.with_bytes(img_blob, format=nil)
|
17
|
+
bytes = img_blob.to_java_bytes if img_blob.is_a?(String)
|
18
|
+
new(ByteArrayInputStream.new(bytes), format)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.from_file(path, format=nil)
|
22
|
+
if !File.readable?(path)
|
23
|
+
raise FileUnreadableError, path.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
# Use the format based on the file's extension
|
27
|
+
ext = File.extname(path)
|
28
|
+
format = !ext.nil? ? ext[1..-1].downcase : nil
|
29
|
+
|
30
|
+
img_blob = IO.read(path.to_s)
|
31
|
+
with_bytes(img_blob, format)
|
32
|
+
|
33
|
+
# TODO: read the file using Java file io instead..?
|
34
|
+
# input_stream = java.io.FileInputStream.new(java.io.File.new(path.to_s))
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.supported_formats
|
38
|
+
@supported_formats ||= begin
|
39
|
+
# NOTE: assuming read and write formats are the same..
|
40
|
+
# Typical formats: bmp, jpg, wbmp, jpeg, png, gif
|
41
|
+
ImageIO.getReaderFormatNames.to_a.map(&:downcase).uniq
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def width
|
46
|
+
@img.width
|
47
|
+
end
|
48
|
+
|
49
|
+
def height
|
50
|
+
@img.height
|
51
|
+
end
|
52
|
+
|
53
|
+
def clean!
|
54
|
+
@img = nil
|
55
|
+
@img_blob = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_blob(format=nil)
|
59
|
+
format ||= @format || DEFAULT_OUTPUT_FORMAT
|
60
|
+
|
61
|
+
if !self.class.supported_formats.include?(format.downcase)
|
62
|
+
raise UnsupportedFormatError, format
|
63
|
+
end
|
64
|
+
|
65
|
+
out = ByteArrayOutputStream.new
|
66
|
+
ImageIO.write(src, format, out)
|
67
|
+
String.from_java_bytes(out.to_byte_array)
|
68
|
+
end
|
69
|
+
|
70
|
+
def save(path)
|
71
|
+
if !File.writable?(File.dirname(path))
|
72
|
+
raise FileUnwritableError, path.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
ext = File.extname(path)
|
76
|
+
format = !ext.nil? ? ext[1..-1].downcase : nil
|
77
|
+
format ||= DEFAULT_OUTPUT_FORMAT
|
78
|
+
|
79
|
+
if !self.class.supported_formats.include?(format)
|
80
|
+
raise UnsupportedFormatError, format
|
81
|
+
end
|
82
|
+
|
83
|
+
ImageIO.write(src, format.downcase, java.io.File.new(path.to_s))
|
84
|
+
true
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -3,51 +3,67 @@ module Imgry
|
|
3
3
|
|
4
4
|
class MiniMagick < Adapter
|
5
5
|
|
6
|
-
def self.
|
7
|
-
|
6
|
+
def self.with_bytes(img_blob, format=nil)
|
7
|
+
new(img_blob, format)
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
raise "Cannot load mini_magick gem"
|
10
|
+
def self.from_file(path, format=nil)
|
11
|
+
if !File.readable?(path)
|
12
|
+
raise FileUnreadableError, path.to_s
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
::MiniMagick.timeout = 45
|
17
|
-
|
18
|
-
@lib_loaded = true
|
15
|
+
new(IO.read(path), format)
|
19
16
|
end
|
20
17
|
|
21
|
-
|
18
|
+
def self.supported_formats
|
19
|
+
# Hardcoded list of supported formats for validity checking..
|
20
|
+
# Image/GraphicsMagick have a much more extensive list.
|
21
|
+
# Submit an issue if this is a problem.
|
22
|
+
['bmp', 'jpg', 'wbmp', 'jpeg', 'gif', 'png', 'png32', 'png24', 'png8', 'tiff']
|
23
|
+
end
|
22
24
|
|
23
|
-
def
|
25
|
+
def load_image!
|
24
26
|
begin
|
25
|
-
@
|
27
|
+
@img = ::MiniMagick::Image.read(@img_blob)
|
26
28
|
rescue ::MiniMagick::Invalid => ex
|
27
29
|
raise InvalidImageError, ex.message
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
def resize!(geometry)
|
32
|
-
@
|
34
|
+
@img.resize(geometry) if !geometry.nil?
|
33
35
|
nil
|
34
36
|
end
|
35
37
|
|
36
38
|
def width
|
37
|
-
@
|
39
|
+
@img['width']
|
38
40
|
end
|
39
41
|
|
40
42
|
def height
|
41
|
-
@
|
43
|
+
@img['height']
|
44
|
+
end
|
45
|
+
|
46
|
+
def format
|
47
|
+
@img['format']
|
42
48
|
end
|
43
49
|
|
44
50
|
def to_blob
|
45
|
-
@
|
51
|
+
@img.to_blob
|
52
|
+
end
|
53
|
+
|
54
|
+
def save(path)
|
55
|
+
if !File.writable?(File.dirname(path))
|
56
|
+
raise FileUnwritableError, path.to_s
|
57
|
+
end
|
58
|
+
if !self.class.supported_formats.include?(format.downcase)
|
59
|
+
raise UnsupportedFormatError, format
|
60
|
+
end
|
61
|
+
@img.write(path.to_s)
|
46
62
|
end
|
47
63
|
|
48
64
|
def clean!
|
49
|
-
@
|
50
|
-
@
|
65
|
+
@img.destroy!
|
66
|
+
@img = nil
|
51
67
|
@img_blob = nil
|
52
68
|
end
|
53
69
|
|
@@ -55,3 +71,31 @@ module Imgry
|
|
55
71
|
|
56
72
|
end
|
57
73
|
end
|
74
|
+
|
75
|
+
#---
|
76
|
+
|
77
|
+
begin
|
78
|
+
require 'mini_magick'
|
79
|
+
|
80
|
+
MiniMagick.processor = :gm
|
81
|
+
MiniMagick.timeout = 45
|
82
|
+
|
83
|
+
# Fix.. this is in mini_magick's github master,
|
84
|
+
# but not in the stable released gem
|
85
|
+
class MiniMagick::Image
|
86
|
+
def run_command(command, *args)
|
87
|
+
# -ping "efficiently determine image characteristics."
|
88
|
+
if command == 'identify'
|
89
|
+
args.unshift '-ping'
|
90
|
+
|
91
|
+
# GraphicsMagick's identify has no -quiet option
|
92
|
+
if MiniMagick.processor.to_s == 'gm'
|
93
|
+
args.delete('-quiet')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
run(MiniMagick::CommandBuilder.new(command, *args))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
rescue LoadError
|
101
|
+
end
|
data/lib/imgry/processor.rb
CHANGED
@@ -2,25 +2,28 @@ module Imgry
|
|
2
2
|
module Processor
|
3
3
|
|
4
4
|
class Adapter
|
5
|
+
DEFAULT_OUTPUT_FORMAT = 'jpg'
|
5
6
|
|
6
|
-
def self.
|
7
|
-
new(img_blob, format)
|
7
|
+
def self.load_lib!
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.
|
11
|
-
#
|
10
|
+
def self.with_bytes(img_bytes, format=nil)
|
11
|
+
# Abstract
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.
|
15
|
-
|
14
|
+
def self.from_file(path, format=nil)
|
15
|
+
# Abstract
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize(img_blob, format=nil)
|
19
|
-
self.class.load_lib! if !self.class.lib_loaded?
|
20
|
-
|
21
19
|
@img_blob = img_blob
|
22
20
|
@format = format
|
23
|
-
|
21
|
+
@img = nil
|
22
|
+
load_image!
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_image!
|
26
|
+
# Abstract
|
24
27
|
end
|
25
28
|
|
26
29
|
def aspect_ratio
|
@@ -31,13 +34,21 @@ module Imgry
|
|
31
34
|
|
32
35
|
end
|
33
36
|
|
34
|
-
class InvalidImageError < StandardError; end
|
35
|
-
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
40
|
+
#---
|
41
|
+
|
42
|
+
# JRuby processors
|
43
|
+
if RUBY_ENGINE == 'jruby'
|
44
|
+
%w(
|
45
|
+
java_adapter
|
46
|
+
image_voodoo
|
47
|
+
img_scalr
|
48
|
+
).each {|lib| require "imgry/processor/#{lib}" }
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generic processors
|
39
52
|
%w(
|
40
|
-
image_voodoo
|
41
|
-
img_scalr
|
42
53
|
mini_magick
|
43
54
|
).each {|lib| require "imgry/processor/#{lib}" }
|
data/lib/imgry/version.rb
CHANGED
data/lib/imgry.rb
CHANGED
@@ -1,24 +1,47 @@
|
|
1
1
|
module Imgry
|
2
2
|
extend self
|
3
3
|
|
4
|
+
attr_accessor :processor
|
5
|
+
|
4
6
|
def with_bytes(img_blob, format=nil)
|
7
|
+
processor_klass.with_bytes(img_blob, format)
|
5
8
|
end
|
6
9
|
|
7
10
|
def from_file(img_blob, format=nil)
|
11
|
+
processor_klass.from_file(img_blob, format)
|
8
12
|
end
|
9
13
|
|
10
|
-
def
|
11
|
-
|
14
|
+
def processor_klass
|
15
|
+
@processor_klass ||= begin
|
16
|
+
k = processor.to_s.split('_').map {|x| x.capitalize }.join('')
|
17
|
+
begin
|
18
|
+
instance_eval("Imgry::Processor::#{k}")
|
19
|
+
rescue
|
20
|
+
raise "Unknown processor #{processor}"
|
21
|
+
end
|
22
|
+
end
|
12
23
|
end
|
13
24
|
|
14
|
-
def
|
15
|
-
@
|
25
|
+
def processor=(processor)
|
26
|
+
@processor_klass = nil
|
27
|
+
@processor = processor
|
16
28
|
end
|
17
29
|
|
30
|
+
|
31
|
+
class InvalidImageError < StandardError; end
|
32
|
+
class UnsupportedFormatError < StandardError; end
|
33
|
+
class FileUnreadableError < StandardError; end
|
34
|
+
class FileUnwritableError < StandardError; end
|
18
35
|
end
|
19
36
|
|
20
37
|
Imagery = Imgry
|
21
38
|
|
39
|
+
if RUBY_ENGINE == 'jruby'
|
40
|
+
Imgry.processor = :img_scalr
|
41
|
+
else
|
42
|
+
Imgry.processor = :mini_magick
|
43
|
+
end
|
44
|
+
|
22
45
|
require 'imgry/version'
|
23
46
|
require 'imgry/geometry'
|
24
47
|
require 'imgry/processor'
|
data/spec/imgry/geometry_spec.rb
CHANGED
@@ -19,15 +19,18 @@ describe Imgry::Geometry do
|
|
19
19
|
|
20
20
|
it 'shrinks to a size when dimensions are larger then corresponding width/height' do
|
21
21
|
size = Imgry::Geometry.scale(1024, 768, "600x600>")
|
22
|
-
|
23
|
-
binding.pry
|
22
|
+
size.should == [600, 450]
|
24
23
|
|
25
|
-
|
24
|
+
size = Imgry::Geometry.scale(300, 400, "600x600>")
|
25
|
+
size.should == [300, 400]
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
it 'enlarges to a size when dimensions are smaller then corresponding width/height' do
|
29
|
+
size = Imgry::Geometry.scale(1024, 768, "600x600<")
|
30
|
+
size.should == [1024, 768]
|
31
|
+
|
32
|
+
size = Imgry::Geometry.scale(300, 400, "600x600<")
|
33
|
+
size.should == [600, 800]
|
34
|
+
end
|
32
35
|
|
33
36
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Imgry do
|
4
|
+
|
5
|
+
let (:img_data) { IO.read(SPEC_ROOT.join('support/335is.jpg')) }
|
6
|
+
|
7
|
+
context "a pretty picture" do
|
8
|
+
|
9
|
+
it "resizes an image from memory through high level interface" do
|
10
|
+
img = Imgry.with_bytes(img_data)
|
11
|
+
|
12
|
+
img.resize!("300x")
|
13
|
+
img.width.should == 300
|
14
|
+
end
|
15
|
+
|
16
|
+
it "loads from a file and resizes an image" do
|
17
|
+
img = Imgry.from_file(SPEC_ROOT.join('support/335is.png'))
|
18
|
+
img.resize!("400x")
|
19
|
+
img.width.should == 400
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises error if file is bogus" do
|
23
|
+
expect { Imgry.from_file('hi') }.to raise_error(Imgry::FileUnreadableError)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "writes to a file" do
|
27
|
+
img = Imgry.with_bytes(img_data)
|
28
|
+
tmpfile = Dir.tmpdir+'/imgry.jpg'
|
29
|
+
img.save(tmpfile)
|
30
|
+
File.exists?(tmpfile).should == true
|
31
|
+
File.unlink(tmpfile)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -1,26 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
if RUBY_ENGINE == 'jruby'
|
4
|
+
describe Imgry::Processor::ImageVoodoo do
|
4
5
|
|
5
|
-
|
6
|
+
let (:img_data) { IO.read(SPEC_ROOT.join('support/335is.jpg')) }
|
6
7
|
|
7
|
-
|
8
|
+
context "a pretty picture" do
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
it "basic loading and resizing of an image" do
|
11
|
+
img = Imgry::Processor::ImageVoodoo.with_bytes(img_data)
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
img.width.should == 1024
|
14
|
+
img.height.should == 764
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
img.resize!("512x")
|
17
|
+
img.width.should == 512
|
18
|
+
img.height.should == 382
|
19
|
+
|
20
|
+
new_img_blob = img.to_blob
|
21
|
+
new_img_blob.length.should < img_data.length
|
22
|
+
new_img_blob.length.should == 32159
|
23
|
+
end
|
18
24
|
|
19
|
-
new_img_blob = img.to_blob
|
20
|
-
new_img_blob.length.should < img_data.length
|
21
|
-
new_img_blob.length.should == 32159
|
22
25
|
end
|
23
26
|
|
24
27
|
end
|
25
|
-
|
26
|
-
end
|
28
|
+
end
|
@@ -1,27 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
if RUBY_ENGINE == 'jruby'
|
4
|
+
describe Imgry::Processor::ImgScalr do
|
4
5
|
|
5
|
-
|
6
|
+
let (:img_data) { IO.read(SPEC_ROOT.join('support/335is.jpg')) }
|
6
7
|
|
7
|
-
|
8
|
+
context "a pretty picture" do
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
it "basic loading and resizing of an image" do
|
11
|
+
img = Imgry::Processor::ImgScalr.with_bytes(img_data)
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
img.width.should == 1024
|
14
|
+
img.height.should == 764
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
img.resize!("512x")
|
17
|
+
img.width.should == 512
|
18
|
+
img.height.should == 382
|
19
|
+
|
20
|
+
new_img_blob = img.to_blob
|
21
|
+
new_img_blob.length.should < img_data.length
|
22
|
+
new_img_blob.length.should == 30319
|
23
|
+
end
|
19
24
|
|
20
|
-
new_img_blob = img.to_blob
|
21
|
-
new_img_blob.length.should < img_data.length
|
22
|
-
new_img_blob.length.should == 30319
|
23
25
|
end
|
24
26
|
|
25
27
|
end
|
26
|
-
|
27
|
-
end
|
28
|
+
end
|
data/spec/imgry_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Imgry do
|
4
|
+
|
5
|
+
let (:img_data) { IO.read(SPEC_ROOT.join('support/335is.jpg')) }
|
6
|
+
|
7
|
+
context "a pretty picture" do
|
8
|
+
|
9
|
+
it "should do stuff..." do
|
10
|
+
img = Imgry.with_bytes(img_data)
|
11
|
+
|
12
|
+
img.resize!("300x")
|
13
|
+
img.width.should == 300
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Pressly
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
|
17
|
-
none: false
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
18
|
- - ~>
|
20
19
|
- !ruby/object:Gem::Version
|
21
20
|
version: '2.12'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
21
|
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '2.12'
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :development
|
30
30
|
description: Fast image resizing/cropping designed for JRuby with MRI support
|
31
31
|
email:
|
32
32
|
- info@pressly.com
|
@@ -34,56 +34,59 @@ executables: []
|
|
34
34
|
extensions: []
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
|
+
- lib/imgry.rb
|
37
38
|
- lib/imgry/geometry.rb
|
39
|
+
- lib/imgry/processor.rb
|
40
|
+
- lib/imgry/version.rb
|
38
41
|
- lib/imgry/processor/image_voodoo.rb
|
39
42
|
- lib/imgry/processor/img_scalr.rb
|
43
|
+
- lib/imgry/processor/java_adapter.rb
|
40
44
|
- lib/imgry/processor/mini_magick.rb
|
41
|
-
- lib/imgry/processor.rb
|
42
|
-
- lib/imgry/version.rb
|
43
|
-
- lib/imgry.rb
|
44
45
|
- lib/java/imgscalr-lib-4.2.jar
|
45
46
|
- README.md
|
47
|
+
- spec/imgry_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
46
49
|
- spec/imgry/geometry_spec.rb
|
50
|
+
- spec/imgry/imgry_spec.rb
|
47
51
|
- spec/imgry/processor/image_voodoo_spec.rb
|
48
52
|
- spec/imgry/processor/img_scalr_spec.rb
|
49
53
|
- spec/imgry/processor/mini_magick_spec.rb
|
50
|
-
- spec/imgry/processor_spec.rb
|
51
|
-
- spec/spec_helper.rb
|
52
54
|
- spec/support/335is.gif
|
53
55
|
- spec/support/335is.jpg
|
54
56
|
- spec/support/335is.png
|
55
57
|
homepage: http://github.com/nulayer/imgry
|
56
58
|
licenses: []
|
57
|
-
post_install_message:
|
59
|
+
post_install_message:
|
58
60
|
rdoc_options: []
|
59
61
|
require_paths:
|
60
62
|
- lib
|
61
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
none: false
|
63
64
|
requirements:
|
64
65
|
- - ! '>='
|
65
66
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
67
|
-
|
67
|
+
version: !binary |-
|
68
|
+
MA==
|
68
69
|
none: false
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
71
|
requirements:
|
70
72
|
- - ! '>='
|
71
73
|
- !ruby/object:Gem::Version
|
72
74
|
version: 1.3.6
|
75
|
+
none: false
|
73
76
|
requirements: []
|
74
|
-
rubyforge_project:
|
77
|
+
rubyforge_project:
|
75
78
|
rubygems_version: 1.8.24
|
76
|
-
signing_key:
|
79
|
+
signing_key:
|
77
80
|
specification_version: 3
|
78
81
|
summary: Fast image resizing/cropping designed for JRuby with MRI support
|
79
82
|
test_files:
|
83
|
+
- spec/imgry_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
80
85
|
- spec/imgry/geometry_spec.rb
|
86
|
+
- spec/imgry/imgry_spec.rb
|
81
87
|
- spec/imgry/processor/image_voodoo_spec.rb
|
82
88
|
- spec/imgry/processor/img_scalr_spec.rb
|
83
89
|
- spec/imgry/processor/mini_magick_spec.rb
|
84
|
-
- spec/imgry/processor_spec.rb
|
85
|
-
- spec/spec_helper.rb
|
86
90
|
- spec/support/335is.gif
|
87
91
|
- spec/support/335is.jpg
|
88
92
|
- spec/support/335is.png
|
89
|
-
has_rdoc:
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Imgry::Processor do
|
4
|
-
|
5
|
-
let (:img_data) { IO.read(SPEC_ROOT.join('support/335is.jpg')) }
|
6
|
-
|
7
|
-
context "a pretty picture" do
|
8
|
-
|
9
|
-
it "should do stuff..." do
|
10
|
-
# This will use the best processor for the VM .. etc.
|
11
|
-
# .. what about the format...?
|
12
|
-
img = Imgry.with_bytes(img_data)
|
13
|
-
|
14
|
-
# img.class # .. this will be ImageTools::Processor::MiniMagick or ::ImgScalr etc.
|
15
|
-
|
16
|
-
# img.resize!("300x200!")
|
17
|
-
|
18
|
-
# img = ImageTools.from_file(SPEC_ROOT.join('support/335is.jpg'))
|
19
|
-
|
20
|
-
binding.pry
|
21
|
-
x = 1
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|