(************** Content-type: application/mathematica ************** CreatedBy='Mathematica 5.1' Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 12715, 373]*) (*NotebookOutlinePosition[ 13908, 413]*) (* CellTagsIndexPosition[ 13805, 406]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Make a web page showing your photos", "Title"], Cell[TextData[{ "Part of the \"Learn ", StyleBox["Mathematica", FontSlant->"Italic"], " by reading code\"" }], "Subtitle"], Cell["\<\ Luc Barthelet May 2005\ \>", "Subsubtitle"], Cell["\<\ This notebook will make a web page and image thumbnails out of a directory \ full of JPGs\ \>", "Text"], Cell[CellGroupData[{ Cell["Let's set up our folder names first", "Section"], Cell["This is the name of the folder with the jpgs", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(folderName = ToFileName[{"\", "\"}]\)], "Input"], Cell[BoxData[ \(TraditionalForm\`"C:\\webSample\\"\)], "Output"] }, Open ]], Cell["and inside it we have a folder named \"thumbs\"", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(destFolder = ToFileName[{"\", "\", "\"}]\)], "Input"], Cell[BoxData[ \(TraditionalForm\`"C:\\webSample\\thumbs\\"\)], "Output"] }, Open ]], Cell["if the folders are not created then make it,.", "Text"], Cell[BoxData[ \(If[MemberQ[{$Failed, {}}, \ FileInformation[destFolder]\ ], CreateDirectory[destFolder]]\)], "Input"], Cell["Let's see the names of the jpgs", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(allPics = FileNames["\<*.jpg\>", folderName]\)], "Input"], Cell[BoxData[ \(TraditionalForm\`{"C:\\webSample\\288322_01.jpg", "C:\\webSample\\288322_02.jpg", "C:\\webSample\\288322_03.jpg", "C:\\webSample\\288322_04.jpg", "C:\\webSample\\288322_05.jpg", "C:\\webSample\\288322_06.jpg", "C:\\webSample\\288322_07.jpg"}\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Now we create the thumbnails of the JPG using mathematica", "Section"], Cell["\<\ This first function will create an ImageSize option respecting the ratio \ but\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(maxWidth = 400. ;\)\), "\[IndentingNewLine]", \(\(makeImageSize[{w_, h_}] := \[IndentingNewLine]ImageSize \[Rule] If[w > maxWidth, {maxWidth, Round[h/w*maxWidth]}, {w, h}];\)\), "\[IndentingNewLine]", \(\(\(Print["\", #, "\<]=\>", makeImageSize[#]\ ] &\)\ /@ \ {{100, 200}, {640, 480}, {400, 100}};\)\)}], "Input"], Cell[BoxData[ FormBox[ InterpretationBox[\("makeImageSize["\[InvisibleSpace]{100, 200}\[InvisibleSpace]"]="\[InvisibleSpace]\(ImageSize \[Rule] \ {100, 200}\)\), SequenceForm[ "makeImageSize[", {100, 200}, "]=", ImageSize -> {100, 200}], Editable->False], TraditionalForm]], "Print"], Cell[BoxData[ FormBox[ InterpretationBox[\("makeImageSize["\[InvisibleSpace]{640, 480}\[InvisibleSpace]"]="\[InvisibleSpace]\(ImageSize \[Rule] \ {400.`, 300}\)\), SequenceForm[ "makeImageSize[", {640, 480}, "]=", ImageSize -> {.4*^3, 300}], Editable->False], TraditionalForm]], "Print"], Cell[BoxData[ FormBox[ InterpretationBox[\("makeImageSize["\[InvisibleSpace]{400, 100}\[InvisibleSpace]"]="\[InvisibleSpace]\(ImageSize \[Rule] \ {400, 100}\)\), SequenceForm[ "makeImageSize[", {400, 100}, "]=", ImageSize -> {400, 100}], Editable->False], TraditionalForm]], "Print"] }, Open ]], Cell["\<\ This function reads the image and makes the thumbnail with the same name but \ in the thumb folder. of course the thumbnail will be the proper size.\ \>", "Text"], Cell[BoxData[{ \(makeThumb[fileName_] := Module[{data, destName}, \[IndentingNewLine]data = Import[fileName]; \[IndentingNewLine]Export[ StringReplace[fileName, folderName \[Rule] destFolder], data, makeImageSize[\((ImageSize\ /. \ FullOptions[ data])\)]]\[IndentingNewLine]]; \), "\[IndentingNewLine]", \(makeThumb[allPics[\([\)\(1\)\(]\)]]; \)}], "Input"], Cell["This does the work:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(makeThumb\ /@ \ allPics\)], "Input"], Cell[BoxData[ \(TraditionalForm\`{"C:\\webSample\\thumbs\\288322_01.jpg", "C:\\webSample\\thumbs\\288322_02.jpg", "C:\\webSample\\thumbs\\288322_03.jpg", "C:\\webSample\\thumbs\\288322_04.jpg", "C:\\webSample\\thumbs\\288322_05.jpg", "C:\\webSample\\thumbs\\288322_06.jpg", "C:\\webSample\\thumbs\\288322_07.jpg"}\)], "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Create the hmtl file:", "Section"], Cell["\<\ This first function transform a two dimensional matrix of strings into an \ html table\ \>", "Text"], Cell[BoxData[ \(\(\(\[IndentingNewLine]\)\(HTMLTable[ matrixOfString_] := \[IndentingNewLine]"\<\n\>" <> \((StringJoin\ @@ \ Map["\<\>" <> \((StringJoin\ @@ \ #)\) <> "\<\n\>" &, Map["\<\n\>" &, matrixOfString, {2}], {1}])\) <> "\<
\>" <> ToString[#] <> "\<
\n\>";\)\)\)], \ "Input", CellTags->{"HTML Functions", "All"}], Cell["\<\ This shows how to use partition to create a two dimensional matrix from a \ list of number. We will use something similar for the photos. Notice that we \ filled the empty elements with empty strings.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Partition[Range[7], 4, 4, {1, 1}, {"\<\>", "\<\>"}]\)], "Input"], Cell[BoxData[ FormBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"1", "2", "3", "4"}, {"5", "6", "7", "\<\"\"\>"} }, RowSpacings->1, ColumnSpacings->1, ColumnAlignments->{Left}], "\[NoBreak]", ")"}], TraditionalForm]], "Output"] }, Open ]], Cell["\<\ This function returns the last part of a filename separated from the list of \ folders.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(FromFileName[path_String] := Module[{dir, thisFile}, \[IndentingNewLine]\(\((dir = Most[#]; thisFile = #[\([\)\(-1\)\(]\)])\) &\)@ StringSplit[path, $PathnameSeparator | "\", All]; \[IndentingNewLine]If[ Length[dir] > 0 && dir[\([\)\(1\)\(]\)] == "\<\>", dir[\([\)\(1\)\(]\)] = $PathnameSeparator]; \[IndentingNewLine]If[ Length[dir] == 1, dir = dir[\([\)\(1\)\(]\)]]; \[IndentingNewLine]If[ thisFile == "\<\>", {dir}, {dir, thisFile}]\[IndentingNewLine]];\)\), "\[IndentingNewLine]", \(FromFileName[allPics[\([1]\)]\ ]\)}], "Input"], Cell[BoxData[ \(TraditionalForm\`{{"C:", "webSample"}, "288322_01.jpg"}\)], "Output"] }, Open ]], Cell["\<\ This creates the html code to display a thumbnail image for a given filename.\ \ \>", "Text"], Cell[BoxData[ \(ShowImageLink[imageName_] := Module[{fileOnly}, \[IndentingNewLine]fileOnly = \(FromFileName[ imageName]\)[\([\)\(-1\)\(]\)]; \[IndentingNewLine]"\<" <> fileOnly <> "\<\" border=0>\>"\[IndentingNewLine]]\)], "Input", InitializationCell->True, CellTags->{"HTML Functions", "All"}], Cell["\<\ This creates a full html link from an image name. it shows the thumbnail, and \ if you click on it shows the full image\ \>", "Text"], Cell[BoxData[ \(MakeThumbLink[imageName_] := Module[{fileOnly}, \[IndentingNewLine]If[ StringLength[imageName] > 0, \[IndentingNewLine]fileOnly = \(FromFileName[ imageName]\)[\([\)\(-1\)\(]\)]; \[IndentingNewLine]"\<" <> ToString[fileOnly\ ] <> "\<\">\>" <> ShowImageLink[ imageName] <> "\<\>", \[IndentingNewLine]"\<.\>"]\ \[IndentingNewLine]]; \)], "Input"], Cell["This is the basic code for an HTML file as text", "Text"], Cell[BoxData[ \(\(pageText = StringJoin[\[IndentingNewLine]"\<", \ \[IndentingNewLine]"\<\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.\ dtd\"> \n\>", \[IndentingNewLine]"\<\n\>", \[IndentingNewLine]"\<\n\>", \[IndentingNewLine]"\< \n\>", \[IndentingNewLine]"\< \ Photos\n\>", \[IndentingNewLine]"\< \n\>", \ \[IndentingNewLine]"\<\n\>", \[IndentingNewLine]"\<\n\>", \ \[IndentingNewLine]"\< \n\>", \[IndentingNewLine]"\< PAGECONTENT\n\ \>", \[IndentingNewLine]"\< \n\>", \[IndentingNewLine]"\<\n\ \>"];\)\)], "Input"], Cell["\<\ This final cell does the complete job of creating the page. each file name become a thumbnail with a link. It is transformed into a \ matrix of links and then into an html table. Finally that html code replaces \ the PAGECONTENT above.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(htmlFileName\ = \ ToFileName[folderName, "\"]\)], "Input"], Cell[BoxData[ \(TraditionalForm\`"C:\\webSample\\index.html"\)], "Output"] }, Open ]], Cell[BoxData[ \(\(Export[htmlFileName, StringReplace[ pageText, "\" -> \[IndentingNewLine]\((\ HTMLTable[\[IndentingNewLine]Map[MakeThumbLink, Partition[allPics, 3, 3, {1, 1}, {"\<\>", "\<\>"}], {2}]\[IndentingNewLine]]\ \[IndentingNewLine])\)], "\"];\)\)], "Input"], Cell["We check the results as a text file:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Import[htmlFileName, "\"]\)], "Input"], Cell[BoxData[ \(TraditionalForm\`" \n\n\n \n Photos\n \n\n\ \n \n \n\n\n\n\n\n\n\n\n\n\n\n\n
..
\n\n \n\ \n"\)], "Output"] }, Open ]] }, Open ]], Cell["You can use your web browser to check the results as HTML!", "Section"] }, Open ]] }, FrontEndVersion->"5.1 for Microsoft Windows", ScreenRectangle->{{0, 1920}, {0, 1083}}, AutoGeneratedPackage->None, WindowSize->{1330, 973}, WindowMargins->{{98, Automatic}, {35, Automatic}}, Magnification->1 ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{ "HTML Functions"->{ Cell[6421, 211, 450, 8, 90, "Input", CellTags->{"HTML Functions", "All"}], Cell[8589, 275, 374, 7, 90, "Input", InitializationCell->True, CellTags->{"HTML Functions", "All"}]}, "All"->{ Cell[6421, 211, 450, 8, 90, "Input", CellTags->{"HTML Functions", "All"}], Cell[8589, 275, 374, 7, 90, "Input", InitializationCell->True, CellTags->{"HTML Functions", "All"}]} } *) (*CellTagsIndex CellTagsIndex->{ {"HTML Functions", 13363, 390}, {"All", 13577, 396} } *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1776, 53, 52, 0, 95, "Title"], Cell[1831, 55, 132, 5, 52, "Subtitle"], Cell[1966, 62, 53, 3, 50, "Subsubtitle"], Cell[2022, 67, 113, 3, 33, "Text"], Cell[CellGroupData[{ Cell[2160, 74, 54, 0, 73, "Section"], Cell[2217, 76, 60, 0, 33, "Text"], Cell[CellGroupData[{ Cell[2302, 80, 85, 1, 30, "Input"], Cell[2390, 83, 68, 1, 29, "Output"] }, Open ]], Cell[2473, 87, 63, 0, 33, "Text"], Cell[CellGroupData[{ Cell[2561, 91, 106, 2, 30, "Input"], Cell[2670, 95, 76, 1, 29, "Output"] }, Open ]], Cell[2761, 99, 61, 0, 33, "Text"], Cell[2825, 101, 128, 2, 30, "Input"], Cell[2956, 105, 47, 0, 33, "Text"], Cell[CellGroupData[{ Cell[3028, 109, 77, 1, 30, "Input"], Cell[3108, 112, 303, 5, 29, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[3460, 123, 76, 0, 73, "Section"], Cell[3539, 125, 102, 3, 33, "Text"], Cell[CellGroupData[{ Cell[3666, 132, 417, 7, 90, "Input"], Cell[4086, 141, 331, 7, 25, "Print"], Cell[4420, 150, 335, 7, 25, "Print"], Cell[4758, 159, 331, 7, 25, "Print"] }, Open ]], Cell[5104, 169, 172, 3, 33, "Text"], Cell[5279, 174, 441, 8, 110, "Input"], Cell[5723, 184, 35, 0, 33, "Text"], Cell[CellGroupData[{ Cell[5783, 188, 57, 1, 30, "Input"], Cell[5843, 191, 373, 7, 48, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[6265, 204, 40, 0, 73, "Section"], Cell[6308, 206, 110, 3, 33, "Text"], Cell[6421, 211, 450, 8, 90, "Input", CellTags->{"HTML Functions", "All"}], Cell[6874, 221, 224, 4, 33, "Text"], Cell[CellGroupData[{ Cell[7123, 229, 84, 1, 30, "Input"], Cell[7210, 232, 307, 9, 45, "Output"] }, Open ]], Cell[7532, 244, 111, 3, 33, "Text"], Cell[CellGroupData[{ Cell[7668, 251, 708, 13, 150, "Input"], Cell[8379, 266, 89, 1, 29, "Output"] }, Open ]], Cell[8483, 270, 103, 3, 33, "Text"], Cell[8589, 275, 374, 7, 90, "Input", InitializationCell->True, CellTags->{"HTML Functions", "All"}], Cell[8966, 284, 143, 3, 33, "Text"], Cell[9112, 289, 454, 9, 130, "Input"], Cell[9569, 300, 63, 0, 33, "Text"], Cell[9635, 302, 762, 12, 290, "Input"], Cell[10400, 316, 259, 5, 52, "Text"], Cell[CellGroupData[{ Cell[10684, 325, 92, 1, 30, "Input"], Cell[10779, 328, 78, 1, 29, "Output"] }, Open ]], Cell[10872, 332, 365, 7, 110, "Input"], Cell[11240, 341, 52, 0, 33, "Text"], Cell[CellGroupData[{ Cell[11317, 345, 65, 1, 30, "Input"], Cell[11385, 348, 1210, 18, 523, "Output"] }, Open ]] }, Open ]], Cell[12622, 370, 77, 0, 87, "Section"] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)