Skip to content

Commit

Permalink
FileIO extension for imshow() (#316)
Browse files Browse the repository at this point in the history
When FileIO is present, imshow() will open an image using a dialog.
  • Loading branch information
jwahlstrand authored Jan 12, 2025
1 parent acaab89 commit dd4ceff
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ StatsBase = "0.28, 0.29, 0.30, 0.31, 0.32, 0.33, 0.34"
julia = "1.10"
TestImages = "1.9"

[weakdeps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"

[extensions]
ImageViewFileIOExt = "FileIO"

[extras]
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ You should get a window with your image:
![photo](readme_images/photo1.jpg)

You can use `imshow()` if you want to choose an image using a file
dialog.
dialog (requires [FileIO](https://github.com/JuliaIO/FileIO.jl)).

Try resizing the image window by dragging one of its corners; you'll
see that the aspect ratio of the image is preserved when you
Expand Down
12 changes: 12 additions & 0 deletions ext/ImageViewFileIOExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module ImageViewFileIOExt

using FileIO, ImageView, Gtk4

"""
imshow()
Choose an image to display via a file dialog.
"""
ImageView.imshow() = imshow(load(open_dialog("Pick an image to display")))

end
7 changes: 0 additions & 7 deletions src/ImageView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ end

const window_wrefs = WeakKeyDict{Gtk4.GtkWindowLeaf,Nothing}()

"""
imshow()
Choose an image to display via a file dialog.
"""
imshow() = imshow(load(open_dialog("Pick an image to display")))

"""
imshow!(canvas, img) -> drawsignal
imshow!(canvas, img::Observable, zr::Observable{ZoomRegion}) -> drawsignal
Expand Down

0 comments on commit dd4ceff

Please sign in to comment.