rsips 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -0
- data/lib/rsips/batch.rb +7 -0
- data/lib/rsips/image.rb +24 -14
- data/lib/rsips/sips.rb +31 -0
- data/lib/rsips.rb +13 -2
- data/rsips.gemspec +1 -1
- metadata +4 -3
- data/lib/rsips/version.rb +0 -3
data/Rakefile
CHANGED
data/lib/rsips/batch.rb
ADDED
data/lib/rsips/image.rb
CHANGED
@@ -1,30 +1,40 @@
|
|
1
1
|
module Rsips
|
2
|
+
|
2
3
|
class Image
|
4
|
+
|
5
|
+
include Rsips::Sips
|
3
6
|
|
4
7
|
attr_reader :width, :height
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@img = img
|
8
|
+
|
9
|
+
def initialize(img)
|
10
|
+
@img = img # TODO: strip out blank spaces
|
8
11
|
@width = get_dimension :width
|
9
12
|
@height = get_dimension :height
|
10
13
|
end
|
11
14
|
|
12
|
-
|
15
|
+
# TODO: how do you know it's long edge?
|
16
|
+
# pass in both long and short edges with
|
17
|
+
# short edge being optional
|
18
|
+
def resize!(long_edge)
|
13
19
|
vertical? ? resample(:height, long_edge) : resample(:width, long_edge)
|
20
|
+
self
|
14
21
|
end
|
15
|
-
|
16
|
-
def
|
17
|
-
|
22
|
+
|
23
|
+
def to_jpg!(compression="default")
|
24
|
+
dup.to_jpg
|
25
|
+
FileUtils.rm @img
|
18
26
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
|
28
|
+
def to_jpg(compression="default")
|
29
|
+
format :jpeg, :compression => compression
|
30
|
+
end
|
31
|
+
|
32
|
+
def orientation
|
33
|
+
@img.vertical? ? 'vertical' : 'horizontal'
|
24
34
|
end
|
25
35
|
|
26
|
-
def
|
27
|
-
|
36
|
+
def vertical?
|
37
|
+
@height > @width
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
data/lib/rsips/sips.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rsips::Sips
|
2
|
+
|
3
|
+
def resample(dimension, pixels)
|
4
|
+
sips "--resample#{dimension.capitalize} #{pixels} #{@img}"
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_dimension(dimension)
|
8
|
+
`sips -g pixel#{dimension.capitalize} #{@img}`.chomp.slice(/\d+$/).to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
def format(type, options={})
|
12
|
+
options = options[:compression] || "default"
|
13
|
+
new_ext = case type
|
14
|
+
when :jpeg then "jpg"
|
15
|
+
when :tiff then "tif"
|
16
|
+
else type
|
17
|
+
end
|
18
|
+
new_image = replace_ext(@img, new_ext)
|
19
|
+
sips "-s format #{type} -s formatOptions #{options} #{@img} --out #{new_image}"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def sips(command)
|
25
|
+
system "sips #{command}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def replace_ext(filename, new_ext)
|
29
|
+
filename.split('.')[0..-2].push(new_ext).join('.')
|
30
|
+
end
|
31
|
+
end
|
data/lib/rsips.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Load dependencies
|
2
|
+
require 'fileutils'
|
3
3
|
|
4
|
+
# Add lib/rsips to load path
|
4
5
|
$:.unshift File.expand_path(File.dirname(__FILE__))
|
5
6
|
|
7
|
+
# rsips
|
8
|
+
module Rsips
|
9
|
+
|
10
|
+
# Current version of rsips
|
11
|
+
VERSION = '0.0.2'
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'rsips/sips'
|
6
16
|
require 'rsips/image'
|
17
|
+
require 'rsips/batch'
|
data/rsips.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsips
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-12 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -23,8 +23,9 @@ files:
|
|
23
23
|
- README.md
|
24
24
|
- Rakefile
|
25
25
|
- lib/rsips.rb
|
26
|
+
- lib/rsips/batch.rb
|
26
27
|
- lib/rsips/image.rb
|
27
|
-
- lib/rsips/
|
28
|
+
- lib/rsips/sips.rb
|
28
29
|
- rsips.gemspec
|
29
30
|
homepage: http://github.com/jdlich/rsips
|
30
31
|
licenses: []
|
data/lib/rsips/version.rb
DELETED