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
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/canvas_exporting/exporter.rb', line 10
def export
@infile_tmp_file = infile_file
type = params[:type] || 'image/png'
extension = MIME::Types[type].first.extensions.first
if params[:outputpath] == nil
output_path = tmp_dir
else
output_path = params[:outputpath]
end
output_path = output_path + '/' if output_path[-1] != '/'
if params[:filename] == nil
filename = 'Chart.' + extension
else
filename = params[:filename]
end
@output_file = output_path + filename
scale = params[:scale] || 2
width = params[:width]
constr = params[:constr] || 'Chart'
convert_args = convert_args({infile: @infile_tmp_file.path,
outfile: @output_file,
scale: scale,
width: width,
constr: constr,
callback: callback_path
})
result = ::Phantomjs.run(*convert_args)
@infile_tmp_file.delete
@callback_tmp_file.delete if @callback_tmp_file
if /Error/ =~ result
render text: result, status: 500
else
send_file @output_file, filename: "#{filename}", type: type
end
end
|