paperclip_background_validator 0.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 136216ad9fa7bae1261d13694738f0cf635d177f4674a32d3ff4a3e3652f060e
4
+ data.tar.gz: 10ec79a6ea47e981d5148b0c94e2dea40991ce7aaa846fe58731b3c59e63c48c
5
+ SHA512:
6
+ metadata.gz: 5c90f2f9087bd3fbda9bc97e9ebcbedb6d572f3a1b968f2f9f28c138096b8dd56caef738824188d46db7154f8ed5220a80ae2acf06dd4ca19b08d829cb621471
7
+ data.tar.gz: 938a0feaedb3608e6fc345f3f1dadc1aab8c8d37288f4c3f315d8813e81472c67fa3f1d0dbb0e1d7b1d0ed17266b21cbeded2b857c9303e3ffab4cb1f6a9c3a1
@@ -0,0 +1,46 @@
1
+ module Paperclip
2
+ module Validators
3
+ class AttachmentBackgroundValidator < ActiveModel::EachValidator
4
+ def initialize(options)
5
+ super
6
+ end
7
+
8
+ def self.helper_method_name
9
+ :validates_attachment_background
10
+ end
11
+
12
+ def validate_each(record, attribute, value)
13
+ if record.send(attr).try(:queued_for_write).present?
14
+ _video = FFMPEG::Movie.new(record.send(attr).queued_for_write[:original].path)
15
+ if _video.valid?
16
+ frame_png = Tempfile.new(["screenshot_#{record.id}_",'.png'])
17
+ frame_txt = Tempfile.new(["screenshot_#{record.id}_",'.txt'])
18
+ begin
19
+ _video.screenshot(frame_png.path)
20
+ `convert #{frame_png.path} -resize 20% #{frame_txt.path}`
21
+ lines = `head -n 10 #{frame_txt.path}`.split("\n")
22
+ lines += `tail -n 10 #{frame_txt.path}`.split("\n")
23
+ lines.shift
24
+ if !lines.all? {|l| l.end_with? '(65535,65535,65535) #FFFFFF white'}
25
+ record.errors.add attr, 'Background is not white (#FFFFFF)'
26
+ end
27
+ ensure
28
+ frame_png.close
29
+ frame_png.unlink
30
+ frame_txt.close
31
+ frame_txt.unlink
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ module HelperMethods
39
+ def validates_attachment_background(*attr_names)
40
+ options = _merge_attributes(attr_names)
41
+ validates_with(AttachmentBackgroundValidator, options.dup)
42
+ validate_before_processing(AttachmentBackgroundValidator, options.dup)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ require 'active_model'
2
+ require 'paperclip/validators'
3
+ require 'paperclip/validators/attachment_background_validator'
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paperclip_background_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jiali Tian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - jason.tian@pixelforcesystems.com.au
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/paperclip/validators/attachment_background_validator.rb
21
+ - lib/paperclip_background_validator.rb
22
+ homepage: http://rubygems.org/gems/paperclip_background_validator
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.7.7
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Validate video background for Paperclip
46
+ test_files: []