pix_scale 0.1.0 → 0.1.1

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: 3b969d5d5f7aa5de29c297dbd8e98c5d6a020d68
4
- data.tar.gz: 9baf4d771fec21f8bab5d0a3e3b48c93fe2ca30e
3
+ metadata.gz: 4d8614598635a11e8ac05abf5923664b1cc70d69
4
+ data.tar.gz: d318080c15e69599c81a3f0f299f28428e0a6018
5
5
  SHA512:
6
- metadata.gz: 8f32fb05f7e477d24b491a57512c5461ac23d44a76f409b61cce943e740c87ce13c617d6a463a9b910826ad47e0347d817c694acbdb5c6fcae64f8d175d416cd
7
- data.tar.gz: 7a0d320513997a7fec07e4e480ecff59ff9c4f3b29f33cbd167ababbe25ac86b2ffb5f5a627e39740b7a523e15a042eac2c9215cfa337e7efbc0bd1523184ec5
6
+ metadata.gz: 6fb5f7f8d3ca4cc4efbf31ca2ba51fa66fea4055ff23a98e1559b67cc8ff6de58407772259a0ef667a20fcbd89f8afe856b0785ae9fd2e102ed8d75aeda91539
7
+ data.tar.gz: 237b17b8fecb6f61f66a457e00884140fe5ad5e5c4b19a6ea7515d58c6600fe6bfcdbec5bee36cdbe68cd9e6ca2c20800f8c8f71f2a4c3a4b6cb9955d8bc228d
data/NEWS.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.1.1: 2013-07-01
4
+
5
+ Supported specify type release!
6
+
7
+ ### Changes
8
+
9
+ * Improvements
10
+ * Added type option for specifying output type.
11
+
3
12
  ## 0.1.0: 2013-06-29
4
13
 
5
14
  Supported absolute length release!
data/README.md CHANGED
@@ -29,17 +29,25 @@ A command line tool for scale of pix.
29
29
  -rw-rw-r-- 1 you you 46643 2013-06-27 20:00 foo.png
30
30
  -rw-rw-r-- 1 you you 18539 2013-06-27 20:01 foo-0.5.png
31
31
 
32
- ### width,height
32
+ ### width/height
33
33
 
34
34
  % ls -l
35
35
  -rw-rw-r-- 1 you you 46643 2013-06-27 20:00 foo.png
36
36
 
37
- % pix_scale foo.png 200,200
37
+ % pix_scale foo.png 200_200 # width_height
38
38
 
39
39
  % ls -l
40
40
  -rw-rw-r-- 1 you you 46643 2013-06-27 20:00 foo.png
41
41
  -rw-rw-r-- 1 you you 18539 2013-06-27 20:01 foo-200_200.png
42
42
 
43
+ #### width only (Height maintains a ratio.)
44
+
45
+ % pix_scale foo.png 200
46
+
47
+ #### height only (Width maintains a ratio.)
48
+
49
+ % pix_scale foo.png _200
50
+
43
51
  ### multiple files
44
52
 
45
53
  % ls -l
@@ -54,6 +62,17 @@ A command line tool for scale of pix.
54
62
  -rw-rw-r-- 1 you you 31438 2013-06-27 20:00 bar.png
55
63
  -rw-rw-r-- 1 you you 16462 2013-06-27 20:01 bar-0.5.png
56
64
 
65
+ ### specify type
66
+
67
+ % ls -l
68
+ -rw-rw-r-- 1 you you 46643 2013-06-27 20:00 foo
69
+
70
+ % pix_scale -t png foo 0.5
71
+
72
+ % ls -l
73
+ -rw-rw-r-- 1 you you 46643 2013-06-27 20:00 foo
74
+ -rw-rw-r-- 1 you you 18539 2013-06-27 20:01 foo-0.5.png
75
+
57
76
  ## Contributing
58
77
 
59
78
  1. Fork it
@@ -6,19 +6,25 @@ module PixScale
6
6
  def self.run(*arguments)
7
7
  if /\A(-h|--help)\z/ =~ arguments[0]
8
8
  puts <<-EOM
9
- Usage: pix_scale FILE... SCALE
10
- Example: pix_scale foo.png 0.5
9
+ Usage: pix_scale [-t TYPE] FILE... SCALE|WIDTH_HEIGHT
10
+ Example1: pix_scale foo.png 0.5
11
+ Example2: pix_scale foo.png 240_180
12
+ Example3: pix_scale -t png foo 0.5
11
13
  EOM
12
14
  exit(true)
13
15
  elsif /\A(-v|--version)\z/ =~ arguments[0]
14
16
  puts PixScale::VERSION
15
17
  exit(true)
18
+ elsif /\A(-t|--type)\z/ =~ arguments[0]
19
+ # FIXME: Use OptionParser
20
+ type = arguments[1]
21
+ arguments.shift(2)
16
22
  end
17
23
 
18
24
  scale = arguments.pop
19
25
 
20
26
  arguments.each do |pic_path|
21
- Pic.scale_and_save(pic_path, scale)
27
+ Pic.scale_and_save(pic_path, scale, type)
22
28
  end
23
29
  end
24
30
  end
data/lib/pix_scale/pic.rb CHANGED
@@ -1,9 +1,13 @@
1
+ # TODO: Remove me. It is workaround untill Ruby/GdkPixbuf2 2.0.3 is released.
2
+ # This is required in order to work on Windows.
3
+ require "cairo"
4
+
1
5
  require "gdk_pixbuf2"
2
6
 
3
7
  module PixScale
4
8
  class Pic
5
- def self.scale_and_save(path, scale)
6
- new(path).scale_and_save(scale)
9
+ def self.scale_and_save(path, scale, type=nil)
10
+ new(path).scale_and_save(scale, type)
7
11
  end
