phototrim 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -4
- data/bin/phototrim +3 -1
- data/lib/phototrim.rb +41 -22
- data/lib/phototrim/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d1b35e852033c9b8ac0898a0e7e61305b3d3ee2
|
4
|
+
data.tar.gz: 30c419f3652204f4e15d69f1993c1bf0ee4f1910
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6283ca3399cf86a1eebd4ec0756583b57c7d7946d6900d765d25427750895af0ebe47070ced8ed01a4da0bc2a28abc2d02ab06568085f3782f0d2163b67b94f7
|
7
|
+
data.tar.gz: 5b4797aec4db31d12cbca5552ade843890854921d3a32ea4034517a701488d58b7e7a9f3341a71a8387d01e81b1b8328eb2ea022008390e560af036ebf102a57
|
data/README.md
CHANGED
@@ -4,9 +4,16 @@ Simple gem that helps with resizing a bunch of photos
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
+
Phototrim has `rmagick` as dependency and it requires MagicWand to run. Depending on your distribution, you'll have to install MagickWand headers first:
|
8
|
+
|
9
|
+
|
10
|
+
$ sudo apt-get install libmagickwand-dev
|
11
|
+
$ sudo yum install ImageMagick-devel
|
12
|
+
|
13
|
+
|
7
14
|
Add this line to your application's Gemfile:
|
8
15
|
|
9
|
-
|
16
|
+
gem 'phototrim'
|
10
17
|
|
11
18
|
And then execute:
|
12
19
|
|
@@ -30,9 +37,10 @@ The `Phototrim` class makes available to you the `trim max_size, root_dir` funct
|
|
30
37
|
|
31
38
|
```
|
32
39
|
|
33
|
-
Phototrim also shows up as a terminal command you can use. Assuming you want to *trim* photos to a width of 50px within `~/memories/goa_photos`,
|
34
|
-
|
35
|
-
$ phototrim 50
|
40
|
+
Phototrim also shows up as a terminal command you can use. Assuming you want to *trim* photos to a width of 50px within `~/memories/goa_photos`, you can use the `phototrim` command. If you like, there's also a destination option.
|
41
|
+
|
42
|
+
$ phototrim 50 ~/memories/goa_photos
|
43
|
+
$ phototrim 640 ~/memories/goa_photos ~/Pictures/Goa
|
36
44
|
|
37
45
|
Boom! :)
|
38
46
|
|
data/bin/phototrim
CHANGED
data/lib/phototrim.rb
CHANGED
@@ -5,29 +5,48 @@ require 'phototrim/version'
|
|
5
5
|
require 'RMagick'
|
6
6
|
include Magick
|
7
7
|
|
8
|
-
class
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
8
|
+
class Phototrimmer
|
9
|
+
|
10
|
+
def initialize max_size, src_path, dest_path=nil
|
11
|
+
@size = max_size
|
12
|
+
@src = src_path
|
13
|
+
@dest = dest_path.nil? ? @src : dest_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def main
|
17
|
+
system("mkdir -p #{@dest}")
|
18
|
+
File.directory? @src ? wrangle : trim
|
19
|
+
end
|
20
|
+
|
21
|
+
def wrangle
|
22
|
+
Dir.foreach @src do |object|
|
23
|
+
next if ignored_type object
|
24
|
+
subtrimmer = Phototrimmer.new @size,
|
25
|
+
File.join(@src, object),
|
26
|
+
File.join(@dest, object)
|
27
|
+
if File.directory? File.join @src, object
|
28
|
+
puts "Processing images within #{object}..."
|
29
|
+
system "mkdir -p #{ File.join @dest, object }"
|
30
|
+
subtrimmer.wrangle
|
31
|
+
else
|
32
|
+
subtrimmer.trim
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
32
|
-
end
|
33
36
|
|
37
|
+
def trim
|
38
|
+
puts "Processing file #{@src}"
|
39
|
+
victim = ImageList.new @src
|
40
|
+
if victim.columns > @size
|
41
|
+
puts "#{@src} is beyond #{@size}px wide, scaling down.."
|
42
|
+
victim = victim.scale @size.to_f/victim.columns
|
43
|
+
puts "Scaled down #{@src}"
|
44
|
+
victim.write @dest
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def ignored_type object
|
49
|
+
%w[. ..].include? object or %w[.svg].include? File.extname object
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/lib/phototrim/version.rb
CHANGED