Skip to content

Commit 34ad95d

Browse files
authored
fix problems with mime write (#136)
* fix problems with mime write * fix not installed error
1 parent 6e179a4 commit 34ad95d

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/loadsave.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ function is_installed(pkg::Symbol)
99
end
1010

1111
function checked_import(pkg::Symbol)
12-
!is_installed(pkg) && throw(NotInstalledError(pkg, ""))
13-
!isdefined(Main, pkg) && eval(Main, Expr(:import, pkg))
12+
isdefined(Main, pkg) && return getfield(Main, pkg)
13+
isdefined(FileIO, pkg) && return getfield(FileIO, pkg)
14+
!is_installed(pkg) && throw(NotInstalledError(pkg, ""))
15+
!isdefined(Main, pkg) && eval(Main, Expr(:import, pkg))
1416
return getfield(Main, pkg)
1517
end
1618

src/mimesave.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
function FileIO.save(file::File{format"PNG"}, data)
1+
module MimeWriter
2+
3+
using ..FileIO: File, @format_str
4+
5+
function save(file::File{format"PNG"}, data)
26
if mimewritable("image/png", data)
37
open(file.filename, "w") do s
48
show(IOContext(s, :full_fidelity=>true), "image/png", data)
@@ -8,7 +12,7 @@ function FileIO.save(file::File{format"PNG"}, data)
812
end
913
end
1014

11-
function FileIO.save(file::File{format"SVG"}, data)
15+
function save(file::File{format"SVG"}, data)
1216
if mimewritable("image/svg+xml", data)
1317
open(file.filename, "w") do s
1418
show(IOContext(s, :full_fidelity=>true), "image/svg+xml", data)
@@ -18,7 +22,7 @@ function FileIO.save(file::File{format"SVG"}, data)
1822
end
1923
end
2024

21-
function FileIO.save(file::File{format"PDF"}, data)
25+
function save(file::File{format"PDF"}, data)
2226
if mimewritable("application/pdf", data)
2327
open(file.filename, "w") do s
2428
show(IOContext(s, :full_fidelity=>true), "application/pdf", data)
@@ -28,7 +32,7 @@ function FileIO.save(file::File{format"PDF"}, data)
2832
end
2933
end
3034

31-
function FileIO.save(file::File{format"EPS"}, data)
35+
function save(file::File{format"EPS"}, data)
3236
if mimewritable("application/eps", data)
3337
open(file.filename, "w") do s
3438
show(IOContext(s, :full_fidelity=>true), "application/eps", data)
@@ -37,3 +41,5 @@ function FileIO.save(file::File{format"EPS"}, data)
3741
throw(ArgumentError("Argument does not support conversion to eps."))
3842
end
3943
end
44+
45+
end

src/registry.jl

Lines changed: 4 additions & 4 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], [:FileIO, SAVE])
46+
add_format(format"EPS", UInt8[0x25,0x21,0x50,0x53,0x2d,0x41,0x64,0x6f], ".eps", [:ImageMagick], [:MimeWriter, SAVE])
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], [:FileIO, SAVE])
52+
add_format(format"PDF", UInt8[0x25,0x50,0x44,0x46], ".pdf", [:ImageMagick], [:MimeWriter, SAVE])
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])
@@ -77,7 +77,7 @@ add_format(
7777
".png",
7878
[:QuartzImageIO, OSX],
7979
[:ImageMagick],
80-
[:FileIO, SAVE]
80+
[:MimeWriter, SAVE]
8181
)
8282
add_format(
8383
format"TIFF",
@@ -110,7 +110,7 @@ add_format(
110110
format"SVG",
111111
(),
112112
".svg",
113-
[:FileIO, SAVE]
113+
[:MimeWriter, SAVE]
114114
)
115115

116116
#=

0 commit comments

Comments
 (0)