simonschoelly / KittyTerminalImages.jl

A package that allows Julia to display images in the kitty terminal editor
MIT License
97 stars 7 forks source link

Need to specify DPI always #2

Closed tallakt closed 4 years ago

tallakt commented 4 years ago

When I use KittyTerminalImages with Plots, the plots always come out really small. I can fix this by specifying , dpi=300 to the call to plot, but this is quite cumbersome.

simonschoelly commented 4 years ago

We probably should have a way to specify that with either some global variables or environment variables.

Another option would be to get the terminal width by using some escape sequences but I first have to figure out what the best way is to do that.

simonschoelly commented 4 years ago

So the question with the escape code has been posted here: https://discourse.julialang.org/t/reading-responses-to-ansi-escape-codes/44572?u=simonschoelly

The kitty author seems to prefer ioctl though: https://github.com/kovidgoyal/kitty/issues/581 There is a Julia library called TerminalUserInterfaces so I might just add that as a dependency

simonschoelly commented 4 years ago

Actually I have to think about that because in certain situations scaling all images might not be what the user wants. I don't have a mac with some high resolution display here, but when you do your plots in Jupyter notebook, are the images as big as they should be?

tallakt commented 4 years ago

Actually I never tried Jupyter on this Mac, as ai prefer working from the terminal and did not install it, and I would rather not have to deal with installing Python.

What I can say is that plots look fine in the built in gui window of Plots (GR). With Kitty it is always stamp sized as default (5x4 cm rough guess)

simonschoelly commented 4 years ago

Now I added some config value, you can use it like this:

set_kitty_config!(:scale, 2.0)
tallakt commented 4 years ago

After reinstalling KittyTerminalImages I am left with a non working system (on Julia 1.4 and 1.5).

julia> using Plots

julia> using KittyTerminalImages

julia> plot(1:4)
Errors encountered while loading nothing.
All errors:
===========================================
ArgumentError: Package ImageIO not found in current path:
- Run `import Pkg; Pkg.add("ImageIO")` to install the ImageIO package.

===========================================
ArgumentError: Package QuartzImageIO not found in current path:
- Run `import Pkg; Pkg.add("QuartzImageIO")` to install the QuartzImageIO package.

===========================================
ArgumentError: Package ImageMagick not found in current path:
- Run `import Pkg; Pkg.add("ImageMagick")` to install the ImageMagick package.

===========================================

Fatal error:
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: ArgumentError: Package ImageIO not found in current path:
- Run `import Pkg; Pkg.add("ImageIO")` to install the ImageIO package.

After installing these I get

v1.4) pkg> add ImageIO
  Resolving package versions...
   Updating `~/.julia/environments/v1.4/Project.toml`
  [82e4d734] + ImageIO v0.3.0
   Updating `~/.julia/environments/v1.4/Manifest.toml`
  [82e4d734] + ImageIO v0.3.0
  [f57f5aa1] + PNGFiles v0.3.0

julia> plot(1:4)
[ Info: Precompiling ImageIO [82e4d734-157c-48bb-816b-45c225c6df19]
[ Info: Precompiling PNGFiles [f57f5aa1-a3ce-4bc8-8ab9-96f992907883]
[ Info: Precompiling QuartzImageIO [dca85d43-d64c-5e67-8c65-017450d5d020]
┌ Warning: QuartzImageIO found no frames
└ @ QuartzImageIO ~/.julia/packages/QuartzImageIO/O8FT7/src/QuartzImageIO.jl:55
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: MethodError: no method matching imresize(::Nothing; ratio=1.0)
Closest candidates are:
  imresize(::AbstractArray{T,0}, ::Tuple{}) where T at /Users/tallakt/.julia/packages/ImageTransformations/J3Mno/src/resizing.jl:276 got unsupported keyword argument "ratio"
  imresize(::AbstractArray; ratio) at /Users/tallakt/.julia/packages/ImageTransformations/J3Mno/src/resizing.jl:232
  imresize(::AbstractArray, ::T, ::T...) where T<:Union{Integer, AbstractUnitRange} at /Users/tallakt/.julia/packages/ImageTransformations/J3Mno/src/resizing.jl:230 got unsupported keyword argument "ratio"
  ...
Stacktrace:
 [1] display(::KittyTerminalImages.KittyDisplay, ::MIME{Symbol("image/png")}, ::Cairo.CairoSurfaceBase{UInt32}; scale::Float64) at /Users/tallakt/.julia/packages/KittyTerminalImages/UJeDQ/src/KittyTerminalImages.jl:92
 [2] display(::KittyTerminalImages.KittyDisplay, ::MIME{Symbol("image/svg+xml")}, ::Plots.Plot{Plots.GRBackend}; scale::Float64) at /Users/tallakt/.julia/packages/KittyTerminalImages/UJeDQ/src/KittyTerminalImages.jl:116
 [3] display(::KittyTerminalImages.KittyDisplay, ::MIME{Symbol("image/svg+xml")}, ::Plots.Plot{Plots.GRBackend}) at /Users/tallakt/.julia/packages/KittyTerminalImages/UJeDQ/src/KittyTerminalImages.jl:104
 [4] display(::KittyTerminalImages.KittyDisplay, ::Plots.Plot{Plots.GRBackend}) at /Users/tallakt/.julia/packages/KittyTerminalImages/UJeDQ/src/KittyTerminalImages.jl:78
 [5] display(::Any) at ./multimedia.jl:323
 [6] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [7] invokelatest at ./essentials.jl:711 [inlined]
 [8] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:161
 [9] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:146
 [10] (::REPL.var"#do_respond#38"{Bool,REPL.var"#48#57"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:729
 [11] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [12] invokelatest at ./essentials.jl:711 [inlined]
 [13] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/LineEdit.jl:2354
 [14] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:1055
 [15] run_repl(::REPL.AbstractREPL, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:206
 [16] (::Base.var"#764#766"{Bool,Bool,Bool,Bool})(::Module) at ./client.jl:383
 [17] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [18] invokelatest at ./essentials.jl:711 [inlined]
 [19] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:367
 [20] exec_options(::Base.JLOptions) at ./client.jl:305
 [21] _start() at ./client.jl:484
simonschoelly commented 4 years ago

Its a bit hard for me to figure out what is going on here, as I don't have a mac. Did you add both, ImageMagick and QuartzImageIO? If yes, can you maybe remove QuartzImageIO and try again?

simonschoelly commented 4 years ago

I pushed some more code that basically enforces the usage of ImageMagic -- it should also not be necessary anymore to install any additional packages.

tallakt commented 4 years ago

Thank you. This time it works as expected both on Julia 1.4 and 1.5.