Class: PicPacPut
- Inherits:
-
Object
- Object
- PicPacPut
- Defined in:
- lib/picpacput.rb,
lib/picpacput/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#ext_types ⇒ Object
Returns the value of attribute ext_types.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#folder ⇒ Object
Returns the value of attribute folder.
-
#outfolder ⇒ Object
Returns the value of attribute outfolder.
-
#recursive ⇒ Object
Returns the value of attribute recursive.
-
#scale_by ⇒ Object
Returns the value of attribute scale_by.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ PicPacPut
constructor
A new instance of PicPacPut.
- #pac ⇒ Object
- #pic ⇒ Object
- #thumbit ⇒ Object
- #thumbOne(image_in = @folder + @extension) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ PicPacPut
Returns a new instance of PicPacPut.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/picpacput.rb', line 13 def initialize( opts = {} ) = { :folder => ('.'+File::SEPARATOR), :recursive => true, :extension => "*.JPG", :scale_by => 0.05, :zipFile => 'output.zip', :outfolder => ('resized'+File::SEPARATOR), :ext_types => ["png","PNG","jpg","JPG","jpeg","JPEG","gif","GIF","bmp","BMP"] }.merge(opts) @folder = [:folder] @recursive = [:recursive] @extension = [:extension] @scale_by = [:scale_by] @outfolder = [:outfolder] @zipFile = [:zipFile] @ext_types = [:ext_types] Dir.mkdir(@outfolder) unless File.exists?(@outfolder) end |
Instance Attribute Details
#ext_types ⇒ Object
Returns the value of attribute ext_types.
11 12 13 |
# File 'lib/picpacput.rb', line 11 def ext_types @ext_types end |
#extension ⇒ Object
Returns the value of attribute extension.
11 12 13 |
# File 'lib/picpacput.rb', line 11 def extension @extension end |
#folder ⇒ Object
Returns the value of attribute folder.
11 12 13 |
# File 'lib/picpacput.rb', line 11 def folder @folder end |
#outfolder ⇒ Object
Returns the value of attribute outfolder.
11 12 13 |
# File 'lib/picpacput.rb', line 11 def outfolder @outfolder end |
#recursive ⇒ Object
Returns the value of attribute recursive.
11 12 13 |
# File 'lib/picpacput.rb', line 11 def recursive @recursive end |
#scale_by ⇒ Object
Returns the value of attribute scale_by.
11 12 13 |
# File 'lib/picpacput.rb', line 11 def scale_by @scale_by end |
Instance Method Details
#pac ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/picpacput.rb', line 79 def pac Zip::ZipFile.open( @outfolder + File::SEPARATOR + @zipFile, Zip::ZipFile::CREATE) do |zipfile| Dir.glob( @outfolder + File::SEPARATOR + '*' ).each do |filename| filename.gsub!(File::SEPARATOR*2, File::SEPARATOR) if File.directory?(filename) or !!filename[@zipFile] next end zipfile.add(filename, filename) end end end |
#pic ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/picpacput.rb', line 59 def pic if not @recursive return thumbit end dirList = [] Find.find(@folder) do |f| if !!f[@outfolder] next end @ext_types.each do |type| ext = f.match(".#{type}") if not ext.nil? dirList << f thumbOne(f)# maybe CWD + directory end end end dirList end |
#thumbit ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/picpacput.rb', line 49 def thumbit if !!@extension["*"] # blob operator Dir.glob("#{@folder + @extension}") do |f| thumbOne(f) end else thumbOne end end |
#thumbOne(image_in = @folder + @extension) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/picpacput.rb', line 33 def thumbOne(image_in = @folder + @extension ) puts "STATUS #{image_in}" if File.exists?(image_in) image = Magick::Image.read(image_in).first new_image = image.scale(@scale_by) if not File.exists?(@outfolder + image.filename.split(File::SEPARATOR)[-1]) new_image.write(@outfolder + image.filename.split(File::SEPARATOR)[-1]) else puts "File #{ @outfolder + image.filename } already exists! Please change your output." end [image,new_image].each { |img| img.destroy! } # IMPORTANT!!! else raise "File #{image_in} does not exist!" end end |