4
$\begingroup$

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]
$\endgroup$
  • $\begingroup$ Without a link to the earlier Q&A ConvertImageToFullyScaledNinePatch is without context so I added a link. I hope you don't mind. $\endgroup$ – Mr.Wizard May 20 '16 at 17:41
  • $\begingroup$ Ah, I meant to include that, thanks! $\endgroup$ – M.R. May 20 '16 at 17:42
3
$\begingroup$

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

$\endgroup$
  • 2
    $\begingroup$ Since it is not editable anyway you can use documented Overlay. $\endgroup$ – Kuba May 20 '16 at 18:36
  • $\begingroup$ @Kuba You are right of course, no need to get all complicated. $\endgroup$ – chuy May 20 '16 at 18:41
  • $\begingroup$ in reflection this is kind of a bad solution, but maybe someone can use it find a better one. $\endgroup$ – chuy May 20 '16 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.