Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

create gem

  • Loading branch information...
commit 6076cfca16592d2549060c0ba866ffd14edb7149 1 parent 3dfea70
@oelbrenner oelbrenner authored
View
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Jason Fraley
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
43 README.md
@@ -1,4 +1,41 @@
-smushkid
-========
-A command utility that compresses images in the background for our customers.
+# smushkid #
+
+--------------------------
+
+A command utility that compresses images in the background for our customers.
+Outputs a JSON file with detailed information on the conversion, and a .txt
+file listing the files processed.
+
+### Installation
+
+ $ gem install smushkid
+
+### Usage
+
+ $ smushkid path/to/directory desired_quality
+
+### Example
+
+ $ smushkid wp-content/uploads 75
+
+
+directory = directory you want to process JPG images in
+
+desired_quality = JPG compression value ( or % quality )
+
+### information:
+
+this script strips metadata from the source image, then quantizies the color
+map at 32 bit, and compresses to desired quality level.
+
+#### Information about RMagick here:
+
+<http://www.imagemagick.org/RMagick/doc/usage.html>
+
+#### Read more about image quantization:
+<http://www.imagemagick.org/Usage/quantize/#colors>
+
+<http://www.imagemagick.org/RMagick/doc/ilist.html#quantize>
+
+<http://www.impulseadventure.com/photo/jpeg-quantization.html>
View
2  bin/smushkid
@@ -0,0 +1,2 @@
+#!/usr/bin/env ruby
+require 'smushkid'
View
27 bin/smushkid.rb → lib/smushkid.rb 100644 → 100755
@@ -1,10 +1,14 @@
#!/usr/bin/env ruby
-
require 'find'
require 'RMagick'
require 'json'
+
+path = ARGV[0]
+quality = ARGV[1]
+
totalsavings = 0
-Find.find('uploads') do |file|
+File.open("images_processed.json", "a+") { |f| f << "{ \"image_results\" : [ " }
+Find.find(path) do |file|
pattern = '**' '/' '*.jpg'
if File.fnmatch(pattern, file, File::FNM_CASEFOLD)
puts "matched: #{file}"
@@ -22,11 +26,9 @@
}
target_file = File.dirname(file) + "/" + "smaller-" + File.basename(file)
simg.strip!
+ simg.quantize 32
simg.write(target_file) do
- # maybe doing this wrong? seems to make file bigger
- # something with unknow pixel density
- #self.compression = Magick::LosslessJPEGCompression
- self.quality = 90
+ self.quality = quality.to_i
end
timg = Magick::Image::read(target_file).first
target_image = {
@@ -41,26 +43,29 @@
'ppi' => timg.units
}
@savings = source_image['filesize'] - target_image['filesize']
- image_results = { 'filename' => file, 'savings' => @savings, 'before' => source_image, 'after' => target_image }
+ image_results = { "filename" => file, "savings" => @savings, "before" => source_image, "after" => target_image }
puts "savings:"
puts @savings
if @savings < 0
@savings = 0
- puts "no space savings acheived deleting #{target_image}"
+ puts "no space savings acheived deleting #{target_file}"
File.delete(target_file)
else
puts "space savings! replacing with #{simg}"
puts "move #{target_file} to #{file}"
File.rename target_file, file
end
- File.open("imageprocessed.json", "a+") { |f| f << image_results.to_json}
- File.open("savings.txt", "a+") { |f| f << @savings.to_s + "\n"}
+ File.open("images_processed.json", "a+") { |f| f << image_results.to_json + ','}
+ File.open("images_processed_list.txt", "a+") { |f| f << file + "\n"}
else
puts "no match: #{file}"
end
totalsavings = totalsavings + @savings.to_i
- puts "RUNNING TOTAL"
+ puts "Running total savings (in bytes):"
puts totalsavings
end
+File.open("images_processed.json", "a+") { |f| f << "]}" }
+
+
View
12 smushkid.gemspec
@@ -0,0 +1,12 @@
+Gem::Specification.new do |s|
+ s.name = 'smushkid'
+ s.version = '0.0.1'
+ s.date = '2012-08-21'
+ s.summary = "Compress and Optimize JPG images"
+ s.description = "Compress and optimize JPG images with RMagick"
+ s.authors = ["Jason Fraley"]
+ s.email = ["whiskeytangoeng@gmail.com"]
+ s.homepage = "http://github.com/zippykid/smushkid"
+ s.files = ["lib/smushkid.rb"]
+ s.executables << 'smushkid'
+end
Please sign in to comment.
Something went wrong with that request. Please try again.