Forked from danielres/2012-07-21-post-with-images-from-flickr.markdown_
Created
July 26, 2012 18:52
-
-
Save og-shawn-crigger/3183782 to your computer and use it in GitHub Desktop.
Fetching images from Flickr to show them in Octopress
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
--- | |
layout: post | |
title: "Post with images from Flickr" | |
date: 2012-07-19 15:19 | |
comments: true | |
categories: art | |
--- | |
A big image: | |
{% flickr_image 6829790399 b %} | |
A medium-sized image: | |
{% flickr_image 7614906062 m %} | |
The same image, as a small square thumbnail: | |
{% flickr_image 7614906062 sq %} |
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
require 'flickraw' | |
class FlickrImage < Liquid::Tag | |
def initialize(tag_name, markup, tokens) | |
super | |
@markup = markup | |
@id = markup.split(' ')[0] | |
@size = markup.split(' ')[1] | |
end | |
def render(context) | |
FlickRaw.api_key = ENV["FLICKR_KEY"] | |
FlickRaw.shared_secret = ENV["FLICKR_SECRET"] | |
info = flickr.photos.getInfo(:photo_id => @id) | |
server = info['server'] | |
farm = info['farm'] | |
id = info['id'] | |
secret = info['secret'] | |
title = info['title'] | |
description = info['description'] | |
size = "_#{@size}" if @size | |
src = "http://farm#{farm}.static.flickr.com/#{server}/#{id}_#{secret}#{size}.jpg" | |
page_url = info['urls'][0]["_content"] | |
img_tag = "<img src='#{src}' title='#{title}'/>" | |
link_tag = "<a href='#{page_url}'>#{img_tag}</a>" | |
end | |
end | |
Liquid::Template.register_tag('flickr_image', FlickrImage) |
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
gem 'flickraw' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment