photile 0.1.8 → 0.1.9

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
@@ -63,8 +63,10 @@ Photile uses the amazing [Imagemagick](http://www.imagemagick.org/script/index.p
63
63
 
64
64
  - Documentation
65
65
  - CLI option to show version
66
+ - Use log4r for logging
66
67
  - File validation for infile/outfile
67
68
  - More unit tests to ensure that all pipe permutations work
69
+ - Sign gem on deploy
68
70
 
69
71
  * * *
70
- Copyright (c) 2013 Nitin Dhar. See [MIT-LICENSE](MIT-LICENSE) for details.
72
+ Copyright (c) 2013 Nitin Dhar. See [MIT-LICENSE](MIT-LICENSE) for details.
@@ -11,21 +11,20 @@ end
11
11
 
12
12
  puts '[photile] Processing...' if verbose
13
13
 
14
- config[:options].each_index do |index|
15
- step = index+1
16
- config[:options][index].each do |key,val|
14
+ config[:options].each do |opt|
15
+ opt.each do |key,val|
17
16
  case key
18
17
  when :quality
19
- puts "[photile] #{step}. #{config[:infile]} => quality #{val}% => #{config[:outfile]}" if verbose
18
+ puts "[photile] * #{config[:infile]} => quality #{val}% => #{config[:outfile]}" if verbose
20
19
  `convert #{config[:infile]} -quality #{val} #{config[:outfile]}`
21
20
  when :compress
22
- puts "[photile] #{step}. #{config[:infile]} => compress => #{config[:outfile]}" if verbose
21
+ puts "[photile] * #{config[:infile]} => compress => #{config[:outfile]}" if verbose
23
22
  `jpegtran -copy none -optimize -perfect -outfile #{config[:outfile]} #{config[:outfile]}`
24
23
  when :watermark
25
- puts "[photile] #{step}. #{config[:infile]} => watermark #{val} => #{config[:outfile]}" if verbose
24
+ puts "[photile] * #{config[:infile]} => watermark #{val} => #{config[:outfile]}" if verbose
26
25
  `composite -gravity center #{val} #{config[:infile]} #{config[:outfile]}`
27
26
  when :tile
28
- puts "[photile] #{step}. #{config[:infile]} => tile #{val[:width]}x#{val[:height]} => [#{config[:outfile]}, ...]" if verbose
27
+ puts "[photile] * #{config[:infile]} => tile #{val[:width]}x#{val[:height]} => [#{config[:outfile]}, ...]" if verbose
29
28
  `convert #{config[:infile]} -crop #{val[:width]}x#{val[:height]} +repage +adjoin #{config[:outfile].split('.').join('%03d.')}`
30
29
  end
31
30
  end
@@ -1,5 +1,6 @@
1
1
  class Photile
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
+ REQUIREMENTS = "photile requires the following libraries to be installed: imagemagick, imagemagick-common and libjpeg-turbo-progs"
3
4
  end
4
5
 
5
6
  require 'photile/cli'
@@ -8,6 +8,7 @@ class Photile::Cli
8
8
  opts.banner = "Usage: photile [options] infile outfile"
9
9
 
10
10
  opts.on('-q', '--quality VALUE', Integer, 'Modify image quality') do |value|
11
+ validate_percent_value('Quality', value)
11
12
  options << {:quality => value}
12
13
  end
13
14
 
@@ -16,6 +17,7 @@ class Photile::Cli
16
17
  end
17
18
 
18
19
  opts.on('-w', '--watermark FILE', String, 'Watermark with given file') do |file|
20
+ validate_file_exist file
19
21
  options << {:watermark => file}
20
22
  end
21
23
 
@@ -24,13 +26,13 @@ class Photile::Cli
24
26
  options << {:tile => {:width => dim.first.to_i, :height => dim.last.to_i}}
25
27
  end
26
28
 
27
- opts.on('-v', '--[no-]verbose', 'Run verbosely') do |value|
29
+ opts.on('-v', '--verbose', 'Run verbosely') do |value|
28
30
  options << {:verbose => value}
29
31
  end
30
32
 
31
33
  opts.on('-h', '--help', 'Display options help') do
32
34
  puts opts
33
- puts 'photile requires the following libraries to be installed: imagemagick, imagemagick-common and libjpeg-turbo-progs'
35
+ puts Photile::REQUIREMENTS
34
36
  exit
35
37
  end
36
38
  end
@@ -40,19 +42,33 @@ class Photile::Cli
40
42
 
41
43
  if options.empty? || ARGV.size != 2
42
44
  puts optparse
43
- puts 'photile requires the following libraries to be installed: imagemagick, imagemagick-common and libjpeg-turbo-progs'
45
+ puts Photile::REQUIREMENTS
44
46
  exit
45
47
  end
46
48
 
49
+ validate_file_exist ARGV.first
50
+
47
51
  {:options => options, :infile => ARGV.first, :outfile => ARGV.last}
48
- rescue OptionParser::InvalidArgument => ia
52
+ rescue OptionParser::InvalidArgument
49
53
  puts 'Invalid argument'
50
54
  puts optparse
51
55
  exit
52
- rescue OptionParser::InvalidOption => io
56
+ rescue OptionParser::InvalidOption
53
57
  puts 'Invalid option'
54
58
  puts optparse
55
59
  exit
60
+ rescue Exception => e
61
+ puts e
62
+ puts optparse
63
+ exit
56
64
  end
57
65
  end
66
+
67
+ def self.validate_percent_value(metric, value)
68
+ raise "Invalid percentage: #{metric} #{value}%. Acceptable range: 0-100" if value < 0 || value > 100
69
+ end
70
+
71
+ def self.validate_file_exist(file)
72
+ raise "File [#{file}] not found" if !FileTest.exists? file
73
+ end
58
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: photile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: