uploads: factor out image dimension and filetype detection code.
* Add MediaFile abstraction. A MediaFile represents an image or video file. * Move filetype detection and dimension parsing code from uploads to MediaFile.
This commit is contained in:
6
app/logical/media_file/flash.rb
Normal file
6
app/logical/media_file/flash.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class MediaFile::Flash < MediaFile::Image
|
||||
def dimensions
|
||||
image_size = ImageSpec.new(file.path)
|
||||
[image_size.width, image_size.height]
|
||||
end
|
||||
end
|
||||
6
app/logical/media_file/image.rb
Normal file
6
app/logical/media_file/image.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class MediaFile::Image < MediaFile
|
||||
def dimensions
|
||||
image_size = ImageSpec.new(file.path)
|
||||
[image_size.width, image_size.height]
|
||||
end
|
||||
end
|
||||
13
app/logical/media_file/ugoira.rb
Normal file
13
app/logical/media_file/ugoira.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class MediaFile::Ugoira < MediaFile
|
||||
def dimensions
|
||||
tempfile = Tempfile.new
|
||||
folder = Zip::File.new(file.path)
|
||||
folder.first.extract(tempfile.path) { true }
|
||||
|
||||
image_file = MediaFile.open(tempfile)
|
||||
image_file.dimensions
|
||||
ensure
|
||||
image_file.close
|
||||
tempfile.close!
|
||||
end
|
||||
end
|
||||
9
app/logical/media_file/video.rb
Normal file
9
app/logical/media_file/video.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class MediaFile::Video < MediaFile
|
||||
def dimensions
|
||||
[video.width, video.height]
|
||||
end
|
||||
|
||||
def video
|
||||
@video ||= FFMPEG::Movie.new(file.path)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user