How can I use words/letters as pixels in an image?
Here is a crude attempt, just using a monospace font and arbitrarily breaking the words..
i = 0;
alice = ExampleData[{"Text", "AliceInWonderland"}];
i0 = Binarize@ImageResize[ ExampleData[{"TestImage", "Lena"}] , {100}];
r = {ImageCrop[
Rasterize[
Style[StringJoin@#, FontSize -> 20, FontFamily -> "Courier",
FontWeight -> "Bold"], RasterSize -> {800, 30},
ImageSize -> {800, 30}], {800, 7}]} & /@
Map[ If[# == 0, StringTake[alice, {++i}] , " " ] & ,
ImageData@i0 , {2} ] ;
Row[ {Show[i0, ImageSize -> 260],
Show[ImageAssemble[r], ImageSize -> 300]}]
ImageTake[ ImageAssemble[r] , {1, 100}, {1, 300}]
When I read your title, I thought "I know how to use letters as pixels of an image..." and answered. But then I re-read your question and realized that it was different altogether. Maybe some part of this will be useful...
One approach is to rasterize all the letters, then scan through the picture and find out which letter is closest to the image at each point. Start by generating a collection of rasterized letters (for simplicity later on, make them all the same size).
allChar = Characters[
"abcdefghijklmnopqrstuvwxyz!@#$%^&*()_+1234567890-=;:'\"/?.>,<~`|\\\\ "];
allLetsUnequal =
Rasterize[
Style[#, FontSize -> 20, FontFamily -> "Courier",
FontWeight -> "Bold"], RasterSize -> 20] & /@ allChar;
allSizes = ImageDimensions[#] & /@ allLetsUnequal;
maxSize = {Max[allSizes[[All, 1]]], Max[allSizes[[All, 2]]]};
allLetsPos =
ImageAdd[Image[ConstantArray[0, RotateRight@maxSize]], #] & /@
allLetsUnequal; allLetsNeg = ColorNegate[#] & /@ allLetsPos;
allLets = Flatten[{allLetsPos, allLetsNeg}];
Now grab an image and partition it. Use a Nearest function to find the best letter for each partition.
img = Import["http://i.stack.imgur.com/fVXtV.png"];
img2 = ImageResize[img, 900];
imgParts = ImagePartition[img2, maxSize];
dims = Dimensions[imgParts];
nf = Nearest[allLets];
asciiLets =
Table[First@nf[imgParts[[i, j]]], {i, 1, First@dims}, {j, 1,
Last@dims}];
ImageAssemble[asciiLets]