simple_magick 1.1.0 → 1.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: 84cec9598f800ccc7f0fdde507e3e4bbf6d7f016
4
- data.tar.gz: 332b6a270e80603d51a87e32350f92d59a963bdd
3
+ metadata.gz: 17a0ccf6b375a6d032c7cea168ce30867532580e
4
+ data.tar.gz: acb2eab7b0dc8713ecea07d4f1d391245d2ec4f4
5
5
  SHA512:
6
- metadata.gz: bdc31d9e883b830815eb7aea1ad211b63e274d58d6617895340aa3bf2297ae49ea74c0f6e5d66296a4d85eb7febbeaa460195b0b6ba9f7ec02925a94c3fc66fd
7
- data.tar.gz: 2caf687984ace41542c206c90368bed7bb6bd29d539c7c9da03ef7702ea6c1d22920fb5ef0c13c667b8049770e6fa72e79f2ab8a2a9bec72fb3a86a34fa4d792
6
+ metadata.gz: 47228979a88460103432c84276653da6b27ea284f95035fd05bb3dcf5d060ef9ead0ed36204e9bfad93de18dd67817f574a30d892887c1c18a165452206c8465
7
+ data.tar.gz: 215efe784a35af263a9c2e486a98fa332451cc51b7d2d3d7d8283b847af5bd214f84e3d3d0ecfd7165b14f5f24fb93050ff0ed21292e2ed37c7e3ec71a0c28f7
data/.gitignore CHANGED
@@ -1,9 +1,12 @@
1
1
  *.gem
2
2
  *.rbc
3
+ *.DS_Store
3
4
  .bundle
4
5
  .idea
5
6
  .config
6
7
  .yardoc
8
+ .*.un~
9
+ .*.swp
7
10
  Gemfile.lock
8
11
  InstalledFiles
9
12
  _yardoc
@@ -13,7 +16,8 @@ lib/bundler/man
13
16
  pkg
14
17
  rdoc
15
18
  spec/reports
19
+ spec/assets/result
16
20
  test/tmp
17
21
  test/version_tmp
18
22
  tmp
19
- bench/tmp
23
+ bench/tmp
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # SimpleMagick
1
+ # SimpleMagick [![Code Climate](https://codeclimate.com/github/sugamasao/simple_magick.png)](https://codeclimate.com/github/sugamasao/simple_magick)
2
2
 
3
3
  SimpleMagick is Ultra Simple ImageMagick Wrapper.
4
4
 
@@ -1,5 +1,6 @@
1
1
  require 'simple_magick/version'
2
2
  require 'simple_magick/image_magick'
3
+ require 'simple_magick/utility'
3
4
  require 'fileutils'
4
5
  require 'open3'
5
6
  require 'shellwords'
@@ -11,7 +12,7 @@ module SimpleMagick
11
12
  # @note Windows Not Supported
12
13
  # @return [Boolean] find mogrify command is true
13
14
  def self.imagemagick_installed?
14
- !`which #{ImageMagick::EXEC}`.split("\n").first.nil?
15
+ !`which #{ImageMagick::EXEC}`.split("\n").first.nil? unless Utility.windows?
15
16
  end
16
17
 
17
18
  # Convert Image Class.
@@ -35,16 +36,19 @@ module SimpleMagick
35
36
  __send__(:additional_option, method.to_s, args[0])
36
37
  end
37
38
 
38
- # use other options.
39
+ # use options.
39
40
  # @param [String] option option name
40
41
  # @param [String] value option value. default = ''
41
42
  def additional_option(option, value = '')
