rsips 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/rsips.rb +1 -1
- data/lib/rsips/image.rb +13 -12
- data/lib/rsips/sips.rb +6 -6
- metadata +2 -2
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
## Ruby sips
|
2
|
-
`sips` is an extremely fast image processing utility that ships with OS X. It
|
2
|
+
`sips` is an extremely fast image processing utility that ships with OS X. It's not nearly as robust as ImageMagick but therein lies its beauty.
|
3
3
|
|
4
|
-
**rsips** seeks to expand on `sips`
|
4
|
+
**rsips** seeks to expand on `sips` and make it fun to use in everyday scripting, Rakefiles, static compilers, etc.
|
5
5
|
|
6
6
|
## Install
|
7
7
|
|
data/lib/rsips.rb
CHANGED
data/lib/rsips/image.rb
CHANGED
@@ -3,21 +3,22 @@ module Rsips
|
|
3
3
|
class Image
|
4
4
|
|
5
5
|
include Rsips::Sips
|
6
|
-
|
7
|
-
attr_reader :width, :height
|
8
|
-
|
6
|
+
|
9
7
|
def initialize(img)
|
10
|
-
@img
|
11
|
-
|
12
|
-
|
8
|
+
@img = img
|
9
|
+
|
10
|
+
properties.each do |k, v|
|
11
|
+
instance_variable_set("@#{k}", v)
|
12
|
+
instance_eval %{
|
13
|
+
def #{k}
|
14
|
+
instance_variable_get("@#{k}")
|
15
|
+
end
|
16
|
+
}
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
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
20
|
def resize!(long_edge)
|
19
21
|
vertical? ? resample(:height, long_edge) : resample(:width, long_edge)
|
20
|
-
self
|
21
22
|
end
|
22
23
|
|
23
24
|
def to_jpg!(compression="default")
|
@@ -30,11 +31,11 @@ module Rsips
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def orientation
|
33
|
-
|
34
|
+
vertical? ? 'vertical' : 'horizontal'
|
34
35
|
end
|
35
36
|
|
36
37
|
def vertical?
|
37
|
-
@
|
38
|
+
@pixelHeight.to_i > @pixelWidth.to_i # temporarily coerce here
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/rsips/sips.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Rsips::Sips
|
2
2
|
|
3
|
-
def
|
4
|
-
sips
|
3
|
+
def properties
|
4
|
+
Hash[`sips -g all '#{@img}'`.split("\n")[1..-1].map { |i| i.strip.split(": ") }]
|
5
5
|
end
|
6
|
-
|
7
|
-
def
|
8
|
-
|
6
|
+
|
7
|
+
def resample(dimension, pixels)
|
8
|
+
sips "--resample#{dimension.capitalize} #{pixels} '#{@img}'"
|
9
9
|
end
|
10
10
|
|
11
11
|
def format(type, options={})
|
@@ -16,7 +16,7 @@ module Rsips::Sips
|
|
16
16
|
else type
|
17
17
|
end
|
18
18
|
new_image = replace_ext(@img, new_ext)
|
19
|
-
sips "-s format #{type} -s formatOptions #{options} #{@img} --out #{new_image}"
|
19
|
+
sips "-s format #{type} -s formatOptions #{options} '#{@img}' --out #{new_image}"
|
20
20
|
end
|
21
21
|
|
22
22
|
private
|
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.1.0
|
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-17 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|