Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielres/3156265 to your computer and use it in GitHub Desktop.
Save danielres/3156265 to your computer and use it in GitHub Desktop.
Fetching images from Flickr to show them in Octopress
---
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 %}
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)
gem 'flickraw'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment