phototrim 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c991d95f75bf97e815c9185d8200f749f0f93d7
4
- data.tar.gz: fda68aa3b135125c9403a437a97f854913f91589
3
+ metadata.gz: 0d1b35e852033c9b8ac0898a0e7e61305b3d3ee2
4
+ data.tar.gz: 30c419f3652204f4e15d69f1993c1bf0ee4f1910
5
5
  SHA512:
6
- metadata.gz: 05ed4272a6af8ea22861d6ff5d2e760e247c467e6ab004171841398bbed201d0f4b3f5391d25de92584a91ea751fbcbbe2c7e073d8e1958efb1030acf1e6cccb
7
- data.tar.gz: 73d5df727782e17230c7a50445de280c2dcb5bbd871d714755d088863dfcd8297dc472692ff566707d53f6fa1076e439b28cddae14c6a2c1071d19e415e0428a
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
- gem 'phototrim'
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`, just do this on your terminal:
34
-
35
- $ phototrim 50, ~/memories/goa_photos
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
 
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'phototrim'
4
- puts Phototrim.trim(ARGV[0].to_i, ARGV[1], ARGV[2])
4
+
5
+ trimmer = Phototrimmer.new ARGV[0].to_i, ARGV[1], ARGV[2]
6
+ puts trimmer.main
@@ -5,29 +5,48 @@ require 'phototrim/version'
5
5
  require 'RMagick'
6
6
  include Magick
7
7
 
8
- class Phototrim
9
- def self.trim(max_size, src_path, dest_path=nil)
10
- unless dest_path
11
- dest_path = src_path
12
- end
13
- Dir.foreach src_path do |src_object|
14
- unless src_object == "." or src_object == ".." or File.extname(src_object) == ".svg"
15
- if File.directory? File.join(src_path, src_object)
16
- puts "Processing images within #{src_object}..."
17
- system "mkdir -p #{File.join(dest_path, src_object)}"
18
- trim(max_size, File.join(src_path, src_object), File.join(dest_path, src_object))
19
- else
20
- puts "Processing file #{src_object}"
21
- victim = ImageList.new(File.join(src_path, src_object))
22
- if victim.columns > max_size
23
- puts "#{src_object} is beyond #{max_size}px wide, scaling down.."
24
- victim = victim.scale(max_size.to_f/victim.columns)
25
- puts "Scaled down #{src_object}"
26
- victim.write(File.join(dest_path, src_object))
27
- end
28
- end
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
@@ -1,3 +1,3 @@
1
1
  module PhototrimVersion
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phototrim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarup Banskota