Skip to content

Commit 68b76f6

Browse files
committed
Add mime save for eps, pdf, png and svg
1 parent a94f376 commit 68b76f6

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/FileIO.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Base.showerror
2929
include("query.jl")
3030
include("error_handling.jl")
3131
include("loadsave.jl")
32+
include("mimesave.jl")
3233
include("registry.jl")
3334

3435
"""

src/mimesave.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function FileIO.save(file::File{format"PNG"}, data)
2+
if mimewritable("image/png", data)
3+
open(file.filename, "w") do s
4+
show(s, "image/png", data)
5+
end
6+
else
7+
throw(ArgumentError("Argument does not support conversion to png."))
8+
end
9+
end
10+
11+
function FileIO.save(file::File{format"SVG"}, data)
12+
if mimewritable("image/svg+xml", data)
13+
open(file.filename, "w") do s
14+
show(s, "image/svg+xml", data)
15+
end
16+
else
17+
throw(ArgumentError("Argument does not support conversion to svg."))
18+
end
19+
end
20+
21+
function FileIO.save(file::File{format"PDF"}, data)
22+
if mimewritable("application/pdf", data)
23+
open(file.filename, "w") do s
24+
show(s, "application/pdf", data)
25+
end
26+
else
27+
throw(ArgumentError("Argument does not support conversion to pdf."))
28+
end
29+
end
30+
31+
function FileIO.save(file::File{format"EPS"}, data)
32+
if mimewritable("application/eps", data)
33+
open(file.filename, "w") do s
34+
show(s, "application/eps", data)
35+
end
36+
else
37+
throw(ArgumentError("Argument does not support conversion to eps."))
38+
end
39+
end

src/registry.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ add_format(format"CRW", UInt8[0x49,0x49,0x1a,0x00,0x00,0x00,0x48,0x45], ".crw",
4343
add_format(format"CUR", UInt8[0x00,0x00,0x02,0x00], ".cur", [:ImageMagick])
4444
add_format(format"DCX", UInt8[0xb1,0x68,0xde,0x3a], ".dcx", [:ImageMagick])
4545
add_format(format"DOT", UInt8[0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1], ".dot", [:ImageMagick])
46-
add_format(format"EPS", UInt8[0x25,0x21,0x50,0x53,0x2d,0x41,0x64,0x6f], ".eps", [:ImageMagick])
46+
add_format(format"EPS", UInt8[0x25,0x21,0x50,0x53,0x2d,0x41,0x64,0x6f], ".eps", [:FileIO, SAVE], [:ImageMagick])
4747
add_format(format"HDR", UInt8[0x23,0x3f,0x52,0x41,0x44,0x49,0x41,0x4e], ".hdr", [:ImageMagick])
4848
add_format(format"ICO", UInt8[0x00,0x00,0x01,0x00], ".ico", [:ImageMagick])
4949
add_format(format"INFO", UInt8[0x7a,0x62,0x65,0x78], ".info",[:ImageMagick])
5050
add_format(format"JP2", UInt8[0x00,0x00,0x00,0x0c,0x6a,0x50,0x20,0x20], ".jp2", [:ImageMagick])
5151
add_format(format"PDB", UInt8[0x73,0x7a,0x65,0x7a], ".pdb", [:ImageMagick])
52-
add_format(format"PDF", UInt8[0x25,0x50,0x44,0x46], ".pdf", [:ImageMagick])
52+
add_format(format"PDF", UInt8[0x25,0x50,0x44,0x46], ".pdf", [:FileIO, SAVE], [:ImageMagick])
5353
add_format(format"PGM", UInt8[0x50,0x35,0x0a], ".pgm", [:ImageMagick])
5454
add_format(format"PSD", UInt8[0x38,0x42,0x50,0x53], ".psd", [:ImageMagick])
5555
add_format(format"RGB", UInt8[0x01,0xda,0x01,0x01,0x00,0x03], ".rgb", [:ImageMagick])
@@ -75,6 +75,7 @@ add_format(
7575
format"PNG",
7676
UInt8[0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a],
7777
".png",
78+
[:FileIO, SAVE],
7879
[:QuartzImageIO, OSX],
7980
[:ImageMagick]
8081
)
@@ -105,6 +106,12 @@ add_format(
105106
".pcx",
106107
[:ImageMagick]
107108
)
109+
add_format(
110+
format"SVG",
111+
(),
112+
".svg",
113+
[:FileIO, SAVE]
114+
)
108115

109116
#=
110117
add_format(format"NPY", UInt8[0x93, 'N', 'U', 'M', 'P', 'Y'], ".npy")

0 commit comments

Comments
 (0)