Skip to content

Instantly share code, notes, and snippets.

@phillipoertel
Created November 19, 2012 23:08
Show Gist options
  • Save phillipoertel/4114704 to your computer and use it in GitHub Desktop.
Save phillipoertel/4114704 to your computer and use it in GitHub Desktop.
Dragonfly FTW
require 'transcoder/base'
require 'transcoder/video'
class Content < ActiveRecord::Base
image_accessor :cover_image do
after_assign :make_preview_video
end
image_accessor :preview_video
attr_accessible :name, :content, :cover_image
def thumbnail
cover_image.thumb("100x100").jpg
end
def preview
cover_image.thumb("555x>").jpg
end
def mobile_preview
cover_image.thumb("600x").jpg
end
def make_preview_video
return unless cover_image.ext == "mov"
out_file = File.new("/tmp/#{rand}.mp4", "a")
Transcoder::Video.new.transcode(cover_image.path, out_file.path)
self.preview_video = out_file
self.save!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment