ruby-epeg 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA1:
3
- data.tar.gz: 4a4adfdee32d2e98f4e0295ef9996e6a0f832783
4
- metadata.gz: 82a4dc0962796b79cb6dada7dab7f574943f5b0a
5
- SHA512:
6
- data.tar.gz: 2ac71eb95371a8325a679fdb7f703a46828ea236993295c917044d1f77584d0288846fe8e82609cc198b2b0cce4ffe6880f2546168fa572e5581936d7bce3912
7
- metadata.gz: 143ec94beb4ddd840fb1bd23d692db4e24dcdd3455a42053ff5cf04cfab0c7a0f89432a3d1f1cda803d4325130832fc43c149d7c11381b9fd8bdb43b89d2539b
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54cb66dfeb952a5db8b4b33c81f7287adf226e30
4
+ data.tar.gz: 4ff7b023ff043d833d4c2de2364d5102ef4da2fa
5
+ SHA512:
6
+ metadata.gz: 9101a5de68dc589f6b5cced9f842e45a3e06d8b8800704c60113da15b204de53836fcd9f2dd3fef3aa48a7e6ccb7308742f68957a08ca3ae5e87891f3cdcde13
7
+ data.tar.gz: 0fc99ecec595dff2dbc5be253794856827ae3cc5fcbbb9b0fa774860ac0e61ecbe16523717bd218091fa3c36f0d6948b8b12f3c988ce5779938a94f9789bb815
data/README.md CHANGED
@@ -23,8 +23,9 @@ Or install it yourself as:
23
23
  ```ruby
24
24
  require "epeg"
25
25
 
26
- # Set the global default jpeg quality
27
- Epeg::Image.quality = 90 # default is 85
26
+ # Get and set the global default jpeg quality
27
+ Epeg::Image.default_quality # => 85
28
+ Epeg::Image.default_quality = 90
28
29
 
29
30
  # Create an image object from the file some-image.jpg
30
31
  image = Epeg::Image.open("./some-image.jpg")
data/Rakefile CHANGED
@@ -9,3 +9,7 @@ task :test => :spec
9
9
 
10
10
  require "rake/extensiontask"
11
11
  Rake::ExtensionTask.new("epeg")
12
+
13
+ task :valgrind => [:compile] do
14
+ system("valgrind --leak-check=yes ruby #{ROOT}/spec/runner.rb")
15
+ end
@@ -7,10 +7,10 @@ void Init_epeg()
7
7
 
8
8
  rb_cv_set(cEpegImage, "@@quality", INT2NUM(85));
9
9
 
10
- rb_define_singleton_method(cEpegImage, "from_blob", rb_epeg_image_from_blob, 1);
11
- rb_define_singleton_method(cEpegImage, "open", rb_epeg_image_open, 1);
12
- rb_define_singleton_method(cEpegImage, "quality=", rb_epeg_image_set_default_quality, 1);
13
- rb_define_singleton_method(cEpegImage, "quality", rb_epeg_image_get_default_quality, 0);
10
+ rb_define_singleton_method(cEpegImage, "from_blob", rb_epeg_image_from_blob, 1);
11
+ rb_define_singleton_method(cEpegImage, "open", rb_epeg_image_open, 1);
12
+ rb_define_singleton_method(cEpegImage, "default_quality=", rb_epeg_image_set_default_quality, 1);
13
+ rb_define_singleton_method(cEpegImage, "default_quality", rb_epeg_image_get_default_quality, 0);
14
14
 
15
15
  rb_define_method(cEpegImage, "initialize", rb_epeg_image_initialize, 0);
16
16
 
@@ -69,12 +69,11 @@ static VALUE rb_epeg_image_from_blob(VALUE klass, VALUE blob)
69
69
 
70
70
  /*
71
71
  * call-seq:
72
- * quality=(q)
72
+ * default_quality=(q)
73
73
  *
74
74
  * Sets the default quality (+q+ >= 0 and +q+ <= 100)
75
- * See Epeg::Image#quality=
76
75
  *
77
- * Epeg::Image.quality = 10
76
+ * Epeg::Image.default_quality = 10
78
77
  */
79
78
  static VALUE rb_epeg_image_set_default_quality(VALUE klass, VALUE q)
80
79
  {
@@ -88,12 +87,11 @@ static VALUE rb_epeg_image_set_default_quality(VALUE klass, VALUE q)
88
87
 
89
88
  /*
90
89
  * call-seq:
91
- * quality
90
+ * default_quality
92
91
  *
93
92
  * Returns the current default quality for all images.
94
- * See Epeg::Image#quality
95
93
  *
96
- * Epeg::Image.quality #=> 85
94
+ * Epeg::Image.default_quality #=> 85
97
95
  */
98
96
  static VALUE rb_epeg_image_get_default_quality(VALUE klass)
99
97
  {
@@ -102,7 +100,7 @@ static VALUE rb_epeg_image_get_default_quality(VALUE klass)
102
100
 
103
101
  /*
104
102
  * call-seq:
105
- * intialize(file_path)
103
+ * intialize()
106
104
  *
107
105
  * See Epeg::Image.open
108
106
  */
@@ -115,14 +113,13 @@ static VALUE rb_epeg_image_initialize(VALUE self)
115
113
  epeg_quality_set(image, NUM2UINT(q));
116
114
  rb_iv_set(self, "@quality", q);
117
115
 
118
- char *comment;
119
116
  epeg_comment_set(image, (char *)NULL);
120
117
 
121
- unsigned int w, h;
118
+ int w, h;
122
119
  epeg_size_get(image, &w, &h);
123
120
 
124
- rb_iv_set(self, "@width", UINT2NUM(w));
125
- rb_iv_set(self, "@height", UINT2NUM(h));
121
+ rb_iv_set(self, "@width", INT2NUM(w));
122
+ rb_iv_set(self, "@height", INT2NUM(h));
126
123
 
127
124
  rb_iv_set(self, "epeg_file_closed", Qfalse);
128
125
  rb_iv_set(self, "epeg_trimmed", Qfalse);
@@ -235,7 +232,7 @@ static VALUE rb_epeg_image_resize_to_fill(VALUE self, VALUE w, VALUE h)
235
232
 
236
233
  /*
237
234
  * call-seq:
238
- * cropp(w, h, (x, y))
235
+ * cropp(w, h, [x, y])
239
236
  *
240
237
  * Crops image to +w+ x +h+. If +x+ and +y+ are not specified the image is
241
238
  * cropped with the center gravity.
@@ -246,28 +243,46 @@ static VALUE rb_epeg_image_crop(int argc, VALUE *argv, VALUE self)
246
243
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 4)", argc);
247
244
  }
248
245
 
249
- unsigned int w, h, x, y, i;
246
+ Check_Type(argv[0], T_FIXNUM);
247
+ Check_Type(argv[1], T_FIXNUM);
250
248
 
251
- if(argc == 2) {
252
- for(i = 0; i < 2; i++) { Check_Type(argv[i], T_FIXNUM); }
249
+ unsigned int w = NUM2UINT(argv[0]);
250
+ unsigned int h = NUM2UINT(argv[1]);
251
+
252
+ unsigned int iw = NUM2UINT(rb_iv_get(self, "@width"));
253
+ unsigned int ih = NUM2UINT(rb_iv_get(self, "@height"));
254
+
255
+ unsigned int x, y;
253
256
 
254
- w = NUM2UINT(argv[0]);
255
- h = NUM2UINT(argv[1]);
257
+ if(w > iw){ w = iw; }
258
+ if(h > ih){ h = ih; }
256
259
 
257
- x = (unsigned int)( ceil( (double)NUM2UINT( rb_iv_get(self, "@width") )/2 ) - (double)w/2 );
258
- y = (unsigned int)( ceil( (double)NUM2UINT( rb_iv_get(self, "@height") )/2 ) - (double)w/2 );
260
+ // crop with gravity = center
261
+ if(argc == 2) {
262
+ x = (int)( ceil( ((double)iw - (double)w)/2 ) );
263
+ y = (int)( ceil( ((double)ih - (double)h)/2 ) );
259
264
  }
260
265
 
266
+ // crop with origin at (x,y)
261
267
  if (argc == 4) {
262
- for(i = 0; i < 4; i++) { Check_Type(argv[i], T_FIXNUM); }
263
-
264
- w = NUM2UINT(argv[0]);
265
- h = NUM2UINT(argv[1]);
268
+ Check_Type(argv[2], T_FIXNUM);
269
+ Check_Type(argv[3], T_FIXNUM);
266
270
 
267
- x = NUM2UINT(argv[2]);
268
- y = NUM2UINT(argv[3]);
271
+ x = NUM2INT(argv[2]);
272
+ y = NUM2INT(argv[3]);
269
273
  }
270
274
 
275
+ if (x >= iw) { x = iw - 1; }
276
+ if (y >= ih) { y = ih - 1; }
277
+
278
+ if (w + x >= iw) { w = iw - x; }
279
+ if (h + y >= ih) { h = ih - y; }
280
+
281
+ // FIXME: epeg doesn't seem to be able to set bounds to (0,0,iw,ih)
282
+ // and encode/write the image to memory or file
283
+ if (w == iw) { w--; }
284
+ if (h == ih) { h--; }
285
+
271
286
  Epeg_Image *image;
272
287
  Data_Get_Struct(self, Epeg_Image, image);
273
288
 
@@ -289,7 +304,7 @@ static void rb_epeg_image_encode_or_trim(VALUE obj, Epeg_Image *image) {
289
304
  status = epeg_encode(image);
290
305
  }
291
306
 
292
- if(status != 0) { rb_raise(rb_eRuntimeError, "Error: can't encode"); }
307
+ if(status != 0) { rb_raise(rb_eRuntimeError, "Error: can't encode"); }
293
308
  }
294
309
 
295
310
  /*
@@ -314,7 +329,6 @@ static VALUE rb_epeg_image_write(VALUE self, VALUE file_path)
314
329
  epeg_file_output_set(image, StringValueCStr(file_path));
315
330
  rb_epeg_image_encode_or_trim(self, image);
316
331
 
317
- rb_iv_set(self, "epeg_file_closed", Qtrue);
318
332
  rb_epeg_image_close(self);
319
333
 
320
334
  return Qnil;
@@ -337,7 +351,7 @@ static VALUE rb_epeg_image_to_blob(VALUE self)
337
351
  Epeg_Image *image;
338
352
  Data_Get_Struct(self, Epeg_Image, image);
339
353
 
340
- unsigned char *data;
354
+ char *data;
341
355
  int size;
342
356
 
343
357
  epeg_memory_output_set(image, &data, &size);
@@ -346,7 +360,6 @@ static VALUE rb_epeg_image_to_blob(VALUE self)
346
360
  VALUE blob = rb_str_new(data, size);
347
361
  free(data);
348
362
 
349
- rb_iv_set(self, "epeg_file_closed", Qtrue);
350
363
  rb_epeg_image_close(self);
351
364
 
352
365
  return blob;
@@ -1,3 +1,3 @@
1
1
  module Epeg
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -12,7 +12,7 @@ describe Epeg::Image do
12
12
 
13
13
  context "when loading a valid jpeg file" do
14
14
  around(:each) do |example|
15
- Epeg::Image.quality = 75
15
+ Epeg::Image.default_quality = 75
16
16
  @image = Epeg::Image.open(TEST_JPEG)
17
17
  @output_image = Tempfile.new(%w{out .jpg})
18
18
 
@@ -92,6 +92,25 @@ describe Epeg::Image do
92
92
  expect(@cropped_image.to_blob).not_to eq(@another_cropped_image.to_blob)
93
93
  end
94
94
 
95
+ it "should not crop beyond image size" do
96
+ @image.crop(2000, 1000, 2000, 1000)
97
+ @image.write(@output_image.path)
98
+
99
+ @another_image = Epeg::Image.open(TEST_JPEG)
100
+ @another_image.crop(2000, 10000)
101
+ @another_output_image = Tempfile.new(%w{out2 .jpg})
102
+ @another_image.write(@another_output_image.path)
103
+
104
+ @cropped_image = Epeg::Image.open(@output_image.path)
105
+ @another_cropped_image = Epeg::Image.open(@another_output_image.path)
106
+
107
+ expect(@cropped_image.width ).to eq(1)
108
+ expect(@cropped_image.height).to eq(1)
109
+
110
+ expect(@another_cropped_image.width ).to eq(614)
111
+ expect(@another_cropped_image.height).to eq(767)
112
+ end
113
+
95
114
  it "should not write image after closing" do
96
115
  @image.close
97
116
 
@@ -0,0 +1,3 @@
1
+ require "rspec"
2
+
3
+ RSpec::Core::Runner.run(["./epeg_image_spec.rb"])
metadata CHANGED
@@ -1,66 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-epeg
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Nelson Darkwah Oppong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2014-10-14 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: rake-compiler
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
19
17
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: "0.9"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
22
20
  type: :development
23
- version_requirements: *id001
24
- - !ruby/object:Gem::Dependency
25
- name: bundler
26
21
  prerelease: false
27
- requirement: &id002 !ruby/object:Gem::Requirement
28
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
29
31
  - - ~>
30
- - !ruby/object:Gem::Version
31
- version: "1.7"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
32
34
  type: :development
33
- version_requirements: *id002
34
- - !ruby/object:Gem::Dependency
35
- name: rake
36
35
  prerelease: false
37
- requirement: &id003 !ruby/object:Gem::Requirement
38
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
39
45
  - - ~>
40
- - !ruby/object:Gem::Version
41
- version: "10.0"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
42
48
  type: :development
43
- version_requirements: *id003
44
- - !ruby/object:Gem::Dependency
45
- name: rspec
46
49
  prerelease: false
47
- requirement: &id004 !ruby/object:Gem::Requirement
48
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
49
59
  - - ~>
50
- - !ruby/object:Gem::Version
51
- version: "3.0"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
52
62
  type: :development
53
- version_requirements: *id004
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
54
69
  description:
55
- email:
70
+ email:
56
71
  - ndo@felixnelson.de
57
72
  executables: []
58
-
59
- extensions:
73
+ extensions:
60
74
  - ext/epeg/extconf.rb
61
75
  extra_rdoc_files: []
62
-
63
- files:
76
+ files:
64
77
  - .gitignore
65
78
  - .travis.yml
66
79
  - Gemfile
@@ -79,35 +92,36 @@ files:
79
92
  - ruby-epeg.gemspec
80
93
  - spec/epeg_image_spec.rb
81
94
  - spec/fixtures/einstein.jpg
95
+ - spec/runner.rb
82
96
  - spec/spec_helper.rb
83
97
  homepage: http://github.com/nelsond/ruby-epeg
84
- licenses:
98
+ licenses:
85
99
  - MIT
86
100
  metadata: {}
87
-
88
101
  post_install_message:
89
102
  rdoc_options: []
90
-
91
- require_paths:
103
+ require_paths:
92
104
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
94
- requirements:
95
- - &id005
96
- - ">="
97
- - !ruby/object:Gem::Version
98
- version: "0"
99
- required_rubygems_version: !ruby/object:Gem::Requirement
100
- requirements:
101
- - *id005
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
102
115
  requirements: []
103
-
104
116
  rubyforge_project:
105
- rubygems_version: 2.4.2
117
+ rubygems_version: 2.0.14
106
118
  signing_key:
107
119
  specification_version: 4
108
- summary: Ruby extension for the epeg library which provides facilities for scaling JPEG images very quickly.
109
- test_files:
120
+ summary: Ruby extension for the epeg library which provides facilities for scaling
121
+ JPEG images very quickly.
122
+ test_files:
110
123
  - spec/epeg_image_spec.rb
111
124
  - spec/fixtures/einstein.jpg
125
+ - spec/runner.rb
112
126
  - spec/spec_helper.rb
113
127
  has_rdoc: