# Making images as big as possible (max width) in pluto notebooks

**URL:** <https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003>\
**Category:** General Usage\
**Tags:** question, images, pluto, html\
**Created:** [May 31, 2024, 9:16am UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003 "2024-05-31T09:16:57Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Post date:** [May 31, 2024, 9:16am UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/1 "2024-05-31T09:16:57Z")

</div>

I am doing some image analysis in Pluto and everythign is amazing… except I can’t control how big the images are!

I have the obligatory column embiggener html code at the top

```julia
html"""<style>
main {
    max-width: 96%;
    margin-left: 1%;
    margin-right: 2% !important;
}
</style>
"""

```

but the images seem to refuse to grow bigger beyond a particular point. I have Images.jl loaded which loads ImageShow, but I want to fill up the screen! How do I change the image display size?

As I make the images bigger, they get bigger…

 ![Screenshot 2024-05-31 at 11.12.20](https://global.discourse-cdn.com/julialang/original/3X/1/1/11ba0d0553881a5b817913635a08f16d014b0581.jpeg)

and then past a certain threshold they get smaller again to some predetermined fixed size which cannot be changed.

 ![Screenshot 2024-05-31 at 11.13.23](https://global.discourse-cdn.com/julialang/original/3X/7/2/729cf9aeee6cfd13379080e9dbdb1939e3ba3449.jpeg)

Further increasing the size of the figure ~~does nothing~~ increases the size until a certain threshold is reached at which point the image size is reduced again.  
Thanks for the help!

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [May 31, 2024, 9:37am UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/2 "2024-05-31T09:37:49Z")

</div>

Cannot reproduce using empty `Figure`s from Makie.jl in a notebook I had running.

I put your html snippet in and made several empty figures with different sizes and they just grow until they fill out the space. So I am not sure what causes this shrinking for you. Did you try to inspect the CSS and DOM using the developer tools? Maybe Images.jl somehow does some shrinking of the output if it thinks it too big for the screen? I don’t think Pluto.jl is to blame here.

---

<div class="post-metadata">

**Author:** ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Post date:** [May 31, 2024, 11:09am UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/3 "2024-05-31T11:09:31Z")

</div>

Im not a html person really but I found the element, the png resource in “blob” is itself stored at a lower resolution, does that mean its a problem with [Images.jl](https://juliahub.com/ui/Packages/General/Images)?

What excatly determines how the output is saved as an html resource?

```julia
<pluto-output class="rich_output " ...
aria-label="Result of unlabeled cell:" 
mime="image/png">

<assignee aria-hidden="true" translate="no">
</assignee><div>
<img type="image/png" src="blob:http://localhost:1240/5ab27dbf-6439-48a0-b701-07b6d4a2dcd4"></div></pluto-output>

```

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [May 31, 2024, 11:46am UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/4 "2024-05-31T11:46:24Z")

</div>

Do these styles from PlutoStyles.jl work for your images?

> <https://github.com/JuliaAPlavin/PlutoStyles.jl/blob/000000002eb840a04606895f6d63e6f21d022214/src/PlutoStyles.jl#L62-L72>

---

<div class="post-metadata">

**Author:** ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Post date:** [May 31, 2024, 12:33pm UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/5 "2024-05-31T12:33:00Z")

</div>

Im not sure Im currently able to get pluto styles working, but I get the same behaviour with

```julia
using PlutoStyles
import pluto
Pluto.run()

```

(thats the defaults right?)

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [May 31, 2024, 12:36pm UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/6 "2024-05-31T12:36:05Z")

</div>

Do you have an MWE image to demonstrate the effect?

---

<div class="post-metadata">

**Author:** ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Post date:** [May 31, 2024, 12:58pm UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/7 "2024-05-31T12:58:57Z")

</div>

```julia
begin
	using Images
	using TestImages
end
# run in successive cells to see fabio 
# get larger and then smaller again.
imresize(testimage("fabio_color_512"); ratio= 1.0)
imresize(testimage("fabio_color_512"); ratio= 1.5)
imresize(testimage("fabio_color_512"); ratio= 2.0)

```

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [May 31, 2024, 1:27pm UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/8 "2024-05-31T13:27:55Z")

</div>

Yeah I think it’s not a pluto/css issue, images shown get smaller in terms of number of pixels.

---

<div class="post-metadata">

**Author:** ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Post date:** [May 31, 2024, 1:41pm UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/9 "2024-05-31T13:41:30Z")

</div>

Ok yeah you can see that images are size controlled carefully on the output in the ImageShow package.

> <https://github.com/JuliaImages/ImageShow.jl/blob/05ec585f91673f96fdd5d5885a1fad719affb917/src/showmime.jl#L29C1-L29C9>

I guess since pluto just reuses show methods, this code (prevents your terminal from exploding with giant arrays) gets in the way. The modularity comes from using `restrict` factor-of-2 downsampling for speed. So I will try and remove this dependency and report back.

Edit: without ImageShow I cant display the images properly. ~~maybe someone knows how to coordinate the `iocontext :thumbnailsize` with the base size of the image?~~

Edit2: I guess actually its the maxpixel term in corrected linked method here. How do I pass a different maxpixel keyword? I dont know what IO variable pluto is sending show.

I can overwrite the method buuuut seems a little risky.

---

<div class="post-metadata">

**Author:** ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Post date:** [June 1, 2024, 10:04pm UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/10 "2024-06-01T22:04:38Z")

</div>

The problem is that the show method in ImagesShow

```julia
Base.show(io::IO, mime::MIME"image/png", img::AbstractMatrix{C};
                   minpixels=10^4, maxpixels=10^6)

```

enforces this maxpixels keyword by default (or unless get(io,:full\_fidelity) == true).

But I don’t know how to increase the maxpixels keyword to show in the Pluto context. Here are some ideas.

1. save the image directly as a resource for the html code to find in a way that mimics Plutos internal methods that call show.
2. Pass a keyword, say maxpixels=10^7 to a show call somewhere inside Pluto (remember, pluto will just try and REshow the output of a show call)
3. set somewhere in stdout::IO a field `:full_fidelity` to `true` (how ???)
4. Overwrite this show method from inside the the package module, maybe using `ImageShow.eval`?
5. submit a PR to ImageShow requesting that maxpixels be increased by a factor of 10 (would change behaviour around the julia ecosystem).

urrgh. Which idea is the least stupid?

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [June 2, 2024, 6:05am UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/11 "2024-06-02T06:05:00Z")

</div>

> [@cdawg](#):
>
> Overwrite this show method from inside the the package module, maybe using `ImageShow.eval`?

I think I would do this but you don’t need to use eval. Just copy the relevant code of ImageShow where it defines the method in Base and add that to your notebook. That is sufficient to overwrite the method (and will cause some recompilation once). If the method is rather complex and uses a lot of ImageShow internals, then maybe you can find a simpler method to overwrite higher in the call stack.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [June 2, 2024, 6:07am UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/12 "2024-06-02T06:07:05Z")

</div>

> [@cdawg](#):
>
> - Pass a keyword, say maxpixels=10^7 to a show call somewhere inside Pluto (remember, pluto will just try and REshow the output of a show call)
> - set somewhere in stdout::IO a field `:full_fidelity` to `true` (how ???)

Also pinging @fonsp. He probably knows best how to customize the display within Pluto.jl

---

<div class="post-metadata">

**Author:** ![cdawg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cdawg/32/9811_2.png) [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Post date:** [June 2, 2024, 7:49am UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/13 "2024-06-02T07:49:25Z")

</div>

Ok! I got the method overwritten, actually without any definitions from ImageShow.

```julia
function Base.show(io::IO, mime::MIME"image/png", img::AbstractMatrix{C}) where {C<:Colorant}
        FileIO.save(FileIO.Stream{format"PNG"}(io), img)
end

```

and now everything is scaled to fit the window! It still kinda bothers me though that theres a keyword that does what I want and I cant use it but thats an aesthetic issue. I can go ahead and remove ImageShow entirely as a dependency.

---

<div class="post-metadata">

**Author:** ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)\
**Post date:** [June 8, 2024, 3:15pm UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/14 "2024-06-08T15:15:08Z")

</div>

Yep this is a feature of ImageShow! There is actually a way to control the IO context, using `PlutoUI.WithIOContext`. Normally, this lets you change flags for just that one render, like `: full_fidelity => true`.

But it’s not working in this very special case because of [this whole thing](https://github.com/JuliaImages/ImageShow.jl/pull/51)…, and the HTML show method does not seem to get the IO context… weird! Well, I tried!

---

<div class="post-metadata">

**Author:** ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)\
**Post date:** [June 8, 2024, 3:35pm UTC](https://discourse.julialang.org/t/making-images-as-big-as-possible-max-width-in-pluto-notebooks/115003/15 "2024-06-08T15:35:03Z")

</div>

I made [html show method: use IOContext from original renderer by fonsp · Pull Request #60 · JuliaImages/ImageShow.jl · GitHub](https://github.com/JuliaImages/ImageShow.jl/pull/60) to fix this, after that PR and release you can do:

```julia
WithIOContext(
	some_image,
	:full_fidelity => true,
)

```

to tell ImageShow.jl not to downscale the image.
