module Media
media processing requires a different type of tempfile… because we use command line tools to process our temp files, these files can't be open and closed by ruby.
instead, Media::TempFile
is used to generate closed files from binary data (for files to be fed to command line tools), or to generate empty tmp files (for output filenames to be fed to command line tools).
We use the Tempfile class for generating these files, but then we always close them right away. By doing this, we ensure that the temp file will eventually get removed when the Tempfile gets garbage collected.
Constants
- GRAPHICSMAGICK_COMMAND
- GRAPHICSMAGICK_VERSION
- INKSCAPE_COMMAND
- LIBREOFFICE_COMMAND
- VERSION
Public Class Methods
# File lib/media.rb, line 56 def self.dimensions(filepath) return unless Media::GraphicsMagickTransmogrifier.available? Media::GraphicsMagickTransmogrifier.dimensions filepath end
special graphicsmagick hooks. we use graphicsmagick in order to parse the dimensions of image files.
# File lib/media.rb, line 51 def self.has_dimensions?(mime_type) Media::GraphicsMagickTransmogrifier.available? && Media::GraphicsMagickTransmogrifier.converts_from?(mime_type) end
# File lib/media.rb, line 42 def self.may_produce?(src_type, dst_type) Transmogrifier.find_class(src_type, dst_type) end
creates a new instance of transmogrifier suitable for turning input into output.
# File lib/media.rb, line 15 def self.transmogrifier(options) if options[:input_type] input_type = Media::MimeType.simple options[:input_type] elsif options[:input_file] input_type = Media::MimeType.mime_type_from_extension options[:input_file] else raise ArgumentError.new end if options[:output_type] output_type = Media::MimeType.simple options[:output_type] elsif options[:output_file] output_type = Media::MimeType.mime_type_from_extension options[:output_file] else raise ArgumentError.new end unless input_type and output_type raise ArgumentError.new("Both input and output types are required (given %s -> %s)." % [input_type||'nil', output_type||'nil']) end transmog_class = Transmogrifier.find_class(input_type, output_type) if transmog_class transmog_class.new(options) end end