img_checker 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/img_checker +3 -0
  3. data/lib/img_checker.rb +81 -81
  4. metadata +28 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7c8de0ef3b898bc07ada4b050ad673bc3d368a9
4
- data.tar.gz: b3ac2de9e2f9f3dcef2746756d8eb2f963dfe0e5
3
+ metadata.gz: d79412fddf96ceb0dc6c4009faf7097d3907be0c
4
+ data.tar.gz: d80e9dbf73cf77daf5de420d9359f3c979c614fc
5
5
  SHA512:
6
- metadata.gz: ea8455c580f6ae721a88160b8e2f5f18f48869417190f79aa659b793e188eda653e5de144c5201ffc790e103b586885b1f3c7722d73ac307b0d78382c36443af
7
- data.tar.gz: 3ac27e76d962d453464ce24c2e4f9ec97ef78fc135b8d70b362b5327e052ef6013a8ec20b6ed421a1140dffa5b249ffcc6f835bb18e03dfb2c978fea7cf2cb12
6
+ metadata.gz: f807d79d87b81820ca192fdf6f5c606d5d85c8054e36c5782e929b5cd2e7f2fbce8ee068cee494dc20df6fe80ee633936e8d1dda9b60192a84fa37d1e6d2ceee
7
+ data.tar.gz: 4199cf5226cfde26b509068b192f2aafe42b10e2d3676e81c33f8a9c29dc5c2d62dac698f52e35bdf6d703591e44209394246f0f03678b7f548e48176f1602e0
data/bin/img_checker ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'img_checker'
data/lib/img_checker.rb CHANGED
@@ -1,81 +1,81 @@
1
- # img_checker ruby gem
2
- # This gem checks for images which exceept the specified limit in the
3
- # img_config.yml file.
4
- # Authored by Abishek V Ashok and Ankit R Gadiya of FOSSASIA
5
- #
6
- # img_checker is free software: you can redistribute it and/or modify
7
- # it under the terms of the GNU General Public License as published by
8
- # the Free Software Foundation, either version 3 of the License, or
9
- # (at your option) any later version.
10
- #
11
- # img_checker is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- # GNU General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU General Public License
17
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- #
19
- class ImageSizeLinter
20
- def initialize(config_file)
21
- print 'Starting Image Checker,'
22
- print ' authored by Abishek V Ashok "for" FOSSASIA with love'
23
- puts "Improvements by Robby O'Connor during GCI 2016"
24
- # Initialize the config file
25
- require 'yaml'
26
- @config = YAML.load(File.open(config_file))
27
- # This int is to count the number of big images that exceed the specified
28
- # widthor height
29
- @big_images = 0
30
- end
31
-
32
- # Check the image dimensions
33
- def check_dimensions?(image, width, height)
34
- require 'fastimage'
35
- image_size = FastImage.size(image)
36
- if image_size[0] > width || image_size[1] > height
37
- puts "The image #{image} is larger than #{width}px x #{height}px [w x h]"
38
- @big_images += 1
39
- return false
40
- end
41
- true
42
- end
43
-
44
- def check_images?
45
- valid_sizes = true
46
- # For each direcotry hash do
47
- @config.each do |dir_config|
48
- # Get the directory pathonly from the array
49
- directory = Dir[dir_config['directory']]
50
- height = dir_config['height']
51
- width = dir_config['width']
52
- directory.each do |image|
53
- # Now we will use the other data available in the dir_config array
54
- valid_sizes = false unless check_dimensions?(image, width, height)
55
- end
56
- end
57
- valid_sizes
58
- end
59
-
60
- def ok?
61
- if check_images?
62
- puts 'All images are ok... Hurray!'
63
- else
64
- big_images = @big_images
65
- puts 'Image Checker: These images exceeds the specified dimensions'
66
- abort "#{big_images} image(s) have greater dimensions then specified."
67
- return false
68
- end
69
- true
70
- end
71
- end
72
-
73
- config_file = './img_config.yml'
74
-
75
- # Check images only if the config file exists or exit throwing out an error
76
- if File.exist?(config_file)
77
- checker = ImageSizeLinter.new config_file
78
- checker.ok?
79
- else
80
- abort 'Critical Error, No config file found. Please put up a config file'
81
- end
1
+ # img_checker ruby gem
2
+ # This gem checks for images which exceept the specified limit in the
3
+ # img_config.yml file.
4
+ # Authored by Abishek V Ashok and Ankit R Gadiya of FOSSASIA
5
+ #
6
+ # img_checker is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # img_checker is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+ class ImgChecker
20
+ def initialize(config_file)
21
+ print 'Starting Image Checker,'
22
+ print ' authored by Abishek V Ashok "for" FOSSASIA with love'
23
+ puts "Improvements by Robby O'Connor during GCI 2016"
24
+ # Initialize the config file
25
+ require 'yaml'
26
+ @config = YAML.load(File.open(config_file))
27
+ # This int is to count the number of big images that exceed the specified
28
+ # widthor height
29
+ @big_images = 0
30
+ end
31
+
32
+ # Check the image dimensions
33
+ def check_dimensions?(image, width, height)
34
+ require 'fastimage'
35
+ image_size = FastImage.size(image)
36
+ if image_size[0] > width || image_size[1] > height
37
+ puts "The image #{image} is larger than #{width}px x #{height}px [w x h]"
38
+ @big_images += 1
39
+ return false
40
+ end
41
+ true
42
+ end
43
+
44
+ def check_images?
45
+ valid_sizes = true
46
+ # For each direcotry hash do
47
+ @config.each do |dir_config|
48
+ # Get the directory pathonly from the array
49
+ directory = Dir[dir_config['directory']]
50
+ height = dir_config['height']
51
+ width = dir_config['width']
52
+ directory.each do |image|
53
+ # Now we will use the other data available in the dir_config array
54
+ valid_sizes = false unless check_dimensions?(image, width, height)
55
+ end
56
+ end
57
+ valid_sizes
58
+ end
59
+
60
+ def ok?
61
+ if check_images?
62
+ puts 'All images are ok... Hurray!'
63
+ else
64
+ big_images = @big_images
65
+ puts 'Image Checker: These images exceeds the specified dimensions'
66
+ abort "#{big_images} image(s) have greater dimensions then specified."
67
+ return false
68
+ end
69
+ true
70
+ end
71
+ end
72
+
73
+ config_file = './img_config.yml'
74
+
75
+ # Check images only if the config file exists or exit throwing out an error
76
+ if File.exist?(config_file)
77
+ checker = ImgChecker.new config_file
78
+ checker.ok?
79
+ else
80
+ abort 'Critical Error, No config file found. Please put up a config file'
81
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: img_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abishek V Ashok
@@ -9,18 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-01-06 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2017-01-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fastimage
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.0'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '2.0'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
14
34
  description: A simple image size checking gem
15
35
  email:
16
36
  - abhi2424shekvashok@gmail.com
17
37
  - ankit4922@gmail.com
18
- executables: []
38
+ executables:
39
+ - img_checker
19
40
  extensions: []
20
41
  extra_rdoc_files: []
21
42
  files:
43
+ - bin/img_checker
22
44
  - lib/img_checker.rb
23
- homepage: http://rubygems.org/gems/ImageSizeLinter
45
+ homepage: https://github.com/Abhi2424shek/img_checker/
24
46
  licenses:
25
47
  - GPL-3.0
26
48
  metadata: {}
@@ -40,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
40
62
  version: '0'
41
63
  requirements: []
42
64
  rubyforge_project:
43
- rubygems_version: 2.5.2
65
+ rubygems_version: 2.4.5.2
44
66
  signing_key:
45
67
  specification_version: 4
46
68
  summary: img_checker