Ah, yeah, it looks like the image loading code inside testimage (which I think uses ImageIO.jl internally) does some magic to lazily load different packages to handle different image types.
I can think of two different ways to avoid this issue:
- Use
invokelatestto run functions that depend onimgwithin the context of your function:
julia> using TestImages
julia> function f()
img = testimage("mandrill")
Base.invokelatest(size, img)
end
f (generic function with 1 method)
julia> f()
(512, 512)
You can learn more about invokelatest here: Essentials · The Julia Language
- Ensure that
TiffImagesis already loaded so thattestimagedoesn’t need to do its lazy loading in the background:
julia> using TestImages, TiffImages
julia> function f()
img = testimage("mandrill")
size(img)
end
f (generic function with 1 method)
julia> f()
(512, 512)
I would also consider creating an issue over at GitHub - JuliaImages/TestImages.jl: commonly used test images , since I’m sure you’re not the only person to have had this problem.