sunny-crush 0.1
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.
- data/bin/crush +33 -0
- data/lib/crush.rb +25 -0
- metadata +54 -0
data/bin/crush
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env ruby -W0
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require File.dirname(__FILE__) + '/../lib/crush'
|
|
5
|
+
|
|
6
|
+
include FileUtils
|
|
7
|
+
include Crush
|
|
8
|
+
|
|
9
|
+
# handle args
|
|
10
|
+
dir = ARGV[0]
|
|
11
|
+
abort "Usage: #{File.basename($0)} dir" if dir.nil?
|
|
12
|
+
|
|
13
|
+
# find files
|
|
14
|
+
files = []
|
|
15
|
+
cd(dir) do
|
|
16
|
+
search = File.join('**', '*')
|
|
17
|
+
files = Dir[search]
|
|
18
|
+
files.reject! { |f| File.directory?(f) }
|
|
19
|
+
end
|
|
20
|
+
files.map! { |f| File.expand_path(File.join(dir, f)) }
|
|
21
|
+
abort "No files found in #{dir}" if files.empty?
|
|
22
|
+
|
|
23
|
+
# loop and transform
|
|
24
|
+
files.each do |file|
|
|
25
|
+
case file
|
|
26
|
+
when /\.png$/
|
|
27
|
+
pngcrush(file) or optipng(file)
|
|
28
|
+
when /\.jpe?g$/
|
|
29
|
+
jpegtran(file)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
data/lib/crush.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'tempfile'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
|
|
6
|
+
module Crush
|
|
7
|
+
def pngcrush(old_file)
|
|
8
|
+
tmp_file = Tempfile.new('crush_pngcrush').path
|
|
9
|
+
`pngcrush '#{old_file}' '#{tmp_file}'`
|
|
10
|
+
return false if $?.exitstatus != 0
|
|
11
|
+
FileUtils::cp tmp_file, old_file
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def optipng(old_file)
|
|
15
|
+
`optipng '#{old_file}'`
|
|
16
|
+
$?.exitstatus == 0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def jpegtran(old_file)
|
|
20
|
+
tmp_file = Tempfile.new('crush_jpegtran').path
|
|
21
|
+
`jpegtran -copy none -optimize '#{old_file}' > '#{tmp_file}'`
|
|
22
|
+
return false if $?.exitstatus != 0
|
|
23
|
+
FileUtils::cp tmp_file, old_file
|
|
24
|
+
end
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sunny-crush
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: "0.1"
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sunny Ripert
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-10-13 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Crushes png and jpg images by removing their headers and usually unnessecary data for the web.
|
|
17
|
+
email: negatif@gmail.com
|
|
18
|
+
executables:
|
|
19
|
+
- crush
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files: []
|
|
23
|
+
|
|
24
|
+
files:
|
|
25
|
+
- lib/crush.rb
|
|
26
|
+
- bin/crush
|
|
27
|
+
has_rdoc: false
|
|
28
|
+
homepage: http://github.com/sunny/crush
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: "0"
|
|
39
|
+
version:
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: "0"
|
|
45
|
+
version:
|
|
46
|
+
requirements: []
|
|
47
|
+
|
|
48
|
+
rubyforge_project:
|
|
49
|
+
rubygems_version: 1.2.0
|
|
50
|
+
signing_key:
|
|
51
|
+
specification_version: 2
|
|
52
|
+
summary: CLI to remove headers from png and jpg files
|
|
53
|
+
test_files: []
|
|
54
|
+
|