privatize 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/privatize +56 -0
- data/lib/privatize/image.rb +53 -0
- data/lib/privatize/pixelate.rb +25 -0
- data/lib/privatize/version.rb +3 -0
- data/lib/privatize.rb +9 -0
- metadata +8 -3
- data/spec/files/test.gif +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15c7b083504112b959ef7f1d786d4c6e5d54c13b
|
4
|
+
data.tar.gz: c3b432ae1ca85827f2047c977dbefcd15faf8a67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08c27b478a6cc25b592cd27f589cc677e1d0ef3a76c7ad56fac08b180654bd8ec7816b7a8045c9ef684d10f4ad7bdf6e1f5f851db77acf83b2c2a393ea40d2ea
|
7
|
+
data.tar.gz: 6f7b3ba533fe588c71bc0551c26e74a733765a9b5015e5262fa211d5058e0c17193cfc935e09e71c4202974299e20182357fb0d349095b136789e4d6818ac3cb
|
data/bin/privatize
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.expand_path('../../lib', __FILE__))
|
3
|
+
|
4
|
+
require 'privatize'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: privatize -i PATH [options] OUTPUT"
|
10
|
+
|
11
|
+
opts.on("-i", "--input PATH", "the PATH to the file you want to alter.") do |path|
|
12
|
+
options[:path] = path
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-e", "--effect EFFECT", "the effect to use on your image. this defaults to 'pixelate'.") do |effect|
|
16
|
+
options[:effect] = effect || "pixelate"
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-l", "--level LEVEL", "this dictates the intensity of the alteration. it must be a number between 1 and 100") do |level|
|
20
|
+
options[:level] = level
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
parser.parse!
|
26
|
+
|
27
|
+
mandatory = [:path]
|
28
|
+
missing = mandatory.select{ |param| options[param].nil? }
|
29
|
+
unless missing.empty?
|
30
|
+
puts "\nMissing options: #{missing.join(', ')}"
|
31
|
+
puts parser, "\n"
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
|
35
|
+
errors = []
|
36
|
+
case
|
37
|
+
when options[:level] && options[:level].to_i < 1 || options[:level].to_i > 100
|
38
|
+
errors << "Error: the level must be between 1 and 100\n\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
unless errors.empty?
|
42
|
+
errors.map { |e| puts "\n#{e}" }
|
43
|
+
puts parser, "\n"
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
|
47
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
48
|
+
puts $!.to_s
|
49
|
+
puts parser, "\n"
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
@effect = options[:effect] || "pixelate"
|
54
|
+
@output = ARGV[0] || Dir.pwd
|
55
|
+
@image = Privatize.const_get(@effect.capitalize).new(options[:path], { output: @output })
|
56
|
+
@image.process!(options[:level])
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Privatize
|
2
|
+
|
3
|
+
class Image
|
4
|
+
|
5
|
+
attr_reader :path, :output
|
6
|
+
|
7
|
+
def initialize path, options={}
|
8
|
+
@path = path
|
9
|
+
@output = options[:output] || nil
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def effects
|
14
|
+
klasses = ObjectSpace.each_object(Class).select { |klass| klass < self }
|
15
|
+
klasses.map {|e| e.to_s.split('::').last.downcase }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def image
|
20
|
+
@image ||= MiniMagick::Image.new(@path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def info
|
24
|
+
@info ||= MiniMagick::Image::Info.new(@path)
|
25
|
+
%w{format width height size human_size}.inject({}) { |r,x| r.update(x => @info.cheap_info(x)) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def filename
|
29
|
+
File.basename(@path, ".*")
|
30
|
+
end
|
31
|
+
|
32
|
+
def ext
|
33
|
+
File.extname(@path)
|
34
|
+
end
|
35
|
+
|
36
|
+
def dirname
|
37
|
+
File.dirname(@path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def output_path method
|
41
|
+
@output = Pathname.new(@output).directory? ? "#{@output}/#{filename}_#{method}_#{Time.now.to_i}#{ext}" : @output
|
42
|
+
@output || "#{dirname}/#{filename}_#{method}_#{Time.now.to_i}#{ext}"
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def dir
|
48
|
+
@dir ||= Dir.mktmpdir
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Privatize
|
2
|
+
|
3
|
+
class Pixelate < Image
|
4
|
+
|
5
|
+
def initialize path, options={}
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def normalize n
|
10
|
+
@percentage = n < 51 ? ((n*2)/100.0)*10 : 10 + 25 * ((n-50)/49.0)
|
11
|
+
end
|
12
|
+
|
13
|
+
def process! level=nil
|
14
|
+
tiny = level || 50
|
15
|
+
MiniMagick::Tool::Convert.new do |convert|
|
16
|
+
convert.scale("#{normalize(100 - tiny.to_i)}%")
|
17
|
+
convert.scale("#{info['width']}x#{info['height']}!")
|
18
|
+
convert << @path
|
19
|
+
convert << output_path(tiny)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/privatize.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: privatize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rob allen
|
@@ -55,11 +55,16 @@ dependencies:
|
|
55
55
|
description: This gem pixilates images using rmagick.
|
56
56
|
email:
|
57
57
|
- rob.all3n@gmail
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- privatize
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
62
|
-
-
|
63
|
+
- bin/privatize
|
64
|
+
- lib/privatize.rb
|
65
|
+
- lib/privatize/image.rb
|
66
|
+
- lib/privatize/pixelate.rb
|
67
|
+
- lib/privatize/version.rb
|
63
68
|
- spec/minitest_helper.rb
|
64
69
|
- spec/privatize/image_spec.rb
|
65
70
|
- spec/privatize/pixelate_spec.rb
|
data/spec/files/test.gif
DELETED
Binary file
|