Created
March 2, 2013 00:36
-
-
Save query/5069053 to your computer and use it in GitHub Desktop.
Simple nanoc handling of width and height for image items, using the "dimensions" Ruby gem.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put this in the lib/ directory. | |
require 'dimensions' | |
def image_tag(item, attributes={}) | |
"<img src='#{item.path}' width='#{item[:img_width]}' height='#{item[:img_height]}' alt='#{attributes[:alt]}'" + (attributes[:title] ? " title='#{attributes[:title]}'" : "") + " />" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
preprocess do | |
@items.each do |item| | |
if %w{png gif jpg jpeg}.include? item[:extension] | |
dimensions = Dimensions.dimensions(item.raw_filename) | |
item[:img_width] = dimensions[0] | |
item[:img_height] = dimensions[1] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment