ruby-epeg 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/ext/epeg/epeg_image.c +42 -18
- data/ext/epeg/epeg_image.h +1 -0
- data/lib/epeg/version.rb +1 -1
- data/{epeg.gemspec → ruby-epeg.gemspec} +1 -1
- data/spec/epeg_image_spec.rb +26 -19
- data/spec/fixtures/einstein.jpg +0 -0
- data/spec/spec_helper.rb +1 -1
- metadata +6 -6
- data/spec/fixtures/test.jpg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
data.tar.gz:
|
4
|
-
metadata.gz:
|
3
|
+
data.tar.gz: 4a4adfdee32d2e98f4e0295ef9996e6a0f832783
|
4
|
+
metadata.gz: 82a4dc0962796b79cb6dada7dab7f574943f5b0a
|
5
5
|
SHA512:
|
6
|
-
data.tar.gz:
|
7
|
-
metadata.gz:
|
6
|
+
data.tar.gz: 2ac71eb95371a8325a679fdb7f703a46828ea236993295c917044d1f77584d0288846fe8e82609cc198b2b0cce4ffe6880f2546168fa572e5581936d7bce3912
|
7
|
+
metadata.gz: 143ec94beb4ddd840fb1bd23d692db4e24dcdd3455a42053ff5cf04cfab0c7a0f89432a3d1f1cda803d4325130832fc43c149d7c11381b9fd8bdb43b89d2539b
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Ruby extension for the epeg library which provides facilities for scaling JPEG i
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem 'ruby-epeg'
|
10
|
+
gem 'ruby-epeg', :require => 'epeg'
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -34,9 +34,7 @@ image = Epeg::Image.open("./some-image.jpg")
|
|
34
34
|
# => some-image.jpeg is 1000x500
|
35
35
|
|
36
36
|
# Resize the image to 50x50, set the quality to 50 and save it
|
37
|
-
image.resize(50,50)
|
38
|
-
image.quality = 50
|
39
|
-
image.write("./some-other-image.jpg")
|
37
|
+
image.resize(50,50).quality(50).write("./some-other-image.jpg")
|
40
38
|
|
41
39
|
# The image is now closed and you can't do any further operations
|
42
40
|
image.closed? # => true
|
data/ext/epeg/epeg_image.c
CHANGED
@@ -14,20 +14,19 @@ void Init_epeg()
|
|
14
14
|
|
15
15
|
rb_define_method(cEpegImage, "initialize", rb_epeg_image_initialize, 0);
|
16
16
|
|
17
|
-
rb_define_method(cEpegImage, "resize", rb_epeg_image_resize,
|
18
|
-
rb_define_method(cEpegImage, "resize_to_fit", rb_epeg_image_resize_to_fit,
|
19
|
-
rb_define_method(cEpegImage, "resize_to_fill", rb_epeg_image_resize_to_fill,
|
20
|
-
rb_define_method(cEpegImage, "crop", rb_epeg_image_crop,
|
21
|
-
rb_define_method(cEpegImage, "write", rb_epeg_image_write,
|
22
|
-
rb_define_method(cEpegImage, "to_blob", rb_epeg_image_to_blob,
|
23
|
-
rb_define_method(cEpegImage, "close", rb_epeg_image_close,
|
24
|
-
rb_define_method(cEpegImage, "closed?", rb_epeg_image_is_closed,
|
25
|
-
rb_define_method(cEpegImage, "quality
|
17
|
+
rb_define_method(cEpegImage, "resize", rb_epeg_image_resize, 2);
|
18
|
+
rb_define_method(cEpegImage, "resize_to_fit", rb_epeg_image_resize_to_fit, 2);
|
19
|
+
rb_define_method(cEpegImage, "resize_to_fill", rb_epeg_image_resize_to_fill, 2);
|
20
|
+
rb_define_method(cEpegImage, "crop", rb_epeg_image_crop, -1);
|
21
|
+
rb_define_method(cEpegImage, "write", rb_epeg_image_write, 1);
|
22
|
+
rb_define_method(cEpegImage, "to_blob", rb_epeg_image_to_blob, 0);
|
23
|
+
rb_define_method(cEpegImage, "close", rb_epeg_image_close, 0);
|
24
|
+
rb_define_method(cEpegImage, "closed?", rb_epeg_image_is_closed, 0);
|
25
|
+
rb_define_method(cEpegImage, "quality", rb_epeg_image_get_or_set_quality, -1);
|
26
|
+
rb_define_method(cEpegImage, "quality=", rb_epeg_image_set_quality, 1);
|
26
27
|
|
27
28
|
rb_define_attr(cEpegImage, "width", 1, 0);
|
28
29
|
rb_define_attr(cEpegImage, "height", 1, 0);
|
29
|
-
rb_define_attr(cEpegImage, "quality", 1, 0);
|
30
|
-
rb_define_attr(cEpegImage, "file_path", 1, 0);
|
31
30
|
}
|
32
31
|
|
33
32
|
/*
|
@@ -116,6 +115,9 @@ static VALUE rb_epeg_image_initialize(VALUE self)
|
|
116
115
|
epeg_quality_set(image, NUM2UINT(q));
|
117
116
|
rb_iv_set(self, "@quality", q);
|
118
117
|
|
118
|
+
char *comment;
|
119
|
+
epeg_comment_set(image, (char *)NULL);
|
120
|
+
|
119
121
|
unsigned int w, h;
|
120
122
|
epeg_size_get(image, &w, &h);
|
121
123
|
|
@@ -168,7 +170,7 @@ static VALUE rb_epeg_image_resize_to_fit(VALUE self, VALUE w, VALUE h)
|
|
168
170
|
const double image_height = (double)NUM2INT(rb_iv_get(self, "@height"));
|
169
171
|
|
170
172
|
const double fit_width = (double)NUM2INT(w);
|
171
|
-
const double fit_height = (double)NUM2INT(
|
173
|
+
const double fit_height = (double)NUM2INT(h);
|
172
174
|
|
173
175
|
const double width_ratio = image_width/fit_width;
|
174
176
|
const double height_ratio = image_height/fit_height;
|
@@ -181,9 +183,9 @@ static VALUE rb_epeg_image_resize_to_fit(VALUE self, VALUE w, VALUE h)
|
|
181
183
|
} else {
|
182
184
|
if(width_ratio > height_ratio) {
|
183
185
|
width = fit_width;
|
184
|
-
height = (
|
186
|
+
height = fit_width*(image_height/image_width);
|
185
187
|
} else {
|
186
|
-
width = (
|
188
|
+
width = fit_height*(image_width/image_height);
|
187
189
|
height = fit_height;
|
188
190
|
}
|
189
191
|
}
|
@@ -208,7 +210,7 @@ static VALUE rb_epeg_image_resize_to_fill(VALUE self, VALUE w, VALUE h)
|
|
208
210
|
const double image_height = (double)NUM2INT(rb_iv_get(self, "@height"));
|
209
211
|
|
210
212
|
const double fit_width = (double)NUM2INT(w);
|
211
|
-
const double fit_height = (double)NUM2INT(
|
213
|
+
const double fit_height = (double)NUM2INT(h);
|
212
214
|
|
213
215
|
const double width_ratio = image_width/fit_width;
|
214
216
|
const double height_ratio = image_height/fit_height;
|
@@ -220,11 +222,11 @@ static VALUE rb_epeg_image_resize_to_fill(VALUE self, VALUE w, VALUE h)
|
|
220
222
|
height = fit_width;
|
221
223
|
} else {
|
222
224
|
if(width_ratio > height_ratio) {
|
223
|
-
width =
|
225
|
+
width = fit_height*(image_width/image_height);
|
224
226
|
height = fit_height;
|
225
227
|
} else {
|
226
228
|
width = fit_width;
|
227
|
-
height =
|
229
|
+
height = fit_width*(image_height/image_width);
|
228
230
|
}
|
229
231
|
}
|
230
232
|
|
@@ -350,12 +352,34 @@ static VALUE rb_epeg_image_to_blob(VALUE self)
|
|
350
352
|
return blob;
|
351
353
|
}
|
352
354
|
|
355
|
+
/*
|
356
|
+
* call-seq:
|
357
|
+
* quality((q))
|
358
|
+
*
|
359
|
+
* Returns the image quality or sets it if +q+ is given.
|
360
|
+
* See Epeg::Image#quality=
|
361
|
+
*/
|
362
|
+
static VALUE rb_epeg_image_get_or_set_quality(int argc, VALUE *argv, VALUE self)
|
363
|
+
{
|
364
|
+
if(argc > 1) {
|
365
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
366
|
+
}
|
367
|
+
|
368
|
+
if(argc == 0) { return rb_iv_get(self, "@quality"); }
|
369
|
+
|
370
|
+
if(argc == 1) {
|
371
|
+
rb_epeg_image_set_quality(self, argv[0]);
|
372
|
+
return self;
|
373
|
+
}
|
374
|
+
|
375
|
+
}
|
376
|
+
|
353
377
|
/*
|
354
378
|
* call-seq:
|
355
379
|
* quality=(q)
|
356
380
|
*
|
357
381
|
* Sets the quality of the image to +q+ (+q+ >= 0 and +q+ <= 100).
|
358
|
-
* See Epeg::Image
|
382
|
+
* See Epeg::Image#quality
|
359
383
|
*/
|
360
384
|
static VALUE rb_epeg_image_set_quality(VALUE self, VALUE q)
|
361
385
|
{
|
data/ext/epeg/epeg_image.h
CHANGED
@@ -14,6 +14,7 @@ static VALUE rb_epeg_image_resize(VALUE, VALUE, VALUE);
|
|
14
14
|
static VALUE rb_epeg_image_resize_to_fit(VALUE, VALUE, VALUE);
|
15
15
|
static VALUE rb_epeg_image_resize_to_fill(VALUE, VALUE, VALUE);
|
16
16
|
static VALUE rb_epeg_image_crop(int, VALUE *, VALUE);
|
17
|
+
static VALUE rb_epeg_image_get_or_set_quality(int, VALUE *, VALUE);
|
17
18
|
static VALUE rb_epeg_image_set_quality(VALUE, VALUE);
|
18
19
|
|
19
20
|
static VALUE rb_epeg_image_write(VALUE, VALUE);
|
data/lib/epeg/version.rb
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
spec.extensions = ["ext/epeg/extconf.rb"]
|
20
20
|
|
21
|
-
spec.
|
21
|
+
spec.add_development_dependency "rake-compiler", "~> 0.9"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/spec/epeg_image_spec.rb
CHANGED
@@ -22,8 +22,8 @@ describe Epeg::Image do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should have well-defined width and height" do
|
25
|
-
expect(@image.width ).to eq(
|
26
|
-
expect(@image.height).to eq(
|
25
|
+
expect(@image.width ).to eq(615)
|
26
|
+
expect(@image.height).to eq(768)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should create new image from blob" do
|
@@ -37,57 +37,57 @@ describe Epeg::Image do
|
|
37
37
|
File.open(@output_image.path, "wb"){ |f| f.write(blob) }
|
38
38
|
@image_from_blob = Epeg::Image.open(@output_image.path)
|
39
39
|
|
40
|
-
expect(@image_from_blob.width ).to
|
41
|
-
expect(@image_from_blob.height).to
|
40
|
+
expect(@image_from_blob.width ).to be_kind_of(Fixnum)
|
41
|
+
expect(@image_from_blob.height).to be_kind_of(Fixnum)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should resize an image" do
|
45
|
-
@image.resize(
|
45
|
+
@image.resize(200, 200)
|
46
46
|
@image.write(@output_image.path)
|
47
47
|
|
48
48
|
@resized_image = Epeg::Image.open(@output_image.path)
|
49
49
|
|
50
|
-
expect(@resized_image.width ).to eq(
|
51
|
-
expect(@resized_image.height).to eq(
|
50
|
+
expect(@resized_image.width ).to eq(200)
|
51
|
+
expect(@resized_image.height).to eq(200)
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should resize an image to fit specific dimensions" do
|
55
|
-
@image.resize_to_fit(
|
55
|
+
@image.resize_to_fit(300,200)
|
56
56
|
@image.write(@output_image.path)
|
57
57
|
|
58
58
|
@resized_image = Epeg::Image.open(@output_image.path)
|
59
59
|
|
60
|
-
expect(@resized_image.width ).to eq(
|
61
|
-
expect(@resized_image.height).to eq(
|
60
|
+
expect(@resized_image.width ).to eq(161)
|
61
|
+
expect(@resized_image.height).to eq(200)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should resize an image to fill specific dimensions" do
|
65
|
-
@image.resize_to_fill(
|
65
|
+
@image.resize_to_fill(300,200)
|
66
66
|
@image.write(@output_image.path)
|
67
67
|
|
68
68
|
@resized_image = Epeg::Image.open(@output_image.path)
|
69
69
|
|
70
|
-
expect(@resized_image.width ).to eq(
|
71
|
-
expect(@resized_image.height).to eq(
|
70
|
+
expect(@resized_image.width ).to eq(300)
|
71
|
+
expect(@resized_image.height).to eq(375)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should crop an image" do
|
75
|
-
@image.crop(
|
75
|
+
@image.crop(100, 100, 0, 0)
|
76
76
|
@image.write(@output_image.path)
|
77
77
|
|
78
78
|
@another_image = Epeg::Image.open(TEST_JPEG)
|
79
|
-
@another_image.crop(
|
79
|
+
@another_image.crop(100, 100)
|
80
80
|
@another_output_image = Tempfile.new(%w{out2 .jpg})
|
81
81
|
@another_image.write(@another_output_image.path)
|
82
82
|
|
83
83
|
@cropped_image = Epeg::Image.open(@output_image.path)
|
84
84
|
@another_cropped_image = Epeg::Image.open(@another_output_image.path)
|
85
85
|
|
86
|
-
expect(@cropped_image.width ).to eq(
|
87
|
-
expect(@cropped_image.height).to eq(
|
86
|
+
expect(@cropped_image.width ).to eq(100)
|
87
|
+
expect(@cropped_image.height).to eq(100)
|
88
88
|
|
89
|
-
expect(@another_cropped_image.width ).to eq(
|
90
|
-
expect(@another_cropped_image.height).to eq(
|
89
|
+
expect(@another_cropped_image.width ).to eq(100)
|
90
|
+
expect(@another_cropped_image.height).to eq(100)
|
91
91
|
|
92
92
|
expect(@cropped_image.to_blob).not_to eq(@another_cropped_image.to_blob)
|
93
93
|
end
|
@@ -104,6 +104,13 @@ describe Epeg::Image do
|
|
104
104
|
expect(@image.quality).to eq(75)
|
105
105
|
end
|
106
106
|
|
107
|
+
it "should set quality using chainable method" do
|
108
|
+
image = @image.quality(50)
|
109
|
+
|
110
|
+
expect(@image.quality).to eq(50)
|
111
|
+
expect(image).to be_kind_of(Epeg::Image)
|
112
|
+
end
|
113
|
+
|
107
114
|
it "should set valid quality" do
|
108
115
|
@image.quality = 100
|
109
116
|
@image.write(@output_image.path)
|
Binary file
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-epeg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nelson Darkwah Oppong
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-14 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake-compiler
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: "0.9"
|
22
|
-
type: :
|
22
|
+
type: :development
|
23
23
|
version_requirements: *id001
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
name: bundler
|
@@ -67,7 +67,6 @@ files:
|
|
67
67
|
- LICENSE.txt
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
|
-
- epeg.gemspec
|
71
70
|
- ext/epeg/EPEG_LICENSE
|
72
71
|
- ext/epeg/Epeg.h
|
73
72
|
- ext/epeg/epeg_image.c
|
@@ -77,8 +76,9 @@ files:
|
|
77
76
|
- ext/epeg/extconf.rb
|
78
77
|
- lib/epeg/epeg.rb
|
79
78
|
- lib/epeg/version.rb
|
79
|
+
- ruby-epeg.gemspec
|
80
80
|
- spec/epeg_image_spec.rb
|
81
|
-
- spec/fixtures/
|
81
|
+
- spec/fixtures/einstein.jpg
|
82
82
|
- spec/spec_helper.rb
|
83
83
|
homepage: http://github.com/nelsond/ruby-epeg
|
84
84
|
licenses:
|
@@ -108,6 +108,6 @@ specification_version: 4
|
|
108
108
|
summary: Ruby extension for the epeg library which provides facilities for scaling JPEG images very quickly.
|
109
109
|
test_files:
|
110
110
|
- spec/epeg_image_spec.rb
|
111
|
-
- spec/fixtures/
|
111
|
+
- spec/fixtures/einstein.jpg
|
112
112
|
- spec/spec_helper.rb
|
113
113
|
has_rdoc:
|
data/spec/fixtures/test.jpg
DELETED
Binary file
|