img_checker 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/img_checker.rb +81 -0
  3. metadata +47 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7c8de0ef3b898bc07ada4b050ad673bc3d368a9
4
+ data.tar.gz: b3ac2de9e2f9f3dcef2746756d8eb2f963dfe0e5
5
+ SHA512:
6
+ metadata.gz: ea8455c580f6ae721a88160b8e2f5f18f48869417190f79aa659b793e188eda653e5de144c5201ffc790e103b586885b1f3c7722d73ac307b0d78382c36443af
7
+ data.tar.gz: 3ac27e76d962d453464ce24c2e4f9ec97ef78fc135b8d70b362b5327e052ef6013a8ec20b6ed421a1140dffa5b249ffcc6f835bb18e03dfb2c978fea7cf2cb12
@@ -0,0 +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
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: img_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Abishek V Ashok
8
+ - Ankit R Gadiya
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-01-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A simple image size checking gem
15
+ email:
16
+ - abhi2424shekvashok@gmail.com
17
+ - ankit4922@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/img_checker.rb
23
+ homepage: http://rubygems.org/gems/ImageSizeLinter
24
+ licenses:
25
+ - GPL-3.0
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.5.2
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: img_checker
47
+ test_files: []