# Images as labels - resizing problem

I'd like to label a pie chart with images, ideally resized to fit inside the sectors. The problem is I can't seem to control the size of the imported images. Here's an MWE with no attempt at resizing, pie chart image size of 1000;

a = Import["strawman.png"];
a2 = RemoveBackground[a];
b = Import["cherry.png"];
b2 = RemoveBackground[b];
c = Import["burden.png"];
c2 = RemoveBackground[c];
d2 = RemoveBackground[d];
PieChart[{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, SectorOrigin -> {Automatic, 2},
ChartLabels -> {a2, b2, "blank", c2, "blank2", d2}, ImageSize -> 1000]


This results in an image like this;

I initially thought I could just resize these images, but the problem is that simply reduces the quality and not the size- it seems ImageSize is overwriting everything. For example, if I try and make the scarecrow resized to 50 pixels with

  a2 = ImageResize[a2,50]


all this does is severely pix-elate the scarecrow element as below, with no impact on size:

Is there a clever way around this? I've tried Inset and Epilog and had no obvious joy with them either.

• try Magnify, e.g., Magnify[a2,.2]? – kglr Jun 4 '19 at 17:09

You could use Pane instead of ImageResize:. For example:

a1 = Pane[ExampleData[{"TestImage","Lena"}], 30];
a2 = Pane[ExampleData[{"TestImage", "Aerial"}], 40];

PieChart[
ConstantArray[1, 15],
SectorOrigin->{Automatic,2},
ChartLabels -> {a1,"blank",a2,"blank2"}
]


• Absolutely perfect, cheers! – DRG Jun 4 '19 at 17:45

As an alternative to using images as labels we can use them as Texture for sectors with a custom ChartElementFunction:

ClearAll[cedF]
cedF[opt_: "Fill"] := Module[{cedf = If[Head[#3[[1]]] === Texture,
SystemBarFunctionDumpTextureRadius[#, #2, "Placement" -> opt] /. _Texture :> #3[[1]]&,
ChartElementDataFunction["Sector"][##] &]}, cedf[##]] &


Examples:

textures = Texture[Rasterize @ Thumbnail[#, Small]]& /@
ExampleData[{"TestImage", #}] & /@ {"Lena", "Apples", "Mandrill", "Flower"};


Attach textures to input data as metadata:

data = Thread[ConstantArray[1, 6] -> Join[textures, {Red, Blue} ]];


With default value of the argument ("Fill") a picture is cropped to the shape of the associated sector:

PieChart[data, SectorOrigin -> {Automatic, 1}, ChartElementFunction -> cedF[]]


With ChartElementFunction -> cedF["StretchToFill"]:

and with ChartElementFunction -> cedF["Tile"]: