magick_minimalistic 0.1.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.
- checksums.yaml +7 -0
- data/README.md +18 -0
- data/lib/magick_minimalistic/option.rb +15 -0
- data/lib/magick_minimalistic/sanitize.rb +44 -0
- data/lib/magick_minimalistic/shell.rb +5 -0
- data/lib/magick_minimalistic.rb +34 -0
- data/test/test_magick_minimalistic.rb +15 -0
- metadata +51 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '098fdd7b61bff71c1fef1456d54ea17100caa15f929d050258ac45e54ce2ab0c'
|
|
4
|
+
data.tar.gz: 5eb8ea0cc80436530f29e6a0b33de0985d6abcde72fa5f0e7e2fa227c420ac50
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b2f72bc22cd967f9639180846b604aca9f59ead6960d6d21cdada1bf3dfafa20c422c7ed4f8658ceef40fec29981306cff3283835dae003b2725c97be0840bbb
|
|
7
|
+
data.tar.gz: c0d5b6592ae0d721660fc41daa6b62f4eca837f4748a6c05ebfb423f8d52089346f98a4ea6f03f5c06a78b8689b612c7960044a8228d47146851c2de3f00efc8
|
data/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Magick Minimalistic
|
|
2
|
+
|
|
3
|
+
A ruby wrapper for ImageMagick command line.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
Imagemagick command-line tool has to be installed. You can check their official
|
|
8
|
+
website documentation: [website]("www.imagemagick.org")
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add the gem to your Gemfile:
|
|
13
|
+
|
|
14
|
+
`gem 'magick_minimalistic'`
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Here's a basic example:
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module Sanitize
|
|
2
|
+
def self.filename(file, type)
|
|
3
|
+
loop do
|
|
4
|
+
return file if type && file.is_a?(String) && File.exist?(file)
|
|
5
|
+
return file if !type && file.is_a?(String) && file.length > 0
|
|
6
|
+
puts "The file -> #{file} <- doesn't exist or is not a String!"
|
|
7
|
+
puts 'Please write a proper filename'
|
|
8
|
+
file = gets.chomp
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.attributes(attrs)
|
|
13
|
+
config = ""
|
|
14
|
+
attrs.each do |key, value|
|
|
15
|
+
unless /^(gravity|crop|resize)$/ =~ key
|
|
16
|
+
puts 'The key is not a valid one'
|
|
17
|
+
next
|
|
18
|
+
end
|
|
19
|
+
value = type(key, value) if /^(gravity)$/ =~ key
|
|
20
|
+
value = geometry(key, value) if /^(crop|resize)$/ =~ key
|
|
21
|
+
config += Option.send(key, value)
|
|
22
|
+
end
|
|
23
|
+
config
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.geometry(key, value)
|
|
27
|
+
loop do
|
|
28
|
+
return value if value.is_a?(String) && (/^\d+x\d+$/ =~ value || /^\d+%$/ =~ value)
|
|
29
|
+
puts "The value (#{value}) for the key (#{key}) is not properly formed!"
|
|
30
|
+
puts 'Write a valid value'
|
|
31
|
+
value = gets.chomp
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.type(key, value)
|
|
36
|
+
loop do
|
|
37
|
+
return value if value.is_a?(String) &&
|
|
38
|
+
/^(NorthWest|North|NortEast|West|Center|East|SouthWest|South|SouthEast)$/ =~ value
|
|
39
|
+
puts "The value (#{value}) for the key (#{key}) is not properly formed!"
|
|
40
|
+
puts 'Write a valid value'
|
|
41
|
+
value = gets.chomp
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module MagickMinimalistic
|
|
2
|
+
class Configurator
|
|
3
|
+
require_relative './magick_minimalistic/option'
|
|
4
|
+
require_relative './magick_minimalistic/sanitize'
|
|
5
|
+
require_relative './magick_minimalistic/shell'
|
|
6
|
+
|
|
7
|
+
include Option
|
|
8
|
+
include Sanitize
|
|
9
|
+
include Shell
|
|
10
|
+
|
|
11
|
+
attr_accessor :source, :config, :destiny
|
|
12
|
+
|
|
13
|
+
def initialize(params = {})
|
|
14
|
+
@source = params[:source]
|
|
15
|
+
@config = params[:config] ? params[:config] : {}
|
|
16
|
+
@destiny = params[:destiny]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def run
|
|
20
|
+
super(command)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def command
|
|
24
|
+
cmd = 'magick '
|
|
25
|
+
puts 'Checking source file...'
|
|
26
|
+
cmd += "#{Sanitize::filename(source, true)} "
|
|
27
|
+
puts 'Checking attributes...'
|
|
28
|
+
cmd += "#{Sanitize::attributes(config)} "
|
|
29
|
+
puts 'Checking destiny file...'
|
|
30
|
+
cmd += "#{Sanitize::filename(destiny, false)}"
|
|
31
|
+
cmd
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'minitest/autorun'
|
|
2
|
+
require_relative '../magick_minimalistic.rb'
|
|
3
|
+
|
|
4
|
+
class TestMagickMinimalistic < MiniTest::Test
|
|
5
|
+
def setup
|
|
6
|
+
@empty = MagickMinimalistic::Configurator.new
|
|
7
|
+
@correct_src = MagickMinimalistic::Configurator.new({source: 'kirby-up.png'})
|
|
8
|
+
@correct_src_dst = MagickMinimalistic::Configurator.new({source: 'kirby-up.png', destiny: 'kirby.png'})
|
|
9
|
+
@wrong_attrs = MagickMinimalistic::Configurator.new({source: 'kirby-up.png', config: {gravities: 'Center', crops: "50%", resiz: "100x100"}, destiny: 'kirby.png'})
|
|
10
|
+
@correct = im = MagickMinimalistic::Configurator.new({source: 'kirby-up.png', config: {gravity: 'Center', crop: "50%", resize: "100x100"}, destiny: 'kirby.png'})
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_that_empty_initialization_request_everything
|
|
14
|
+
assert_
|
|
15
|
+
|
metadata
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: magick_minimalistic
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- YourSouLisMine
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-02-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: |2
|
|
14
|
+
Magick Minimalistic allows you to use some commands from the imagemagick's
|
|
15
|
+
shell package with Ruby's hashes.
|
|
16
|
+
email: precichysim@gmail.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/magick_minimalistic.rb
|
|
23
|
+
- lib/magick_minimalistic/option.rb
|
|
24
|
+
- lib/magick_minimalistic/sanitize.rb
|
|
25
|
+
- lib/magick_minimalistic/shell.rb
|
|
26
|
+
- test/test_magick_minimalistic.rb
|
|
27
|
+
homepage: https://github.com/YourSouLi5Mine/magick_minimalistic
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata: {}
|
|
31
|
+
post_install_message:
|
|
32
|
+
rdoc_options: []
|
|
33
|
+
require_paths:
|
|
34
|
+
- lib
|
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: '0'
|
|
45
|
+
requirements:
|
|
46
|
+
- You must have ImageMagick installed
|
|
47
|
+
rubygems_version: 3.0.2
|
|
48
|
+
signing_key:
|
|
49
|
+
specification_version: 4
|
|
50
|
+
summary: Image manipulator with ImageMagick
|
|
51
|
+
test_files: []
|