jpreg 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.
Files changed (4) hide show
  1. data/Rakefile +105 -0
  2. data/bin/jpreg +110 -0
  3. data/jpreg.gemspec +70 -0
  4. metadata +48 -0
@@ -0,0 +1,105 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ "0.1"
17
+ end
18
+
19
+ def date
20
+ Date.today.to_s
21
+ end
22
+
23
+ def rubyforge_project
24
+ name
25
+ end
26
+
27
+ def gemspec_file
28
+ "#{name}.gemspec"
29
+ end
30
+
31
+ def gem_file
32
+ "#{name}-#{version}.gem"
33
+ end
34
+
35
+ def replace_header(head, header_name)
36
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
37
+ end
38
+
39
+ #############################################################################
40
+ #
41
+ # Packaging tasks
42
+ #
43
+ #############################################################################
44
+
45
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
46
+ task :release => :build do
47
+ unless `git branch` =~ /^\* master$/
48
+ puts "You must be on the master branch to release!"
49
+ exit!
50
+ end
51
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
52
+ sh "git tag v#{version}"
53
+ sh "git push origin master"
54
+ sh "git push origin v#{version}"
55
+ sh "gem push pkg/#{name}-#{version}.gem"
56
+ end
57
+
58
+ desc "Build #{gem_file} into the pkg directory"
59
+ task :build => :gemspec do
60
+ sh "mkdir -p pkg"
61
+ sh "gem build #{gemspec_file}"
62
+ sh "mv #{gem_file} pkg"
63
+ end
64
+
65
+ desc "Generate #{gemspec_file}"
66
+ task :gemspec => :validate do
67
+ # read spec file and split out manifest section
68
+ spec = File.read(gemspec_file)
69
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
70
+
71
+ # replace name version and date
72
+ replace_header(head, :name)
73
+ replace_header(head, :version)
74
+ replace_header(head, :date)
75
+ #comment this out if your rubyforge_project has a different name
76
+ replace_header(head, :rubyforge_project)
77
+
78
+ # determine file list from git ls-files
79
+ files = `git ls-files`.
80
+ split("\n").
81
+ sort.
82
+ reject { |file| file =~ /^\./ }.
83
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
84
+ map { |file| " #{file}" }.
85
+ join("\n")
86
+
87
+ # piece file back together and write
88
+ manifest = " s.files = %w[\n#{files}\n ]\n"
89
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
90
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
91
+ puts "Updated #{gemspec_file}"
92
+ end
93
+
94
+ desc "Validate #{gemspec_file}"
95
+ task :validate do
96
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
97
+ unless libfiles.empty?
98
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
99
+ exit!
100
+ end
101
+ unless Dir['VERSION*'].empty?
102
+ puts "A `VERSION` file at root level violates Gem best practices."
103
+ exit!
104
+ end
105
+ end
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'fileutils'
5
+
6
+ timestamp = Time.now.strftime(fmt='%F_%Hh-%Mm-%Ss')
7
+
8
+ options = {
9
+ :output => "#{ENV['HOME']}/Desktop/jpreg-#{timestamp}.jpg",
10
+ :quiet => false,
11
+ :times => 5,
12
+ :quality => 40
13
+ }
14
+
15
+ parser = OptionParser.new do |opts|
16
+ opts.version = "0.0.1"
17
+ opts.banner = "Usage: jpreg [-h] [-o /path/to/output] [-q] [-v] FILE"
18
+
19
+ opts.separator ""
20
+ opts.separator " FILES can be listed out, like `file1.jpg file2.jpg`, or it"
21
+ opts.separator " can be a normal shell glob, like `*.jpg`."
22
+
23
+ opts.separator ""
24
+ opts.separator "Options:"
25
+
26
+ opts.on("-o", "--output /path/to/output", "Set the animation's output directory") do |out|
27
+ options[:output] = out
28
+ end
29
+
30
+ opts.on("-v", "--version", "Shows the program version") do
31
+ puts "jpreg " + opts.version
32
+ exit
33
+ end
34
+
35
+ opts.on("-t", "--times 5", "Sets the number of times to run convert") do |times|
36
+ options[:times] = times
37
+ end
38
+
39
+ opts.on("-l", "--level 40", "Sets the compression level") do |level|
40
+ options[:quality] = level
41
+ end
42
+
43
+ opts.on("-q", "--quiet", "Don't print status messages to stdout") do
44
+ options[:quiet] = true
45
+ end
46
+
47
+ opts.on("-h", "--help", "Show this message") do
48
+ puts opts
49
+ exit
50
+ end
51
+ end
52
+
53
+ parser.parse!
54
+ file = ARGV.first
55
+
56
+ unless system("which convert 2>&1 > /dev/null")
57
+ puts "You need to install ImageMagick first.\n\n"
58
+ puts "If you're on a Mac, this should be as easy as:"
59
+ puts " brew install imagemagick"
60
+ exit(1)
61
+ end
62
+
63
+ unless file && file.size != 0
64
+ puts parser.help
65
+ exit(1)
66
+ end
67
+
68
+ file = File.expand_path(file)
69
+
70
+ base_name = File.basename(file, ".*")
71
+ extension = File.extname(file)
72
+ path = File.dirname(file)
73
+ modified_base_name = "#{base_name}2"
74
+
75
+ cmd = ["convert"]
76
+ cmd << file
77
+ cmd << File.join(path, "#{modified_base_name}.tiff")
78
+
79
+ unless system(*cmd)
80
+ puts "Something broke when we were compressing your jpeg. Shit."
81
+ exit(1)
82
+ end
83
+
84
+ options[:times].to_i.times do
85
+
86
+ cmd = ["convert"]
87
+ cmd << "-quality" << options[:quality].to_s
88
+ cmd << File.join(path, "#{modified_base_name}.tiff")
89
+ cmd << File.join(path, "#{modified_base_name}.jpg")
90
+
91
+ unless system(*cmd)
92
+ puts "Something broke when we were compressing your jpeg. Shit."
93
+ exit(1)
94
+ end
95
+
96
+ cmd = ["convert"]
97
+ cmd << File.join(path, "#{modified_base_name}.jpg")
98
+ cmd << File.join(path, "#{modified_base_name}.tiff")
99
+
100
+ unless system(*cmd)
101
+ puts "Something broke when we were compressing your jpeg. Shit."
102
+ exit(1)
103
+ end
104
+
105
+ end
106
+
107
+ FileUtils.mv File.join(path, "#{modified_base_name}.jpg"), options[:output]
108
+ File.delete File.join(path, "#{modified_base_name}.tiff")
109
+
110
+ puts "You now have a handsome jpeg at #{options[:output]}"
@@ -0,0 +1,70 @@
1
+ ## This is the rakegem gemspec template. Make sure you read and understand
2
+ ## all of the comments. Some sections require modification, and others can
3
+ ## be deleted if you don't need them. Once you understand the contents of
4
+ ## this file, feel free to delete any comments that begin with two hash marks.
5
+ ## You can find comprehensive Gem::Specification documentation, at
6
+ ## http://docs.rubygems.org/read/chapter/20
7
+ Gem::Specification.new do |s|
8
+ s.specification_version = 2 if s.respond_to? :specification_version=
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.rubygems_version = '1.3.5'
11
+
12
+ ## Leave these as is they will be modified for you by the rake gemspec task.
13
+ ## If your rubyforge_project name is different, then edit it and comment out
14
+ ## the sub! line in the Rakefile
15
+ s.name = 'jpreg'
16
+ s.version = '0.1'
17
+ s.date = '2013-04-16'
18
+ # s.rubyforge_project = 'jpreg'
19
+
20
+ ## Make sure your summary is short. The description may be as long
21
+ ## as you like.
22
+ s.summary = "Shitty jpeg compression for the masses"
23
+ s.description = "Shitty jpeg compression for the masses"
24
+
25
+ ## List the primary authors. If there are a bunch of authors, it's probably
26
+ ## better to set the email to an email list or something. If you don't have
27
+ ## a custom homepage, consider using your GitHub URL or the like.
28
+ s.authors = ["Josh Kaplan"]
29
+ s.email = 'joshbrentkaplan@gmail.com'
30
+ s.homepage = 'http://www.josh-kaplan.com'
31
+
32
+ # ## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
33
+ # ## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
34
+ # s.require_paths = %w[lib]
35
+
36
+ # ## This sections is only necessary if you have C extensions.
37
+ # s.require_paths << 'ext'
38
+ # s.extensions = %w[ext/extconf.rb]
39
+
40
+ ## If your gem includes any executables, list them here.
41
+ s.executables = ["jpreg"]
42
+
43
+ # ## Specify any RDoc options here. You'll want to add your README and
44
+ # ## LICENSE files to the extra_rdoc_files list.
45
+ # s.rdoc_options = ["--charset=UTF-8"]
46
+ # s.extra_rdoc_files = %w[README LICENSE]
47
+
48
+ ## List your runtime dependencies here. Runtime dependencies are those
49
+ ## that are needed for an end user to actually USE your code.
50
+ # s.add_dependency('DEPNAME', [">= 1.1.0", "< 2.0.0"])
51
+
52
+ ## List your development dependencies here. Development dependencies are
53
+ ## those that are only needed during development
54
+ # s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
55
+
56
+ ## Leave this section as-is. It will be automatically generated from the
57
+ ## contents of your Git repository via the gemspec task. DO NOT REMOVE
58
+ ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
59
+ # = MANIFEST =
60
+ s.files = %w[
61
+ Rakefile
62
+ bin/jpreg
63
+ jpreg.gemspec
64
+ ]
65
+ # = MANIFEST =
66
+
67
+ ## Test files will be grabbed from the file list. Make sure the path glob
68
+ ## matches what you actually use.
69
+ # s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
70
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jpreg
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Kaplan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Shitty jpeg compression for the masses
15
+ email: joshbrentkaplan@gmail.com
16
+ executables:
17
+ - jpreg
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Rakefile
22
+ - bin/jpreg
23
+ - jpreg.gemspec
24
+ homepage: http://www.josh-kaplan.com
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.25
45
+ signing_key:
46
+ specification_version: 2
47
+ summary: Shitty jpeg compression for the masses
48
+ test_files: []