Skip to content

Commit

Permalink
Compress JPG to 80% quality.
Browse files Browse the repository at this point in the history
Add support for --acl option.
  • Loading branch information
Papipo committed Jun 26, 2017
1 parent 19d25dd commit 353a999
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/s3imageoptim/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
require "s3imageoptim/command"

class S3imageoptim::CLI < Thor

register S3imageoptim::Command, "optim", "optim BUCKET", "Get all files from a S3 BUCKET and put them back compressed"
register S3imageoptim::Command, "optim", "optim BUCKET [--acl=public|private]", "Get all files from a S3 BUCKET and put them back compressed"

private
def exit_on_failure?
Expand Down
13 changes: 11 additions & 2 deletions lib/s3imageoptim/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class S3imageoptim::Command < Thor::Group
argument :bucket, desc: "S3 Bucket to compress"
class_option :acl, enum: %w(public private), default: "public"

desc "Get all files from BUCKET and put them back compressed"
def get
s3cmd("get --exclude '*' --rinclude '\.(#{extensions("|")})$' --recursive #{bucket} #{tmpdir}") do |error|
Expand All @@ -17,11 +19,18 @@ def get
end

def compress
ImageOptim.new(pngout: false, svgo: false).optimize_images!(local_files)
ImageOptim.new(
svgo: false,
pngout: false,
jpegoptim: {
allow_lossy: true,
max_quality: 80
}
).optimize_images!(local_files)
end

def put
s3cmd("sync #{tmpdir}/ #{bucket}") do |error|
s3cmd("sync --acl-#{options[:acl]} #{tmpdir}/ #{bucket}") do |error|
abort("An error ocurred while putting the files: #{error}")
end
end
Expand Down

0 comments on commit 353a999

Please sign in to comment.