Class: PhotoResize

Inherits:
Object
  • Object
show all
Defined in:
lib/potion/extensions/photo_resize.rb

Instance Method Summary collapse

Instance Method Details

#process(item) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/potion/extensions/photo_resize.rb', line 4

def process(item)
  return unless item.path.include?("_posts")
  return if item.site.config["photo_resize"].nil?
  return unless item.site.config["photo_resize"]["enabled"]
  return if item.site.fast_build
  
  extensions = [".jpg", ".jpeg", ".gif", ".png"]    

  return unless extensions.include?(File.extname(item.output_path).downcase)

  begin
      image = MiniMagick::Image.read(item.content)
      image.resize(item.site.config["photo_resize"]["size"])
      item.content = image.to_blob
  rescue => e
      raise "ERROR: Something went wrong when resizing images, do you have ImageMagick installed?\n\n#{e}"
  end
end