# How can I set an image to be the Notebook's background?

Is it possible to set a notebook's background to a nonscrolling image?

-
I remember looking for this once. There isn't an option for it. You can only change the background color. –  Searke Jun 18 '12 at 15:00
I don't see anything in the Option Inspector. I also don't think it can be done programatically. –  becko Jun 29 '12 at 1:48
The closest I can think of is a scrollable Pane on top of a background, which isn't very good. Note that this will be possible in v9, but not documented (see the chat log in the Mathematica chat room for evening, Oct. 21, where I discuss why that's the case). When v9 ships, I'll swing back around and answer this question. –  John Fultz Oct 25 '12 at 12:57

In version 9 there is a new option called BackgroundAppearance that can be used to set the notebook's background.

The picture below was made by setting this option in the option inspector to FrontEndFileName[{"SlideShow"}, "WaterTitleBackground.png"]

-
In John's comment above he said this option is undocumented. Is that the case? Looks nice though. –  Mike Honeychurch Nov 30 '12 at 22:56
@MikeHoneychurch If it is documented it's hidden well. –  Sjoerd C. de Vries Nov 30 '12 at 23:10

In version 9, Mathematica includes a feature for doing background images which was implemented for slide shows. However, it wasn't documented because, although enough support was included for slide shows, the feature has distinct limitations which shouldn't be enshrined in documentation, and its usage is not the most straightforward at this point. I'll discuss its usage, but I must emphasize that it was left undocumented for a reason. Slide show notebooks will certainly be forward compatible with future versions of Mathematica, but edge cases experimentally discovered by users may not be forward compatible.

The option is BackgroundAppearance, and it can take either an Image or a fully qualified filename reference. However, it can't accept just any image. It accepts an image following the nine-patch convention defined by the Android SDK. I won't fully explain nine-patch here, but in brief, it's a very nice convention for customizing the scaling behavior of bitmaps which can be used to produce near-vector-quality resizable graphics from bitmap specifications. A nice tutorial describing the principles can be found here. For the purposes of notebook backgrounds, the "fill" specifications are ignored, but they must still be present in the image.

The most trivial form of a nine-patch image is one that scales the entire image. Such an image would have a fully black frame with white pixels in each of the corners. Here's a function which modifies an image to a nine-patch which scales the entire image:

ConvertImageToFullyScaledNinePatch[img_] :=
Flatten[
Outer[List, {0, #1}, {0, #2}] & @@ ImageDimensions[paddedImage],
1] -> White]]


And here's an example of the function's usage:

NotebookPut[
Notebook[{},
SystemBackgroundAppearance ->
ConvertImageToFullyScaledNinePatch[
ExampleData[{"TestImage", "JellyBeans"}]]]]


Additionally, the front end only presently understands a limited subset of possible color spaces for the image, which may exclude, for example, images which are imported from some types of external files.

Some of the images used for slide shows have more customized scaling behaviors than the one I demonstrated here. Those images can be listed by the following command:

FileNames["*", {FileNameJoin[{\$InstallationDirectory, "SystemFiles",
"FrontEnd", "SystemResources", "SlideShow"}]}]


I would expect that, in a future version of Mathematica, you may see a different option name, a much more flexible specification of possible right-hand side values, and first-class support for nine-patch bitmaps.

-
Great! This seems a good method to simulate a transparent background for notebooks! –  Silvia Dec 2 '12 at 14:23
It seems to be unnecessary to transform the image in v9.0.1. Was that added in that update? –  Sjoerd C. de Vries Mar 13 '13 at 13:30