fastimage_resize 1.2.1 → 1.2.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.
- data/README.textile +3 -3
- data/VERSION.yml +1 -1
- data/lib/fastimage_resize.rb +6 -5
- data/test/fixtures/faulty.jpg +0 -0
- data/test/fixtures/test.bmp +0 -0
- data/test/fixtures/test.gif +0 -0
- data/test/fixtures/test.ico +0 -0
- data/test/fixtures/test.jpg +0 -0
- data/test/fixtures/test.png +0 -0
- data/test/test.rb +68 -1
- metadata +8 -2
data/README.textile
CHANGED
@@ -29,7 +29,7 @@ h4. Gem
|
|
29
29
|
|
30
30
|
<pre>
|
31
31
|
<code>
|
32
|
-
sudo gem install
|
32
|
+
sudo gem install fastimage_resize
|
33
33
|
</pre>
|
34
34
|
</code>
|
35
35
|
|
@@ -41,7 +41,7 @@ Install the gem as above, and configure it in your environment.rb file as below:
|
|
41
41
|
...
|
42
42
|
Rails::Initializer.run do |config|
|
43
43
|
...
|
44
|
-
config.gem "
|
44
|
+
config.gem "fastimage_resize", :lib=>"fastimage_resize"
|
45
45
|
...
|
46
46
|
end
|
47
47
|
...
|
@@ -72,7 +72,7 @@ h2. Requirements
|
|
72
72
|
|
73
73
|
<pre>
|
74
74
|
<code>
|
75
|
-
sudo gem install
|
75
|
+
sudo gem install fastimage
|
76
76
|
</pre>
|
77
77
|
</code>
|
78
78
|
|
data/VERSION.yml
CHANGED
data/lib/fastimage_resize.rb
CHANGED
@@ -55,7 +55,7 @@ class FastImage
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def self.resize_local(file_in, file_out, w, h, jpeg_quality)
|
58
|
-
fi = new(file_in, :raise_on_failure=>true
|
58
|
+
fi = new(file_in, :raise_on_failure=>true)
|
59
59
|
type_index = SUPPORTED_FORMATS.index(fi.type)
|
60
60
|
raise FormatNotSupported unless type_index
|
61
61
|
fi.resize_image(file_in, file_out, w, h, type_index, jpeg_quality)
|
@@ -68,14 +68,13 @@ class FastImage
|
|
68
68
|
builder.add_link_flags "-lgd"
|
69
69
|
|
70
70
|
builder.c <<-"END"
|
71
|
-
|
71
|
+
VALUE resize_image(char *filename_in, char *filename_out, int w, int h, int image_type, int jpeg_quality) {
|
72
72
|
gdImagePtr im_in, im_out;
|
73
73
|
FILE *in, *out;
|
74
|
-
int trans,
|
75
|
-
int x, y, f = 0;
|
74
|
+
int trans = 0, x = 0, y = 0, f = 0;
|
76
75
|
|
77
76
|
in = fopen(filename_in, "rb");
|
78
|
-
if (!in) return;
|
77
|
+
if (!in) return Qnil;
|
79
78
|
|
80
79
|
im_out = gdImageCreateTrueColor(w, h); /* must be truecolor */
|
81
80
|
switch(image_type) {
|
@@ -103,6 +102,7 @@ class FastImage
|
|
103
102
|
if (!f) trans = -1; /* no transparent pixel found */
|
104
103
|
}
|
105
104
|
break;
|
105
|
+
default: return Qnil;
|
106
106
|
}
|
107
107
|
|
108
108
|
fclose(in);
|
@@ -131,6 +131,7 @@ class FastImage
|
|
131
131
|
}
|
132
132
|
gdImageDestroy(im_in);
|
133
133
|
gdImageDestroy(im_out);
|
134
|
+
return Qnil;
|
134
135
|
}
|
135
136
|
END
|
136
137
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/test.rb
CHANGED
@@ -1 +1,68 @@
|
|
1
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
PathHere = File.dirname(__FILE__)
|
6
|
+
|
7
|
+
require File.join(PathHere, "..", "lib", 'fastimage_resize')
|
8
|
+
|
9
|
+
require 'fakeweb'
|
10
|
+
|
11
|
+
FixturePath = File.join(PathHere, "fixtures")
|
12
|
+
|
13
|
+
GoodFixtures = {
|
14
|
+
"test.gif"=>[:gif, [17, 32]],
|
15
|
+
"test.jpg"=>[:jpeg, [882, 470]],
|
16
|
+
"test.png"=>[:png, [30, 20]]
|
17
|
+
}
|
18
|
+
|
19
|
+
BadFixtures = [
|
20
|
+
"test.bmp",
|
21
|
+
"faulty.jpg",
|
22
|
+
"test.ico"
|
23
|
+
]
|
24
|
+
|
25
|
+
TestUrl = "http://example.nowhere/"
|
26
|
+
|
27
|
+
GoodFixtures.each do |fn, info|
|
28
|
+
FakeWeb.register_uri(:get, "#{TestUrl}#{fn}", :body => File.join(FixturePath, fn))
|
29
|
+
end
|
30
|
+
BadFixtures.each do |fn|
|
31
|
+
FakeWeb.register_uri(:get, "#{TestUrl}#{fn}", :body => File.join(FixturePath, fn))
|
32
|
+
end
|
33
|
+
|
34
|
+
class FastImageResizeTest < Test::Unit::TestCase
|
35
|
+
def test_resize_image_types
|
36
|
+
GoodFixtures.each do |fn, info|
|
37
|
+
outfile = File.join(PathHere, "fixtures", "resized_" + fn)
|
38
|
+
FastImage.resize(TestUrl + fn, outfile, info[1][0] / 3, info[1][1] / 2)
|
39
|
+
assert_equal [info[1][0] / 3, info[1][1] / 2], FastImage.size(outfile)
|
40
|
+
File.unlink outfile
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_raise_for_bmp_files
|
45
|
+
fn = BadFixtures[0]
|
46
|
+
outfile = File.join(PathHere, "fixtures", "resized_" + fn)
|
47
|
+
assert_raises(FastImage::FormatNotSupported) do
|
48
|
+
FastImage.resize(TestUrl + fn, outfile, 20, 20)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_raise_for_faulty_files
|
53
|
+
fn = BadFixtures[1]
|
54
|
+
outfile = File.join(PathHere, "fixtures", "resized_" + fn)
|
55
|
+
assert_raises(FastImage::SizeNotFound) do
|
56
|
+
FastImage.resize(TestUrl + fn, outfile, 20, 20)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_raise_for_ico_files
|
61
|
+
fn = BadFixtures[2]
|
62
|
+
outfile = File.join(PathHere, "fixtures", "resized_" + fn)
|
63
|
+
assert_raises(FastImage::UnknownImageType) do
|
64
|
+
FastImage.resize(TestUrl + fn, outfile, 20, 20)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastimage_resize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Sykes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-16 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -47,6 +47,12 @@ files:
|
|
47
47
|
- Rakefile
|
48
48
|
- VERSION.yml
|
49
49
|
- lib/fastimage_resize.rb
|
50
|
+
- test/fixtures/faulty.jpg
|
51
|
+
- test/fixtures/test.bmp
|
52
|
+
- test/fixtures/test.gif
|
53
|
+
- test/fixtures/test.ico
|
54
|
+
- test/fixtures/test.jpg
|
55
|
+
- test/fixtures/test.png
|
50
56
|
- test/test.rb
|
51
57
|
has_rdoc: true
|
52
58
|
homepage: http://github.com/sdsykes/fastimage_resize
|