local-fastimage_resize 3.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f327d6289f0a78931571438e476321352ad3e3ad
4
+ data.tar.gz: 25d60b345bf41043e6c444def8cf47f632070ae4
5
+ SHA512:
6
+ metadata.gz: 9cae988edee0fb067cdc7fd9ed1fd1926d00d6eacfc0c23491f1f7e2b0547a65d0b82043972e8ae2514d9a457c330c74baa56edb9c367959f6a928abca2ea34b
7
+ data.tar.gz: 2b780ebdf8b756b9597d83729fec8e8a27e9164a7939676c1cc8215234bfcbe2552c9427faf0be16a787ace0a4a46dea0681459334131cb9b03c37186fe93b78
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # 3.0.0 - 2016-06-02
2
+
3
+ Removing remote image support
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ local-fastimage_resize (3.0.0)
5
+ RubyInline (>= 3.8.2)
6
+ local-fastimage (>= 3.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ RubyInline (3.12.4)
12
+ ZenTest (~> 4.3)
13
+ ZenTest (4.11.0)
14
+ local-fastimage (3.0.0)
15
+ minitest (5.9.0)
16
+ rake (10.5.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ bundler (~> 1.12)
23
+ local-fastimage_resize!
24
+ minitest (~> 5.0)
25
+ rake (~> 10.0)
26
+
27
+ BUNDLED WITH
28
+ 1.12.5
data/MIT_LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2011 Stephen Sykes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,27 @@
1
+ FastImage Resize is an extremely light solution for resizing images in ruby by using libgd
2
+
3
+ === Examples
4
+
5
+ require 'fastimage_resize'
6
+
7
+ FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", "my.gif", 100, 20)
8
+ => 1
9
+
10
+ === Requirements
11
+
12
+ RubyInline
13
+
14
+ gem install RubyInline
15
+
16
+ FastImage
17
+
18
+ gem install fastimage
19
+
20
+ Libgd
21
+
22
+ See http://www.libgd.org/
23
+ Libgd is commonly available on most unix platforms, including OSX.
24
+
25
+ === References
26
+
27
+ * http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Local FastImage Resize
2
+
3
+ This is a fork of the [FastImage
4
+ Resize](https://github.com/sdsykes/fastimage_resize) gem.
5
+
6
+ It features the following differences:
7
+
8
+ * Removal of all remote image handling code
9
+ * Minor changes to code organization
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'local-fastimage_resize', require: 'fastimage/resize'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+
24
+ If you are using Bundler's autorequire, you're good to go. Otherwise make sure
25
+ to `require "fastimage/resize"`.
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install local-fastimage_resize
30
+
31
+ Again, make sure to `require "fastimage/resize"`.
32
+
33
+
34
+
35
+ ## Usage
36
+
37
+ See [README.textile](README.textile) for more documentation. Everything should
38
+ work as advertised, except for remote images of course.
39
+
40
+
41
+
42
+ ## License
43
+
44
+ MIT, see file [MIT-LICENSE](MIT-LICENSE)
data/README.textile ADDED
@@ -0,0 +1,150 @@
1
+ h1. FastImage Resize
2
+
3
+ > This fork of the FastImage Resize Gem removes remote URL support to avoid a
4
+ > whole class of security-related problems. See "README.md":README.md for
5
+ > more details.
6
+
7
+ h4. FastImage Resize is an extremely light solution for resizing images in ruby by using libgd
8
+
9
+ FastImage Resize will resize gifs, jpegs, and png files.
10
+
11
+ It uses resampling to get good looking results.
12
+
13
+ And it doesn't rely on installing external heavy libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage).
14
+
15
+ FastImage Resize uses *Libgd*, which is commonly available on most unix platforms, including OSX. It is very likely that you already have this software installed on your server.
16
+
17
+ As its input, FastImage Resize can take a URI, a filename, or an IO object (or anything that responds to :read).
18
+ If you do not supply an output filename in the :outfile option, FastImage Resize will return you a Tempfile object. This will be unlinked when it is finalized during garbage collection.
19
+
20
+ FastImage Resize relies on "RubyInline":https://github.com/seattlerb/rubyinline for compiling and managing the C extension code.
21
+
22
+ h4. Incompatible API change Version 2.0.0 and above
23
+
24
+ Note that the parameters for version 2.0.0 have changed, the output filename is no longer the second parameter. See the examples.
25
+
26
+ h2. Examples
27
+
28
+ <pre>
29
+ <code>
30
+ require 'fastimage_resize'
31
+
32
+ FastImage.resize("example.gif", 100, 20, :outfile=>"my.gif")
33
+ => nil
34
+
35
+ outfile = FastImage.resize("nonexistentfile.png", 50, 50)
36
+ =>FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
37
+
38
+ outfile = FastImage.resize("afile.png", 50, 150)
39
+ => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-x3l8r7-0.png>
40
+
41
+ File.open("afile.png", "r") {|f| FastImage.resize(f, 100, 100)}
42
+ => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-y1ofh-0.png>
43
+ </code>
44
+ </pre>
45
+
46
+ Giving a zero value for width or height causes the image to scale proportionately.
47
+
48
+ h2. Installation
49
+
50
+ First check the requirements section below.
51
+
52
+ h4. Gem
53
+
54
+ <pre>
55
+ <code>
56
+ gem install fastimage_resize
57
+ </pre>
58
+ </code>
59
+
60
+ h4. Rails
61
+
62
+ Install the gem as above, and for Rails 2 configure it in your environment.rb file as below:
63
+ <pre>
64
+ <code>
65
+ ...
66
+ Rails::Initializer.run do |config|
67
+ ...
68
+ config.gem "fastimage_resize"
69
+ ...
70
+ end
71
+ ...
72
+ </code>
73
+ </pre>
74
+
75
+ For Rails 3, add this to your Gemfile:
76
+
77
+ <pre>
78
+ <code>
79
+ gem 'fastimage_resize'
80
+ </code>
81
+ </pre>
82
+
83
+ For any Rails version, you may also need this in your environment.rb so that the rails process puts the compiled C code in a place it can access:
84
+
85
+ <pre>
86
+ <code>
87
+ ENV['INLINEDIR'] = RAILS_ROOT + "/tmp" # for RubyInline
88
+ </code>
89
+ </pre>
90
+
91
+ Then you're off - just use FastImage.resize() in your code as in the examples.
92
+
93
+ h2. Requirements
94
+
95
+ * RubyInline
96
+
97
+ <pre>
98
+ <code>
99
+ gem install RubyInline
100
+ </pre>
101
+ </code>
102
+
103
+ * FastImage
104
+
105
+ <pre>
106
+ <code>
107
+ gem install fastimage
108
+ </pre>
109
+ </code>
110
+
111
+ * Libgd
112
+
113
+ See "http://www.libgd.org/":http://www.libgd.org/
114
+
115
+ Libgd is commonly available on most unix platforms, including OSX.
116
+
117
+ On OSX, if you have "macports":http://www.macports.org/ you can use.
118
+
119
+ <pre>
120
+ <code>
121
+ sudo port install gd2
122
+ </code>
123
+ </pre>
124
+
125
+ It is also available in "homebrew":http://github.com/mxcl/homebrew (search for gd), and "fink":http://www.finkproject.org/ (try fink install gd2 gd2-bin).
126
+
127
+ h2. Documentation
128
+
129
+ "http://rdoc.info/projects/sdsykes/fastimage_resize":http://rdoc.info/projects/sdsykes/fastimage_resize
130
+
131
+ h2. Caveats
132
+
133
+ Because of the way that libgd works, gif files that have transparency may not always come through with the transparency perfectly retained.
134
+
135
+
136
+ h2. Tests
137
+
138
+ Run @ruby test/test.rb@ to execute the tests.
139
+
140
+ h2. References
141
+
142
+ * "http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing":http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing
143
+
144
+ h2. Licence
145
+
146
+ MIT, see file MIT_LICENCE
147
+
148
+ h2. Author
149
+
150
+ Stephen Sykes, @sdsykes
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :patch: 3
3
+ :major: 2
4
+ :build:
5
+ :minor: 0
@@ -0,0 +1,177 @@
1
+ # FastImage Resize is an extremely light solution for resizing images in ruby by using libgd
2
+ #
3
+ # === Examples
4
+ #
5
+ # require 'fastimage_resize'
6
+ #
7
+ # FastImage.resize("image.gif", 100, 20, :outfile=>"thumbnail.gif")
8
+ # => 1
9
+ #
10
+ # === Requirements
11
+ #
12
+ # RubyInline and FastImage (installed via RubyGems) and libgd
13
+ #
14
+ # See http://www.libgd.org/
15
+ #
16
+ # Libgd is commonly available on most unix platforms, including OSX.
17
+ #
18
+ # === References
19
+ #
20
+ # * http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing
21
+
22
+ require 'inline'
23
+ require 'tempfile'
24
+ require 'fastimage'
25
+
26
+ module FastImage::Resize
27
+ SUPPORTED_FORMATS = [:jpeg, :png, :gif]
28
+ FILE_EXTENSIONS = [:jpg, :png, :gif] # prefer jpg to jpeg as an extension
29
+
30
+ class FormatNotSupported < FastImage::FastImageException # :nodoc:
31
+ end
32
+
33
+ def self.included(base)
34
+ base.extend ClassMethods
35
+ end
36
+
37
+ module ClassMethods
38
+ # Resizes an image, storing the result in a file given in file_out
39
+ #
40
+ # Input can be a filename, a uri, or an IO object.
41
+ #
42
+ # FastImage Resize can resize GIF, JPEG and PNG files.
43
+ #
44
+ # Giving a zero value for width or height causes the image to scale proportionately.
45
+ #
46
+ # === Example
47
+ #
48
+ # require 'fastimage_resize'
49
+ #
50
+ # FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", 100, 20, :outfile=>"my.gif")
51
+ #
52
+ # === Supported options
53
+ # [:jpeg_quality]
54
+ # A figure passed to libgd to determine quality of output jpeg (only useful if input is jpeg)
55
+ # [:outfile]
56
+ # Name of a file to store the output in, in this case a temp file is not used
57
+ #
58
+ def resize(source, width, height, options={})
59
+ new(source, :raise_on_failure => true).resize(width, height, options)
60
+ end
61
+ end
62
+
63
+ def resize(width, height, options = {})
64
+ jpeg_quality = options[:jpeg_quality] || -1
65
+ file_out = options[:outfile]
66
+
67
+ type_index = SUPPORTED_FORMATS.index(type)
68
+ raise FormatNotSupported unless type_index
69
+
70
+ if !file_out
71
+ temp_file = Tempfile.new(["fastimage-resize-", ".#{FILE_EXTENSIONS[type_index]}"])
72
+ temp_file.binmode
73
+ file_out = temp_file.path
74
+ else
75
+ temp_file = nil
76
+ end
77
+
78
+ resize_image(path, file_out.to_s, width.to_i, height.to_i, type_index, jpeg_quality.to_i)
79
+
80
+ temp_file
81
+ rescue RuntimeError => e
82
+ raise ImageFetchFailure, e.message
83
+ 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
+ end
176
+
177
+ FastImage.send(:include, FastImage::Resize)
@@ -0,0 +1,5 @@
1
+ class FastImage
2
+ module Resize
3
+ VERSION = "3.0.0"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fastimage/resize/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "local-fastimage_resize"
8
+ s.version = FastImage::Resize::VERSION
9
+ s.authors = ["Stephen Sykes"]
10
+ s.email = ["sdsykes@gmail.com"]
11
+
12
+ s.summary = "FastImage Resize - Image resizing fast and simple"
13
+ s.description = "FastImage Resize is an extremely light solution for resizing images in ruby by using libgd."
14
+ s.homepage = "http://github.com/sdsykes/fastimage_resize"
15
+
16
+ s.requirements = ["libgd, see www.libgd.org"]
17
+
18
+ s.license = "MIT"
19
+
20
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency "RubyInline", ">= 3.8.2"
24
+ s.add_dependency "local-fastimage", ">= 3.0.0"
25
+
26
+ s.add_development_dependency "bundler", "~> 1.12"
27
+ s.add_development_dependency "rake", "~> 10.0"
28
+ s.add_development_dependency "minitest", "~> 5.0"
29
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: local-fastimage_resize
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Stephen Sykes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: RubyInline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.8.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.8.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: local-fastimage
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: FastImage Resize is an extremely light solution for resizing images in
84
+ ruby by using libgd.
85
+ email:
86
+ - sdsykes@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - MIT_LICENCE
95
+ - README
96
+ - README.md
97
+ - README.textile
98
+ - Rakefile
99
+ - VERSION.yml
100
+ - lib/fastimage/resize.rb
101
+ - lib/fastimage/resize/version.rb
102
+ - local-fastimage_resize.gemspec
103
+ homepage: http://github.com/sdsykes/fastimage_resize
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements:
122
+ - libgd, see www.libgd.org
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.8
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: FastImage Resize - Image resizing fast and simple
128
+ test_files: []