picpacput 0.0.1b

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 Daniel P. Clark & 6ft Dan(TM)
4
+
5
+ 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:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ 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.
10
+
data/README ADDED
@@ -0,0 +1,2 @@
1
+ The purpose of PicPacPut is to shrink images in bulk and then hand them
2
+ off to something else; as in a service or into a compressed file.
@@ -0,0 +1,3 @@
1
+ class PicPacPut
2
+ VERSION = "0.0.1b"
3
+ end
data/lib/picpacput.rb ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'find'
4
+ require 'tmpdir' # Dir.tmpdir
5
+ require 'rubygems'
6
+ require 'RMagick'
7
+
8
+
9
+ class PicPacPut
10
+ attr_accessor :folder, :extension, :scale_by, :outfolder, :ext_types
11
+
12
+ def initialize( opts = {} )
13
+ options = {
14
+ :folder => ('.'+File::SEPARATOR),
15
+ :extension => "*.JPG",
16
+ :scale_by => 0.05,
17
+ :outfolder => ('resized'+File::SEPARATOR),
18
+ :ext_types => ["png","PNG","jpg","JPG","jpeg","JPEG","gif","GIF","bmp","BMP"]
19
+ }.merge(opts)
20
+ @folder = options[:folder]
21
+ @extension = options[:extension]
22
+ @scale_by = options[:scale_by]
23
+ @outfolder = options[:outfolder]
24
+ @ext_types = options[:ext_types]
25
+ Dir.mkdir(@outfolder) unless File.exists?(@outfolder)
26
+ end
27
+
28
+ def thumbOne(image_in = @folder + @extension )
29
+ puts "STATUS #{image_in}"
30
+ if File.exists?(image_in)
31
+ image = Magick::Image.read(image_in).first
32
+ new_image = image.scale(@scale_by)
33
+ if not File.exists?(@outfolder + image.filename.split(File::SEPARATOR)[-1])
34
+ new_image.write(@outfolder + image.filename.split(File::SEPARATOR)[-1])
35
+ else
36
+ puts "File #{ @outfolder + image.filename } already exists! Please change your output."
37
+ end
38
+ [image,new_image].each { |img| img.destroy! } # IMPORTANT!!!
39
+ else
40
+ raise "File #{image_in} does not exist!"
41
+ end
42
+ end
43
+
44
+ def thumbit
45
+ if !!@extension["*"] # blob operator
46
+ Dir.glob("#{@folder + @extension}") do |f|
47
+ thumbOne(f)
48
+ end
49
+ else
50
+ thumbOne
51
+ end
52
+ end
53
+
54
+ def thumbDirDown
55
+ dirList = []
56
+ Find.find(@folder) do |f|
57
+ if !!f[@outfolder]
58
+ next
59
+ end
60
+ @ext_types.each do |type|
61
+ ext = f.match(".#{type}")
62
+ if not ext.nil?
63
+ dirList << f
64
+ thumbOne(f)# maybe CWD + directory
65
+ end
66
+ end
67
+ end
68
+ dirList
69
+ end
70
+ end
71
+
72
+ picpacput = PicPacPut.new
73
+ picpacput.thumbDirDown
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: picpacput
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1b
5
+ prerelease: 5
6
+ platform: ruby
7
+ authors:
8
+ - Daniel P. Clark / 6ftDan(TM)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rmagick
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.13.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.13.0
30
+ description: PicPacPut - Bulk shrink images and pack them.
31
+ email: webmaster@6ftdan.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files:
35
+ - README
36
+ files:
37
+ - lib/picpacput.rb
38
+ - lib/picpacput/version.rb
39
+ - README
40
+ - LICENSE
41
+ homepage: http://www.github.com/danielpclark/PicPacPut
42
+ licenses:
43
+ - The MIT License (MIT)
44
+ post_install_message: PicPacPut - Bulk shrink and package those images.
45
+ rdoc_options:
46
+ - --main
47
+ - README
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>'
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.1
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.24
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Bulk shrink images and package them.
68
+ test_files: []