pngdefry 0.0.1 → 0.0.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
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea13bef297ccdabc27a38ea0a7905b1d0fe6b019
4
- data.tar.gz: 585c349950ff89d86d0922ef7520405d6918a0e5
3
+ metadata.gz: 2e822644b0565eafcb0b240e580dc23887c3c35d
4
+ data.tar.gz: b20c17f4151685075cd42cd7aac58c4b2bda7870
5
5
  SHA512:
6
- metadata.gz: 9e47a1c4dab523e07f9e3cc37af773feef8e2858382dc2eb13de4c315c329eb05c0e6220faf30dfe045fbe3889ac15b39e125b47fb285848857932840f6bd96e
7
- data.tar.gz: 122f0890cf6e2b7827df61602b73a694375262c5ff835ab9a9bf0767f61940d71d587da1532871279e6cbd1e98b5db586f6a9b976a202e5750c8f1d5cb58d853
6
+ metadata.gz: 0f8be23cdd0e0e75335b58ab8507377d6358bdd18c2fd467deb8421756b2799e4add12d7c8533de964c6a85c503311ac648476f3aece4fc84306552660e7453c
7
+ data.tar.gz: eeb34ec2cd7e38fbd56398f7bfee51ddfcfafe841c688894ea4a48b968c816a05b83ab87f91048d3dcf99706695a6d5658639ea736fd74d7f95a4174c98a33ef
@@ -20,10 +20,19 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ To defry an image, call `defry`:
24
+
23
25
  ``` ruby
24
26
  Pngdefry.defry('input.png', 'output.png')
25
27
  ```
26
28
 
29
+ If you just need the dimensions, you can simply call `dimensions`:
30
+
31
+ ``` ruby
32
+ Pngdefry.dimensions('input.png')
33
+ #=> [58, 58]
34
+ ```
35
+
27
36
  ## Contributing
28
37
 
29
38
  1. Fork it
@@ -388,7 +388,7 @@ void applyRowFilters (int wide, int high, unsigned char *data)
388
388
  }
389
389
  }
390
390
 
391
- int process (char *filename, char *write_file_name)
391
+ int process (char *filename, char *write_file_name, unsigned int *width, unsigned int *height)
392
392
  {
393
393
  FILE *f;
394
394
  unsigned int length;
@@ -613,6 +613,13 @@ int process (char *filename, char *write_file_name)
613
613
  }
614
614
  imgwidth = read_long (&ihdr_chunk->data[4]);
615
615
  imgheight = read_long (&ihdr_chunk->data[8]);
616
+
617
+ if (!write_file_name) {
618
+ *width = imgwidth;
619
+ *height = imgheight;
620
+ return 1;
621
+ }
622
+
616
623
  bitdepth = ihdr_chunk->data[12];
617
624
  colortype = ihdr_chunk->data[13];
618
625
  compression = ihdr_chunk->data[14];
@@ -1130,7 +1137,7 @@ int process (char *filename, char *write_file_name)
1130
1137
  free (data_out);
1131
1138
  }
1132
1139
 
1133
- if (1)
1140
+ if (write_file_name)
1134
1141
  {
1135
1142
  if (!didShowName)
1136
1143
  {
@@ -1272,15 +1279,29 @@ int process (char *filename, char *write_file_name)
1272
1279
  VALUE Pngdefry = Qnil;
1273
1280
  void Init_pngdefry();
1274
1281
  VALUE method_pngdefry_defry(VALUE self, VALUE input, VALUE output);
1282
+ VALUE method_pngdefry_dimensions(VALUE self, VALUE input);
1275
1283
 
1276
1284
  void Init_pngdefry() {
1277
1285
  Pngdefry = rb_define_module("Pngdefry");
1278
1286
  rb_define_singleton_method(Pngdefry, "defry", method_pngdefry_defry, 2);
1287
+ rb_define_singleton_method(Pngdefry, "dimensions", method_pngdefry_dimensions, 1);
1279
1288
  }
1280
1289
 
1281
1290
  VALUE method_pngdefry_defry(VALUE self, VALUE input, VALUE output) {
1282
1291
  char *filename = StringValueCStr(input);
1283
1292
  char *outputFilename = StringValueCStr(output);
1284
- int result = process(filename, outputFilename);
1293
+ int result = process(filename, outputFilename, NULL, NULL);
1285
1294
  return INT2FIX(result);
1286
1295
  }
1296
+
1297
+ VALUE method_pngdefry_dimensions(VALUE self, VALUE input) {
1298
+ char *filename = StringValueCStr(input);
1299
+ unsigned int width = 0;
1300
+ unsigned int height = 0;
1301
+ int result = process(filename, NULL, &width, &height);
1302
+
1303
+ VALUE array = rb_ary_new();
1304
+ rb_ary_store(array, 0, INT2FIX(width));
1305
+ rb_ary_store(array, 1, INT2FIX(height));
1306
+ return array;
1307
+ }
@@ -1,3 +1,3 @@
1
1
  module Pngdefry
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pngdefry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Soffes