Skip to content

Instantly share code, notes, and snippets.

@flyingzumwalt
Last active December 20, 2015 04:29
Show Gist options
  • Save flyingzumwalt/6071705 to your computer and use it in GitHub Desktop.
Save flyingzumwalt/6071705 to your computer and use it in GitHub Desktop.
case-based syntax for makes_derivatives_of
makes_derivatives_of :content, when: :mime_type, is_one_of: 'application/pdf',
derivatives: { :thumb => "100x100>" }
makes_derivatives_of :content, when: :mime_type, is_one_of: 'audio/wav',
derivatives: { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processors: :audio
# -g 30 enforces keyframe generation every second (30fps)
# -b:v is the video bitrate
# -acodec is the audio codec
size_attributes = "-s 320x240"
audio_attributes = "-ac 2 -ab 96k -ar 44100"
makes_derivatives_of :content, when: :mime_type, is: 'video/avi',
derivatives: { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processors: :video
makes_derivatives_of :content, when: :mime_type, is_one_of: ['image/png', 'image/jpg'],
derivatives: { :medium => "300x300>", :thumb => "100x100>" }
makes_derivatives_of :content do |ds|
size_attributes = "-s 320x240"
audio_attributes = "-ac 2 -ab 96k -ar 44100"
case ds.mime_type
when 'application/pdf'
transform_datastream ds, { :thumb => "100x100>" }
when 'audio/wav'
transform_datastream ds, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processors: :audio
when 'video/avi'
transform_datastream ds, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processors: :video
when 'image/png', 'image/jpg'
transform_datastream ds, { :medium => "300x300>", :thumb => "100x100>" }
end
end
makes_derivatives do |obj|
size_attributes = "-s 320x240"
audio_attributes = "-ac 2 -ab 96k -ar 44100"
case obj.mime_type
when 'application/pdf'
obj.transform_datastream :content, { :thumb => "100x100>" }
when 'audio/wav'
obj.transform_datastream :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
when 'video/avi'
obj.transform_datastream :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
when 'image/png', 'image/jpg'
obj.transform_datastream :content, { :medium => "300x300>", :thumb => "100x100>" }
end
end
make_derivatives_of :content, :using => :derivatives_from_content_ds
def derivatives_from_content_ds
size_attributes = "-s 320x240"
audio_attributes = "-ac 2 -ab 96k -ar 44100"
case obj.mime_type
when 'application/pdf'
obj.transform_datastream :content, { :thumb => "100x100>" }
when 'audio/wav'
obj.transform_datastream :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
when 'video/avi'
obj.transform_datastream :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
when 'image/png', 'image/jpg'
obj.transform_datastream :content, { :medium => "300x300>", :thumb => "100x100>" }
end
end
makes_derivatives :generate_content_derivatives
def generate_content_derivatives
size_attributes = "-s 320x240"
audio_attributes = "-ac 2 -ab 96k -ar 44100"
case obj.mime_type
when 'application/pdf'
obj.transform_datastream :content, { :thumb => "100x100>" }
when 'audio/wav'
obj.transform_datastream :content, { :mp3 => {format: 'mp3'}, :ogg => {format: 'ogg'} }, processor: :audio
when 'video/avi'
obj.transform_datastream :content, { :mp4 => {format: 'mp4'}, :webm => {format: 'webm'} }, processor: :video
when 'image/png', 'image/jpg'
obj.transform_datastream :content, { :medium => "300x300>", :thumb => "100x100>" }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment