local-fastimage_resize 3.0.1 → 3.1.0

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: 35d30f9c5c3d94e005b8fc135fc1dd05b7f6673d
4
- data.tar.gz: e49f5802cd1dc2f9122a594659a1b018acb3ff3c
3
+ metadata.gz: ca87a23d6291dfd4c29c89cfcd301359a9c5f462
4
+ data.tar.gz: e23c3c7cb8d65db9a0d69975a6caade81a5daef6
5
5
  SHA512:
6
- metadata.gz: f5e113bafa6aa697a41c0e27e8b0f3e19005643093dae7c31b59cfd5f4ce5e1597d3ef0d45680691f1a1abf25e8afa4b88a588156eafee578ae3b4c429101248
7
- data.tar.gz: bb2dfa53b43dd1203a56d44fe6bec054110b44007e9cfaba432c58d0ad2ff8bc4ac52d5426b1d38b6151123c8227a1c1f9c655961deb6666cce7bc7607577d8d
6
+ metadata.gz: 3e8089f8e0dbcadb8a7d0a724a527a01c3e07216b671b5cafbf769b2bc5c646c15cfd94d16d8d85c90d21737ecf37a207934732039ab4512a2f4cc6cd8554d5d
7
+ data.tar.gz: 98958df3a3f1092189898370580be076ad2e0ca725dfe0570fad73d50a51e4c2c2afdc88ae8f17ceefd551d28a350a84644126b13450a3c8b00327bfcb45c067
data/.gitignore CHANGED
@@ -1,2 +1,5 @@
1
1
  /Gemfile.lock
2
2
  /pkg/
3
+ /tmp/
4
+ /lib/fastimage/resize/native_resize.bundle
5
+ /lib/fastimage/resize/native_resize.so
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.9
4
+ - 2.2.5
5
+ - 2.3.1
6
+
7
+ before_install:
8
+ - gem install bundler
9
+
10
+ cache: bundler
11
+ sudo: false
12
+
13
+ addons:
14
+ apt:
15
+ packages:
16
+ - libgd2-noxpm-dev
data/CHANGELOG.md CHANGED
@@ -1,7 +1,11 @@
1
+ # 3.1.0 - 2016-06-03
2
+
3
+ Replacing RubyInline with native extension.
4
+
1
5
  # 3.0.1 - 2016-06-02
2
6
 
3
7
  Updating meta data in gemspec, no code changes.
4
8
 
5
9
  # 3.0.0 - 2016-06-02
6
10
 
7
- Removing remote image support
11
+ Removing remote image support.
data/README.md CHANGED
@@ -6,8 +6,12 @@ Resize](https://github.com/sdsykes/fastimage_resize) gem.
6
6
  It features the following differences:
7
7
 
8
8
  * Removal of all remote image handling code
9
+ * Replacing RubyInline with native extension
9
10
  * Minor changes to code organization
10
11
 
12
+ [![Build
13
+ Status](https://travis-ci.org/planio-gmbh/local-fastimage_resize.svg?branch=master)](https://travis-ci.org/planio-gmbh/local-fastimage_resize)
14
+
11
15
  ## Installation
12
16
 
13
17
  Add this line to your application's Gemfile:
@@ -31,6 +35,19 @@ Or install it yourself as:
31
35
  Again, make sure to `require "fastimage/resize"`.
32
36
 
33
37
 
38
+ ### External dependencies
39
+
40
+ `local-fastimage_resize`, just as `fastimage_resize`, depends on
41
+ [libgd](http://www.libgd.org). Therefore you need to have the development
42
+ headers installed on your system.
43
+
44
+ * *Mac OS* (Homebrew): `brew install gd`
45
+ * *Debian*: `apt-get install libgd-dev`
46
+ * *Ubuntu*: `apt-get install libgd2-noxpm-dev`
47
+
48
+ The Ubuntu package with XPM support will work just as well. It's just, that
49
+ `fastimage_resize` will not make any use of it.
50
+
34
51
 
35
52
  ## Usage
36
53
 
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
2
3
  require "rake/testtask"
3
4
 
4
5
  Rake::TestTask.new(:test) do |t|
@@ -7,4 +8,14 @@ Rake::TestTask.new(:test) do |t|
7
8
  t.test_files = FileList['test/**/*_test.rb']
8
9
  end
9
10
 
11
+ require "rake/extensiontask"
12
+
13
+ Rake::ExtensionTask.new do |ext|
14
+ ext.name = "native_resize"
15
+ ext.ext_dir = "ext/fastimage_resize"
16
+ ext.lib_dir = "lib/fastimage/resize"
17
+ end
18
+
19
+ Rake::Task[:test].prerequisites << :compile
20
+
10
21
  task :default => :test
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fastimage/resize"
5
+
6
+ require "irb"
7
+ IRB.start
@@ -0,0 +1,6 @@
1
+ require "mkmf"
2
+
3
+ abort "missing libgd" unless have_library("gd")
4
+
5
+ dir_config "fastimage_resize"
6
+ create_makefile "native_resize"
@@ -0,0 +1,104 @@
1
+ #include <ruby.h>
2
+ #include <gd.h>
3
+
4
+ // static void d(VALUE v) {
5
+ // ID sym_puts = rb_intern("puts");
6
+ // ID sym_inspect = rb_intern("inspect");
7
+ // rb_funcall(rb_mKernel, sym_puts, 1, rb_funcall(v, sym_inspect, 0));
8
+ // }
9
+
10
+ static VALUE native_resize(VALUE self, VALUE rb_in, VALUE rb_out, VALUE rb_w, VALUE rb_h, VALUE rb_image_type, VALUE rb_jpeg_quality) {
11
+ char *filename_in = StringValuePtr(rb_in);
12
+ char *filename_out = StringValuePtr(rb_out);
13
+ int w = NUM2INT(rb_w);
14
+ int h = NUM2INT(rb_h);
15
+ int image_type = NUM2INT(rb_image_type);
16
+ int jpeg_quality = NUM2INT(rb_jpeg_quality);
17
+
18
+
19
+ gdImagePtr im_in, im_out;
20
+ FILE *in, *out;
21
+ int trans = 0, x = 0, y = 0, f = 0;
22
+
23
+ in = fopen(filename_in, "rb");
24
+ if (!in) return Qnil;
25
+
26
+ switch(image_type) {
27
+ case 0: im_in = gdImageCreateFromJpeg(in);
28
+ break;
29
+ case 1: im_in = gdImageCreateFromPng(in);
30
+ break;
31
+ case 2: im_in = gdImageCreateFromGif(in);
32
+ trans = gdImageGetTransparent(im_in);
33
+ /* find a transparent pixel, then turn off transparency
34
+ so that it copies correctly */
35
+ if (trans >= 0) {
36
+ for (x=0; x<gdImageSX(im_in); x++) {
37
+ for (y=0; y<gdImageSY(im_in); y++) {
38
+ if (gdImageGetPixel(im_in, x, y) == trans) {
39
+ f = 1;
40
+ break;
41
+ }
42
+ }
43
+ if (f) break;
44
+ }
45
+ gdImageColorTransparent(im_in, -1);
46
+ if (!f) trans = -1; /* no transparent pixel found */
47
+ }
48
+ break;
49
+ default: return Qnil;
50
+ }
51
+
52
+ if (w == 0 || h == 0) {
53
+ int originalWidth = gdImageSX(im_in);
54
+ int originalHeight = gdImageSY(im_in);
55
+ if (w == 0) {
56
+ w = (int)(h * originalWidth / originalHeight);
57
+ } else {
58
+ h = (int)(w * originalHeight / originalWidth);
59
+ }
60
+ }
61
+
62
+ im_out = gdImageCreateTrueColor(w, h); /* must be truecolor */
63
+
64
+ if (image_type == 1) {
65
+ gdImageAlphaBlending(im_out, 0); /* handle transparency correctly */
66
+ gdImageSaveAlpha(im_out, 1);
67
+ }
68
+
69
+ fclose(in);
70
+
71
+ /* Now copy the original */
72
+ gdImageCopyResampled(im_out, im_in, 0, 0, 0, 0,
73
+ gdImageSX(im_out), gdImageSY(im_out),
74
+ gdImageSX(im_in), gdImageSY(im_in));
75
+
76
+ out = fopen(filename_out, "wb");
77
+ if (out) {
78
+ switch(image_type) {
79
+ case 0: gdImageJpeg(im_out, out, jpeg_quality);
80
+ break;
81
+ case 1: gdImagePng(im_out, out);
82
+ break;
83
+ case 2: gdImageTrueColorToPalette(im_out, 0, 256);
84
+ if (trans >= 0) {
85
+ trans = gdImageGetPixel(im_out, x, y); /* get the color index of our transparent pixel */
86
+ gdImageColorTransparent(im_out, trans); /* may not always work as hoped */
87
+ }
88
+ gdImageGif(im_out, out);
89
+ break;
90
+ }
91
+ fclose(out);
92
+ }
93
+ gdImageDestroy(im_in);
94
+ gdImageDestroy(im_out);
95
+ return Qnil;
96
+ }
97
+
98
+ void Init_native_resize(void) {
99
+ VALUE cFastImageResize;
100
+
101
+ cFastImageResize = rb_const_get(rb_cObject, rb_intern("FastImage"));
102
+
103
+ rb_define_singleton_method(cFastImageResize, "native_resize", native_resize, 6);
104
+ }
@@ -19,7 +19,6 @@
19
19
  #
20
20
  # * http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing
21
21
 
22
- require 'inline'
23
22
  require 'tempfile'
24
23
  require 'fastimage'
25
24
 
@@ -75,103 +74,13 @@ module FastImage::Resize
75
74
  temp_file = nil
76
75
  end
77
76
 
78
- resize_image(path, file_out.to_s, width.to_i, height.to_i, type_index, jpeg_quality.to_i)
77
+ FastImage.native_resize(path, file_out.to_s, width.to_i, height.to_i, type_index, jpeg_quality.to_i)
79
78
 
80
79
  temp_file
81
80
  rescue RuntimeError => e
82
81
  raise ImageFetchFailure, e.message
83
82
  end
84
-
85
- private
86
-
87
- def resize_image(filename_in, filename_out, w, h, image_type, jpeg_quality); end
88
-
89
- inline do |builder|
90
- builder.include '"gd.h"'
91
- builder.add_link_flags "-lgd"
92
-
93
- builder.c <<-"END"
94
- VALUE resize_image(char *filename_in, char *filename_out, int w, int h, int image_type, int jpeg_quality) {
95
- gdImagePtr im_in, im_out;
96
- FILE *in, *out;
97
- int trans = 0, x = 0, y = 0, f = 0;
98
-
99
- in = fopen(filename_in, "rb");
100
- if (!in) return Qnil;
101
-
102
- switch(image_type) {
103
- case 0: im_in = gdImageCreateFromJpeg(in);
104
- break;
105
- case 1: im_in = gdImageCreateFromPng(in);
106
- break;
107
- case 2: im_in = gdImageCreateFromGif(in);
108
- trans = gdImageGetTransparent(im_in);
109
- /* find a transparent pixel, then turn off transparency
110
- so that it copies correctly */
111
- if (trans >= 0) {
112
- for (x=0; x<gdImageSX(im_in); x++) {
113
- for (y=0; y<gdImageSY(im_in); y++) {
114
- if (gdImageGetPixel(im_in, x, y) == trans) {
115
- f = 1;
116
- break;
117
- }
118
- }
119
- if (f) break;
120
- }
121
- gdImageColorTransparent(im_in, -1);
122
- if (!f) trans = -1; /* no transparent pixel found */
123
- }
124
- break;
125
- default: return Qnil;
126
- }
127
-
128
- if (w == 0 || h == 0) {
129
- int originalWidth = gdImageSX(im_in);
130
- int originalHeight = gdImageSY(im_in);
131
- if (w == 0) {
132
- w = (int)(h * originalWidth / originalHeight);
133
- } else {
134
- h = (int)(w * originalHeight / originalWidth);
135
- }
136
- }
137
-
138
- im_out = gdImageCreateTrueColor(w, h); /* must be truecolor */
139
-
140
- if (image_type == 1) {
141
- gdImageAlphaBlending(im_out, 0); /* handle transparency correctly */
142
- gdImageSaveAlpha(im_out, 1);
143
- }
144
-
145
- fclose(in);
146
-
147
- /* Now copy the original */
148
- gdImageCopyResampled(im_out, im_in, 0, 0, 0, 0,
149
- gdImageSX(im_out), gdImageSY(im_out),
150
- gdImageSX(im_in), gdImageSY(im_in));
151
-
152
- out = fopen(filename_out, "wb");
153
- if (out) {
154
- switch(image_type) {
155
- case 0: gdImageJpeg(im_out, out, jpeg_quality);
156
- break;
157
- case 1: gdImagePng(im_out, out);
158
- break;
159
- case 2: gdImageTrueColorToPalette(im_out, 0, 256);
160
- if (trans >= 0) {
161
- trans = gdImageGetPixel(im_out, x, y); /* get the color index of our transparent pixel */
162
- gdImageColorTransparent(im_out, trans); /* may not always work as hoped */
163
- }
164
- gdImageGif(im_out, out);
165
- break;
166
- }
167
- fclose(out);
168
- }
169
- gdImageDestroy(im_in);
170
- gdImageDestroy(im_out);
171
- return Qnil;
172
- }
173
- END
174
- end
175
83
  end
176
84
 
85
+ require 'fastimage/resize/native_resize'
177
86
  FastImage.send(:include, FastImage::Resize)
@@ -1,5 +1,5 @@
1
1
  class FastImage
2
2
  module Resize
3
- VERSION = "3.0.1"
3
+ VERSION = "3.1.0"
4
4
  end
5
5
  end
@@ -20,10 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
21
  s.require_paths = ["lib"]
22
22
 
23
- s.add_dependency "RubyInline", ">= 3.8.2"
23
+ s.extensions = "ext/fastimage_resize/extconf.rb"
24
+
24
25
  s.add_dependency "local-fastimage", "~> 3.0"
25
26
 
26
27
  s.add_development_dependency "bundler", "~> 1.12"
27
28
  s.add_development_dependency "rake", "~> 10.0"
28
29
  s.add_development_dependency "minitest", "~> 5.0"
30
+ s.add_development_dependency "rake-compiler", "~> 0.9.9"
29
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: local-fastimage_resize
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Sykes
@@ -9,22 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-02 00:00:00.000000000 Z
12
+ date: 2016-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: RubyInline
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 3.8.2
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: 3.8.2
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: local-fastimage
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -81,6 +67,20 @@ dependencies:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
69
  version: '5.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake-compiler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.9
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 0.9.9
84
84
  description: Local FastImage Resize is an extremely light solution for resizing images
85
85
  in ruby by using libgd.
86
86
  email:
@@ -88,10 +88,12 @@ email:
88
88
  - gregor@plan.io
89
89
  - support@plan.io
90
90
  executables: []
91
- extensions: []
91
+ extensions:
92
+ - ext/fastimage_resize/extconf.rb
92
93
  extra_rdoc_files: []
93
94
  files:
94
95
  - ".gitignore"
96
+ - ".travis.yml"
95
97
  - CHANGELOG.md
96
98
  - Gemfile
97
99
  - MIT_LICENCE
@@ -100,6 +102,9 @@ files:
100
102
  - README.textile
101
103
  - Rakefile
102
104
  - VERSION.yml
105
+ - bin/console
106
+ - ext/fastimage_resize/extconf.rb
107
+ - ext/fastimage_resize/native_resize.c
103
108
  - lib/fastimage/resize.rb
104
109
  - lib/fastimage/resize/version.rb
105
110
  - local-fastimage_resize.gemspec