42
- @command << "-#{command_escape(option)} #{command_escape(value)}".strip
43
+ value = value.strip
44
+ @command << %Q(-#{option}).strip
45
+ @command.last << %Q( "#{value}") unless value.empty?
46
+ @command
43
47
  end
44
48
 
45
49
  # run ImageMagick.
46
50
  # @param [String] destination_path output image path
47
- # @return [Void]
51
+ # @return [String] execute command
48
52
  # @raise [SimpleMagick::ConvertError] mogrify command fail.
49
53
  def convert!(destination_path)
50
54
  file_copy(destination_path)
@@ -61,6 +65,8 @@ module SimpleMagick
61
65
  unless status.success?
62
66
  raise ConvertError.new("#{ImageMagick::EXEC} error. exec command => [#{command}], stdout => [#{stdout}], stderr => [#{stderr}]")
63
67
  end
68
+
69
+ command
64
70
  end
65
71
 
66
72
  private
@@ -85,15 +91,12 @@ module SimpleMagick
85
91
  # @param [String] destination_path create image path
86
92
  # @return [String] command String.
87
93
  def create_command(command, destination_path)
88
- command << Shellwords.escape(destination_path)
94
+ if Utility.windows?
95
+ command << destination_path
96
+ else
97
+ command << Shellwords.escape(destination_path)
98
+ end
89
99
  command.join(' ')
90
100
  end
91
-
92
- # option string to CLI Escape.
93
- # @return [String] escaped string
94
- def command_escape(value)
95
- string_value = value.to_s.strip
96
- Shellwords.escape(string_value) unless string_value.empty?
97
- end
98
101
  end
99
102
  end
@@ -0,0 +1,9 @@
1
+ module SimpleMagick
2
+ # Utility methods
3
+ class Utility
4
+ # @return [Boolean] true is Windows
5
+ def self.windows?
6
+ !!RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module SimpleMagick
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -16,7 +16,7 @@ describe SimpleMagick do
16
16
 
17
17
  it 'set option and value' do
18
18
  image = SimpleMagick::Image.new(asset_path)
19
- expect(image.additional_option('type', 'Grayscale').last).to eq '-type Grayscale'
19
+ expect(image.additional_option('type', 'Grayscale').last).to eq '-type "Grayscale"'
20
20
  end
21
21
 
22
22
  it 'set only option' do
@@ -57,7 +57,60 @@ describe SimpleMagick do
57
57
  end
58
58
  end
59
59
 
60
+ context 'create command remove ShellEscape and quote option' do
61
+ context '#3 draw option filed' do
62
+ let(:asset_path) { File.join(__dir__, 'assets', 'sample.jpg') }
63
+ let(:result_path) { File.join(__dir__, 'assets', 'result', 'resize.jpg') }
64
+
65
+ before do
66
+ result_dir = File.dirname(result_path)
67
+ FileUtils.rm_r(result_dir) if File.directory?(result_dir)
68
+ end
69
+
70
+ it 'draw option Success' do
71
+ image = SimpleMagick::Image.new(asset_path)
72
+ image.draw 'stroke #0000ff stroke-width 2 fill-opacity 0.0 rectangle 10,10 100,100'
73
+ image.convert! result_path
74
+ expect(File).to be_file(result_path)
75
+ end
76
+ end
77
+
78
+ context '#2 Windows filename type 8.1 filed(only windows)' do
79
+ let(:asset_path) { File.join(__dir__, 'assets', 'sample.jpg') }
80
+ let(:result_path) { File.join(__dir__, 'assets', 'result', 'AAA123~1.jpg') }
81
+
82
+ context 'Windows OS' do
83
+ before do
84
+ result_dir = File.dirname(result_path)
85
+ FileUtils.rm_r(result_dir) if File.directory?(result_dir)
86
+ SimpleMagick::Utility.stub(:windows?) { true }
87
+ end
88
+
89
+ it 'convert! success' do
90
+ image = SimpleMagick::Image.new(asset_path)
91
+ image.resize '150x'
92
+ expect(image.convert!(result_path).split(' ').last).to eq result_path
93
+ expect(File).to be_file(result_path)
94
+ end
95
+ end
96
+
97
+ context 'Not Windows OS' do
98
+ before do
99
+ result_dir = File.dirname(result_path)
100
+ FileUtils.rm_r(result_dir) if File.directory?(result_dir)
101
+ SimpleMagick::Utility.stub(:windows?) { false }
102
+ end
103
+
104
+ it 'convert! success' do
105
+ image = SimpleMagick::Image.new(asset_path)
106
+ image.resize '150x'
107
+ expect(image.convert!(result_path).split(' ').last).to eq Shellwords.escape(result_path)
108
+ expect(File).to be_file(result_path)
109
+ end
110
+ end
111
+ end
112
+ end
60
113
  end
61
114
  end
62
115
 
63
- end
116
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - sugamasao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-11 00:00:00.000000000 Z
11
+ date: 2014-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -111,6 +111,7 @@ files:
111
111
  - benchmark/benchmark.rb
112
112
  - lib/simple_magick.rb
113
113
  - lib/simple_magick/image_magick.rb
114
+ - lib/simple_magick/utility.rb
114
115
  - lib/simple_magick/version.rb
115
116
  - simple_magick.gemspec
116
117
  - spec/assets/sample.jpg
@@ -136,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
137
  version: '0'
137
138
  requirements: []
138
139
  rubyforge_project:
139
- rubygems_version: 2.2.0
140
+ rubygems_version: 2.2.2
140
141
  signing_key:
141
142
  specification_version: 4
142
143
  summary: Simple ImageMagick Wrapper.