-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathmimesave.jl
63 lines (56 loc) · 1.89 KB
/
mimesave.jl
1
2
3
4
5
6
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module MimeWriter
using ..FileIO: File, @format_str
function save(file::File{format"PNG"}, data; ppi::Union{Nothing,Number}=nothing)
if showable("image/png", data)
open(file.filename, "w") do s
if ppi === nothing
show(IOContext(s, :full_fidelity=>true), "image/png", data)
else
show(IOContext(s, :full_fidelity=>true, :ppi=>ppi), "image/png", data)
end
end
else
throw(ArgumentError("Argument does not support conversion to png."))
end
end
function save(file::File{format"SVG"}, data)
if showable("image/svg+xml", data)
open(file.filename, "w") do s
show(IOContext(s, :full_fidelity=>true), "image/svg+xml", data)
end
else
throw(ArgumentError("Argument does not support conversion to svg."))
end
end
function save(file::File{format"PDF"}, data)
if showable("application/pdf", data)
open(file.filename, "w") do s
show(IOContext(s, :full_fidelity=>true), "application/pdf", data)
end
else
throw(ArgumentError("Argument does not support conversion to pdf."))
end
end
function save(file::File{format"EPS"}, data)
if showable("application/eps", data)
open(file.filename, "w") do s
show(IOContext(s, :full_fidelity=>true), "application/eps", data)
end
else
throw(ArgumentError("Argument does not support conversion to eps."))
end
end
function save(file::File{format"HTML"}, data)
if showable("application/vnd.julia.fileio.htmlfile", data)
open(file.filename, "w") do s
show(s, "application/vnd.julia.fileio.htmlfile", data)
end
elseif showable("text/html", data)
open(file.filename, "w") do s
show(s, "text/html", data)
end
else
throw(ArgumentError("Argument does not support conversion to HTML."))
end
end
end