Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Created January 28, 2012 16:56
Show Gist options
  • Save bil-bas/1695008 to your computer and use it in GitHub Desktop.
Save bil-bas/1695008 to your computer and use it in GitHub Desktop.
compile '/images/screenshots/*/', rep: :thumbnail do
filter :thumbnailize, factor: 0.25
end
route '/images/screenshots/*/', rep: :thumbnail do
item.identifier.chop + '-thumbnail.' + item[:extension]
end
-------------------
# layouts/screenshot.html.haml
- path = "/images/screenshots/#{@image}"
- screenshot = @items.find {|i| i.identifier == "#{path}/" }
# Fails here, unless the full-size screenshots exist in output, unless I use 'screenshot.compiled_content', which spits out a big error, of course.
- thumbnail = screenshot.rep_named(:thumbnail)
- image = ChunkyPNG::Image.from_file("output#{path}-thumbnail.png")
- @title ||= @alt
= link_to screenshot.path, rel: "lightbox-gallery" do
%img{ class: "thumb", src: thumbnail.path, alt: @alt, title: @title, width: image.width, height: image.height }
@bil-bas
Copy link
Author

bil-bas commented Jan 28, 2012

class Thumbnailize < Nanoc3::Filter
  identifier :thumbnailize
  type       :binary

  def run(filename, params={})
    factor = params[:factor]

    image = ChunkyPNG::Image.from_file(filename)
    image.resample_nearest_neighbor! (image.width * factor).round, (image.height * factor).round

    image.save output_filename
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment