2

Ive searched for hours ... but Im at a loss !

I have imported an image int Mathematica -> dimensions 2x2cm at 72DPI.

I am trying to "label" the image with a text string that: - has font color "fontColor" - has a black outline, so it contrasts to any underlying color - sits in the bottom right corner of the imported image - has size h/w in cm - optionally sits in a text box with a white background

This is how far ive come:

MathCode:

image = Import["myimg.jpg"];
inchFactor = 2.54;(* 1 inch = 2.54cm *)
docRes = 72;
pixelConverter = docRes/inchFactor/2;

myText = First[
   First[ImportString[
     ExportString[
      Style["glorious label string here", Bold, FontSize -> 15, 
       FontFamily -> "Verdana"], "PDF"], "PDF", 
     "TextMode" -> "Outlines"]]];

myTextGraphic = 
  Graphics[{EdgeForm[Directive[Black, Thickness[0.01]]], White, 
    myText}, Background -> White, 
   ImageSize -> {10*pixelConverter, 2*pixelConverter}];
myTextGraphic = Rasterize[myTextGraphic];

combined = SetAlphaChannel[myTextGraphic, myTextGraphicAlphaVersion];

I found the above method (PDF wrapper) for the black outline of the text string.

I am adding an AlphaChannel to the graphic of the text string using a version of it that only uses black/white.

I then try to combine the images with Overlay.

As none of this seems to work concerning the outputted image size and positioning, Im kindly asking for help. There´s no need to "fix" that messy code.

Maybe you could point me to a script or tutorial - all I really want is to add and position a text string or text box to an underlying image.

Thanks a lot !

4

2 回答 2

2

看看这个。还有其他方法。

img = Import["http://todayinsci.com/H/Hilbert_David/HilbertDavidThm.jpg"];

Column[{
  img,
  Text[Style["Professor Hilbert", Red]]
}]

imgCtr = Round[ImageDimensions[img]/2];

overlay = Framed[Graphics[{Text[Style["Professor Hilbert", Red, 9], imgCtr]},ImageSize-> {66, 14}], FrameStyle -> Green]

Overlay[{img, overlay}, Alignment -> Center]
于 2013-03-20T23:21:58.883 回答
1

这里已经很晚了,所以这只是为您提供解决方案的开始,但这是向图像添加文本标签的简单方法:

lbl = Graphics[Text[Style["Bottom", Red, Large]]]

它会创建一个带有大字体红色文本“底部”的图像。接下来,给定一个名为img1

ImageCompose[img1,lbl]

将文本放在图像的中心。 ImageCompose具有允许您在第一张图像上放置第二张图像(即标签)的选项。您可以将标签放在彩色背景上,如下所示:

lbl = Graphics[Text[Style["Bottom", Red, Large, Background -> Blue]]]

我还没有弄清楚如何用彩色轮廓编写文本。

于 2013-03-19T22:51:18.270 回答