4

I'd like to make code Cells have a specific background image. I know you can do this for Notebooks, but what about Cells?

This simple test fails:

ConvertImageToFullyScaledNinePatch[img_] := 
  Module[{paddedImage = ImagePad[img, 1, Black]}, 
   ReplaceImageValue[paddedImage, 
    Flatten[Outer[List, {0, #1}, {0, #2}] & @@ 
       ImageDimensions[paddedImage], 1] -> White]];

img = ConvertImageToFullyScaledNinePatch[
   ExampleData[{"TestImage", "JellyBeans"}]];

CellPrint@Cell["test", "Code", BackgroundAppearance -> img]
M.R.
  • 31,425
  • 8
  • 90
  • 281

1 Answers1

3

Probably not ideal, but using OverlayBox (undocumented) can get you something:

img = ConvertImageToFullyScaledNinePatch[
               Import["https://addons.cdn.mozilla.net/static/img/docs/themes/header.jpg"]
      ];


CellPrint[
 Cell[BoxData[
   OverlayBox[{ToBoxes[img], "test"}, Alignment -> Center]], "Code", 
  CellFrameMargins -> 0, CellMargins -> 0, PageWidth -> 1600]]

Mathematica graphics

chuy
  • 11,205
  • 28
  • 48