Sha256: c909aa749b26805941a34f1393c9550fc43b337a876d3a1c6b484870ef0b9149

Contents?: true

Size: 1.83 KB

Versions: 12

Compression:

Stored size: 1.83 KB

Contents

module Alula
  class ImageProcessor < Processor
    def process
      super
      
      sizes.each do |size|
        width, height = size[:size]
        # output_dir = self.site.storage.path(:cache, "attachments", size[:type].to_s)
        
        # Generate attachment hash
        name = File.join size[:type].to_s, if size[:hires]
          ext = File.extname(item.name)
          item.name.gsub(/#{ext}$/, "-hires#{ext}")
        else
          item.name
        end
        
        output = asset_path(name, size[:type].to_s)
        # asset_name = self.attachments.asset_name(name, size[:type].to_s)
        # output = File.join(self.site.storage.path(:cache, "attachments"), asset_name)
        # # Make sure our directory exists
        # output_dir = self.site.storage.path(:cache, "attachments", File.dirname(asset_name))
        
        # Skip image processing if output already exists...
        next if File.exists?(output)
        
        # Skip if our original resolution isn't enough for hires images
        next if (width > self.info.width and height > self.info.height) and size[:hires]
        
        # Generate resized image to output path
        resize_image(output: output, size: size[:size], type: size[:type])
      end
      
      # Cleanup ourself
      cleanup
    end
    
    def sizes
      @sizes ||= begin
        sizes = []
        sizes << { type: :image,  hires: false, size: self.site.config.attachments["image"]["size"].split("x").collect{|i| i.to_i} }
        sizes << { type: :thumbnail, hires: false, size: self.site.config.attachments["image"]["thumbnail"].split("x").collect{|i| i.to_i} }
        
        if self.site.config.attachments["image"]["hires"]
          sizes += sizes.collect {|s| { type: s[:type], hires: true, size: s[:size].collect{|x| x*2} } }
        end
        
        sizes
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
alula-0.4.27 lib/alula/processors/image.rb
alula-0.4.26 lib/alula/processors/image.rb
alula-0.4.25 lib/alula/processors/image.rb
alula-0.4.24 lib/alula/processors/image.rb
alula-0.4.23 lib/alula/processors/image.rb
alula-0.4.22 lib/alula/processors/image.rb
alula-0.4.21 lib/alula/processors/image.rb
alula-0.4.20 lib/alula/processors/image.rb
alula-0.4.19 lib/alula/processors/image.rb
alula-0.4.18 lib/alula/processors/image.rb
alula-0.4.17 lib/alula/processors/image.rb
alula-0.4.16 lib/alula/processors/image.rb