class Paperclip::Validators::AttachmentBackgroundValidator
Public Class Methods
helper_method_name()
click to toggle source
# File lib/paperclip/validators/attachment_background_validator.rb, line 8 def self.helper_method_name :validates_attachment_background end
new(options)
click to toggle source
Calls superclass method
# File lib/paperclip/validators/attachment_background_validator.rb, line 4 def initialize(options) super end
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
# File lib/paperclip/validators/attachment_background_validator.rb, line 12 def validate_each(record, attribute, value) if record.send(attr).try(:queued_for_write).present? _video = FFMPEG::Movie.new(record.send(attr).queued_for_write[:original].path) if _video.valid? frame_png = Tempfile.new(["screenshot_#{record.id}_",'.png']) frame_txt = Tempfile.new(["screenshot_#{record.id}_",'.txt']) begin _video.screenshot(frame_png.path) `convert #{frame_png.path} -resize 20% #{frame_txt.path}` lines = `head -n 10 #{frame_txt.path}`.split("\n") lines += `tail -n 10 #{frame_txt.path}`.split("\n") lines.shift if !lines.all? {|l| l.end_with? '(65535,65535,65535) #FFFFFF white'} record.errors.add attr, 'Background is not white (#FFFFFF)' end ensure frame_png.close frame_png.unlink frame_txt.close frame_txt.unlink end end end end