7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/hyperimage/images_controller.rb', line 7
def show
raise ActionController::RoutingError.new('Not Found') unless Hyperimage::Image.exist?(params[:resource])
if Hyperimage::Image.exists?(params[:resource], 'gif')
source = Hyperimage::Image.first(params[:resource], 'gif')
else
source = Hyperimage::Image.first(params[:resource])
end
source_file = Magick::Image::read(source)
frame = params[:frame].to_i
raise ActionController::RoutingError.new('Not Found') unless (0..(source_file.length - 1)).include?(frame)
@image = Hyperimage::Image.first(params[:resource], params[:format], frame)
if @image.nil? if source_file.length > 1
path = Hyperimage::Image.root.join(params[:resource])
Dir.mkdir(path) unless File.exists?(path)
@image = path.join([frame, params[:format]].join('.'))
else
@image = Hyperimage::Image.root.join([params[:resource], params[:format]].join('.'))
end
source_file[frame].write(@image) { self.quality = 100}
end
mime_type = Mime::Type.lookup_by_extension(File.extname(@image).sub('.', ''))
send_file @image, :type => mime_type.to_s, :disposition => 'inline'
end
|