image_resizer 0.1.4 → 0.2.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.
data/README.md CHANGED
@@ -17,19 +17,19 @@ Example:
17
17
  processor = ImageResizer::Processor.new
18
18
 
19
19
  # resize to fit the specified width, maintaining the original ratio
20
- resized_file = processor.resize(temp_object, :width => 320)
20
+ tempfile = processor.resize(temp_object, :width => 320)
21
21
 
22
22
  # resize to fit the specified height, maintaining the original ratio
23
- resized_file = processor.resize(temp_object, :height => 240)
23
+ tempfile = processor.resize(temp_object, :height => 240)
24
24
 
25
25
  # resize to the specified dimensions, cropping around the center to avoid stretching
26
- resized_file = processor.resize(temp_object, :width => 320, :height => 240)
26
+ tempfile = processor.resize(temp_object, :width => 320, :height => 240)
27
27
 
28
28
  # crop the original image to a frame and resize the result
29
29
  upper_left = [0.25, 0.15] # 25% from the left, 15% from the top
30
30
  lower_right = [0.75, 0.95] # 75% from the left, 95% from the top
31
31
  width = 320
32
- resized_file = processor.crop_to_frame_and_resize(temp_object,
32
+ tempfile = processor.crop_to_frame_and_resize(temp_object,
33
33
  :upper_left => upper_left,
34
34
  :lower_right => lower_right,
35
35
  :width => width
@@ -39,14 +39,18 @@ Example:
39
39
  point = [0.8, 0.3] # 80% from the left, 30% from the top
40
40
  width = 320
41
41
  height = 400
42
- resized_file = processor.resize_and_crop_around_point(temp_object,
42
+ tempfile = processor.resize_and_crop_around_point(temp_object,
43
43
  :point => point,
44
44
  :width => width,
45
45
  :height => height
46
46
  )
47
- File.open(output_file, 'wb') { |f| f.write(File.read(processed)) }
47
+ File.open(path_to_output_file, 'wb') { |f| f.write(File.read(tempfile)) }
48
48
 
49
49
 
50
+ # generate a .ico file with 16, 32, 64, 128, and 256 pixel square sizes
51
+ tempfile = processor.generate_icon(temp_object)
52
+ File.open(path_to_output_file, 'wb') { |f| f.write(File.read(tempfile)) }
53
+
50
54
  Credits
51
55
  =======
52
56
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "image_resizer"
8
- s.version = "0.1.4"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Nelson"]
12
- s.date = "2012-04-24"
12
+ s.date = "2012-04-27"
13
13
  s.description = "Image resizing gem (requires ImageMagick)"
14
14
  s.email = "daniel@populr.me"
15
15
  s.extra_rdoc_files = [
@@ -216,5 +216,14 @@ module ImageResizer
216
216
  format ? [super, {:format => format.to_sym}] : super
217
217
  end
218
218
 
219
+ def generate_icon(temp_object)
220
+ two_fifty_six_png = convert(temp_object, '-resize 256x256! -transparent white', :png).first
221
+ sixteen_png = convert(two_fifty_six_png, '-resize 16x16! -transparent white')
222
+ thirty_two_png = convert(two_fifty_six_png, '-resize 32x32! -transparent white')
223
+ sixty_four_png = convert(two_fifty_six_png, '-resize 64x64! -transparent white')
224
+ one_twenty_eight_png = convert(two_fifty_six_png, '-resize 128x128! -transparent white')
225
+ convert([sixteen_png, thirty_two_png, sixty_four_png, one_twenty_eight_png, two_fifty_six_png],
226
+ '', :ico).first
227
+ end
219
228
  end
220
229
  end
@@ -13,7 +13,13 @@ module ImageResizer
13
13
 
14
14
  def convert(temp_object=nil, args='', format=nil)
15
15
  tempfile = new_tempfile(format)
16
- run convert_command, %(#{quote(temp_object.path) if temp_object} #{args} #{quote(tempfile.path)})
16
+ if temp_object.is_a?(Array)
17
+ paths = temp_object.map { |obj| quote(obj.path) }.join(' ')
18
+ run convert_command, %(#{paths} #{args} #{quote(tempfile.path)})
19
+ else
20
+ run convert_command, %(#{quote(temp_object.path) if temp_object} #{args} #{quote(tempfile.path)})
21
+ end
22
+
17
23
  tempfile
18
24
  end
19
25
 
@@ -585,6 +585,39 @@ describe ImageResizer::Processor do
585
585
  image = ImageResizer::TempObject.new(SAMPLES_DIR.join('white pixel.png'))
586
586
  @processor.convert(image, "-resize 2x2!").should have_width(2)
587
587
  end
588
+
589
+ it "should allow an array of image files as the first parameter" do
590
+ image1 = double('image1')
591
+ image2 = double('image2')
592
+ tempfile = double('tempfile')
593
+
594
+ image1.stub(:path).and_return('hello world')
595
+ image2.stub(:path).and_return('goodbye')
596
+ tempfile.stub(:path).and_return('output path')
597
+
598
+ @processor.stub(:new_tempfile).and_return(tempfile)
599
+ @processor.should_receive(:run).with('convert', "'hello world' 'goodbye' 'output path'")
600
+ image = @processor.convert([image1, image2])
601
+ end
588
602
  end
589
603
 
604
+
605
+ describe "#generate_icon" do
606
+ it "it should create a multi-sized ico file from the source file" do
607
+ two_fifty_six_png = double('256')
608
+ @processor.should_receive(:convert).with(@image, '-resize 256x256! -transparent white', :png).and_return([two_fifty_six_png, :format => :png])
609
+ sixteen_png = double('16')
610
+ @processor.should_receive(:convert).with(two_fifty_six_png, '-resize 16x16! -transparent white').and_return(sixteen_png)
611
+ thirty_two_png = double('32')
612
+ @processor.should_receive(:convert).with(two_fifty_six_png, '-resize 32x32! -transparent white').and_return(thirty_two_png)
613
+ sixty_four_png = double('64')
614
+ @processor.should_receive(:convert).with(two_fifty_six_png, '-resize 64x64! -transparent white').and_return(sixty_four_png)
615
+ one_twenty_eight_png = double('128')
616
+ @processor.should_receive(:convert).with(two_fifty_six_png, '-resize 128x128! -transparent white').and_return(one_twenty_eight_png)
617
+ ico = double('ico')
618
+ @processor.should_receive(:convert).with([sixteen_png, thirty_two_png, sixty_four_png, one_twenty_eight_png, two_fifty_six_png],
619
+ '', :ico).and_return([ico, :format => :ico])
620
+ @processor.generate_icon(@image)
621
+ end
622
+ end
590
623
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_resizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-24 00:00:00.000000000 Z
12
+ date: 2012-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2153615040 !ruby/object:Gem::Requirement
16
+ requirement: &2152250060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153615040
24
+ version_requirements: *2152250060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jeweler
27
- requirement: &2153613480 !ruby/object:Gem::Requirement
27
+ requirement: &2152248560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153613480
35
+ version_requirements: *2152248560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &2153639960 !ruby/object:Gem::Requirement
38
+ requirement: &2152487300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153639960
46
+ version_requirements: *2152487300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: pry-nav
49
- requirement: &2153639400 !ruby/object:Gem::Requirement
49
+ requirement: &2152486740 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153639400
57
+ version_requirements: *2152486740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: pry-stack_explorer
60
- requirement: &2153638580 !ruby/object:Gem::Requirement
60
+ requirement: &2152485860 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153638580
68
+ version_requirements: *2152485860
69
69
  description: Image resizing gem (requires ImageMagick)
70
70
  email: daniel@populr.me
71
71
  executables: []
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  segments:
133
133
  - 0
134
- hash: -4439322556749363730
134
+ hash: 857189311652511831
135
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  none: false
137
137
  requirements: