Skip to content

Commit e8c7928

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

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ext/FreeTypeExt.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,11 @@ 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...) =
491+
FileIO.save(fn, args...; kw...)
492+
493+
# compat for Plots
494+
UnicodePlots.save_image(io::IO, args...; kw...) =
495+
FileIO.save(FileIO.Stream{FileIO.format"PNG"}(io), args...; kw...)
491496

492497
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)