8
12
 
9
13
  attr_reader :path, :type
@@ -13,10 +17,12 @@ module PixScale
13
17
  @type = (/\A\.jpg\z/i =~ extname) ? "jpeg" : extname.sub(/^\./, "").downcase
14
18
  end
15
19
 
16
- def scale_and_save(scale)
20
+ def scale_and_save(scale, type=nil)
17
21
  scale_string = scale.to_s.sub(/[^\.0-9]/, "_")
18
- output_path = "#{dirname}/#{basename}-#{scale_string}#{extname}"
19
- scale(scale).save(output_path)
22
+ extention = type || extname
23
+ extention = ".#{extention}" unless /\A\./ =~ extention
24
+ output_path = "#{dirname}/#{basename}-#{scale_string}#{extention}"
25
+ scale(scale).save(output_path, type)
20
26
  end
21
27
 
22
28
  def scale(scale)
@@ -48,8 +54,9 @@ module PixScale
48
54
  @pic = @pic.scale(width, height)
49
55
  end
50
56
 
51
- def save(output_path)
52
- @pic.save(output_path, @type)
57
+ def save(output_path, type=nil)
58
+ output_type = type || @type
59
+ @pic.save(output_path, output_type)
53
60
  end
54
61
 
55
62
  private
@@ -1,3 +1,3 @@
1
1
  module PixScale
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/pix_scale.gemspec CHANGED
@@ -20,6 +20,10 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_runtime_dependency("gdk_pixbuf2")
22
22
 
23
+ # TODO: Remove me. It is workaround untill Ruby/GdkPixbuf2 2.0.3 is released.
24
+ # This is required in order to work on Windows.
25
+ spec.add_runtime_dependency("cairo")
26
+
23
27
  spec.add_development_dependency("test-unit")
24
28
  spec.add_development_dependency("test-unit-notify")
25
29
  spec.add_development_dependency("test-unit-rr")
data/test/test-pic.rb CHANGED
@@ -13,60 +13,67 @@ class PicTest < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  class ScaleAndSaveTest < self
16
- def test_scale_and_save_rate
16
+ def test_rate
17
17
  path = "test/fixtures/nijip.png"
18
18
  scale = 0.5
19
19
  scaled_path = "test/fixtures/nijip-0.5.png"
20
20
  assert_scale_and_save(path, scale, scaled_path)
21
21
  end
22
22
 
23
- def test_scale_and_save_width_and_height
23
+ def test_width_and_height
24
24
  path = "test/fixtures/nijip.png"
25
25
  scale = "240,180"
26
26
  scaled_path = "test/fixtures/nijip-240_180.png"
27
27
  assert_scale_and_save(path, scale, scaled_path)
28
28
  end
29
29
 
30
- def test_scale_and_save_upcase_PNG
30
+ def test_upcase_PNG
31
31
  path = "test/fixtures/nyanko.PNG"
32
32
  scale = 0.66
33
33
  scaled_path = "test/fixtures/nyanko-0.66.PNG"
34
34
  assert_scale_and_save(path, scale, scaled_path)
35
35
  end
36
36
 
37
- def test_scale_and_save_jpg
37
+ def test_jpg
38
38
  path = "test/fixtures/teabreak.jpg"
39
39
  scale = 0.09
40
40
  scaled_path = "test/fixtures/teabreak-0.09.jpg"
41
41
  assert_scale_and_save(path, scale, scaled_path)
42
42
  end
43
43
 
44
- def test_scale_and_save_jpeg
44
+ def test_jpeg
45
45
  path = "test/fixtures/teabreak.jpeg"
46
46
  scale = 0.09
47
47
  scaled_path = "test/fixtures/teabreak-0.09.jpeg"
48
48
  assert_scale_and_save(path, scale, scaled_path)
49
49
  end
50
50
 
51
- def test_scale_and_save_upcase_JPG
51
+ def test_upcase_JPG
52
52
  path = "test/fixtures/teabreak.JPG"
53
53
  scale = 0.09
54
54
  scaled_path = "test/fixtures/teabreak-0.09.JPG"
55
55
  assert_scale_and_save(path, scale, scaled_path)
56
56
  end
57
57
 
58
- def test_scale_and_save_upcase_JPEG
58
+ def test_upcase_JPEG
59
59
  path = "test/fixtures/teabreak.JPEG"
60
60
  scale = 0.09
61
61
  scaled_path = "test/fixtures/teabreak-0.09.JPEG"
62
62
  assert_scale_and_save(path, scale, scaled_path)
63
63
  end
64
64
 
65
+ def test_type_option
66
+ path = "test/fixtures/teabreak.JPEG"
67
+ scale = 0.09
68
+ scaled_path = "test/fixtures/teabreak-0.09.png"
69
+ assert_scale_and_save(path, scale, scaled_path, "png")
70
+ end
71
+
65
72
  private
66
- def assert_scale_and_save(path, scale, scaled_path)
73
+ def assert_scale_and_save(path, scale, scaled_path, type=nil)
67
74
  File.delete(scaled_path) if File.exist?(scaled_path)
68
75
  pic = PixScale::Pic.new(path)
69
- pic.scale_and_save(scale)
76
+ pic.scale_and_save(scale, type)
70
77
  assert_true(File.file?(scaled_path))
71
78
  assert_true(File.size(path) > File.size(scaled_path))
72
79
  assert_true(File.size(scaled_path) > 0)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pix_scale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-29 00:00:00.000000000 Z
11
+ date: 2013-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gdk_pixbuf2
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cairo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: test-unit
29
43
  requirement: !ruby/object:Gem::Requirement