Skip to content

Commit

Permalink
add compat save_image for Plots
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Feb 8, 2023
1 parent b12e041 commit 960ef3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ext/FreeTypeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ function UnicodePlots.get_font_face(font = nothing, fallback = fallback_fonts())
face
end

UnicodePlots.save_image(args...; kw...) = FileIO.save(args...; kw...)
UnicodePlots.save_image(fn::AbstractString, args...; kw...) = FileIO.save(fn, args...; kw...)

# compat for Plots
UnicodePlots.save_image(io::IO, args...; kw...) =
FileIO.save(FileIO.Stream{FileIO.format"PNG"}(io), args...; kw...)

end # module
10 changes: 10 additions & 0 deletions test/tst_io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ end

@test_throws ArgumentError savefig(p, tempname() * ".jpg")
end

# for Plots
if font_found
p = lineplot(1:2)
tmp = tempname() * ".png"
open(tmp, "w") do io
UnicodePlots.save_image(io, UnicodePlots.png_image(p))
end
@test filesize(tmp) > 1_000
end
end

@testset "stringify plot - performance regression" begin
Expand Down

0 comments on commit 960ef3a

Please sign in to comment.