Skip to content

Commit 960ef3a

Browse files
committed
add compat save_image for Plots
1 parent b12e041 commit 960ef3a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ext/FreeTypeExt.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ function UnicodePlots.get_font_face(font = nothing, fallback = fallback_fonts())
487487
face
488488
end
489489

490-
UnicodePlots.save_image(args...; kw...) = FileIO.save(args...; kw...)
490+
UnicodePlots.save_image(fn::AbstractString, args...; kw...) = FileIO.save(fn, args...; kw...)
491+
492+
# compat for Plots
493+
UnicodePlots.save_image(io::IO, args...; kw...) =
494+
FileIO.save(FileIO.Stream{FileIO.format"PNG"}(io), args...; kw...)
491495

492496
end # module

test/tst_io.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ end
4444

4545
@test_throws ArgumentError savefig(p, tempname() * ".jpg")
4646
end
47+
48+
# for Plots
49+
if font_found
50+
p = lineplot(1:2)
51+
tmp = tempname() * ".png"
52+
open(tmp, "w") do io
53+
UnicodePlots.save_image(io, UnicodePlots.png_image(p))
54+
end
55+
@test filesize(tmp) > 1_000
56+
end
4757
end
4858

4959
@testset "stringify plot - performance regression" begin

0 commit comments

Comments
 (0)