http://gildang.co.kr/?p=2331



    php에서 python 결과 출력하기 시도를 한 과정입니다.


    안녕하세요, 저는 길당 홍길한이라 합니다.
    한동안 저는 php 에서 다음과 같은 python code를

    1. #!/usr/bin/python
    2. import pandas as pd
    3. import numpy as np
    4. import matplotlib.pyplot as plt
    5. import matplotlib
    6. matplotlib.style.use('ggplot')
    7. ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
    8. ts = ts.cumsum()
    9. plt.figure()
    10. ts.plot()
    11. plt.savefig("foo.png", bbox_inches='tight')

    어떻게 하면
    표현할 수 있을지 고민을 하여 왔습니다.

    그래서 오늘 고민 끝에 우선 다음과 같이 위의 코드를 실행하고 나면,
    foo.png라는 파일이 생성되고 ,

    그 파일을 다음과 같이

    html 파일에 img 태그로 insert 하여 준 다음에,

    1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    3. <head>
    4. <title>Good morning</title>
    5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    6. <link rel="Stylesheet" type="text/css" href="goodmorning.css" />
    7. </head>
    8. <body>
    9. <div id="container">
    10. <div id="header">
    11. <h1> Your website name </h1>
    12. <ul id="mainmenu">
    13. <li class="active"><a href="http://all-free-download.com/free-website-templates/">Home</a></li>
    14. <li><a href="http://all-free-download.com/free-website-templates/">About</a></li>
    15. <li><a href="http://all-free-download.com/free-website-templates/">Contact</a></li>
    16. <li><a href="http://all-free-download.com/free-website-templates/">Guestbook</a></li>
    17. <li><a href="http://all-free-download.com/free-website-templates/">Links</a></li>
    18. </ul>
    19. </div>
    20. <div id="content">
    21. <!-- CONTENT START -->
    22. <h2>About the Template</h2>
    23. <p>The header image is a drawing I made a long time ago for some other design, but it was not used.
    24. It's pretty simple-looking, and I believe it makes a great blog template.</p>
    25. <p>It's tested in <a href="http://all-free-download.com/free-website-templates/">Mozilla Firefox 2.0</a>, <a href="http://all-free-download.com/free-website-templates/">Internet Explorer 6 &amp; 7</a>, <a href="http://all-free-download.com/free-website-templates/">Opera 9</a>, and <a href="http://all-free-download.com/free-website-templates/">Netscape 7.2</a>,
    26. on resolution 800x600 and
    27. 1024x768, and works good in each of the mentioned. It is also validated <a href="http://validator.w3.org/check?uri=referer">XHTML</a> and <a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>. </p>
    28. <h2>Terms of Service</h2>
    29. <p>This work is released under the <a href="http://creativecommons.org/licenses/by-nc-nd/2.5/" title="Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License">Creative Commons Licence</a>.</p>
    30. <ol>
    31. <li>Leave the credit and link back to http://inobscuro.com/http://inobscuro.com/</a> visible.</li>
    32. <li>Do not redistribute.</li>
    33. <li>Personal, non-profit use only.</li>
    34. <li>Derivative work prohibited.</li>
    35. </ol>
    36. <h2>Instructions for Installation</h2>
    37. <ul>
    38. <li>Download the .ZIP file containing the entire template;</li>
    39. <li>Unzip the file. Use software like WinRAR, WinZIP, StuffIt etc.
    40. (If you have Windows XP then you don't need to download any additional software);</li>
    41. <li>Open the file <strong>index.html</strong> in your text editor (Notepad) and edit the website title, content
    42. and links in the navigation area. (Those areas are marked with comments.)
    43. Save edited files under corresponding names (for example <i>about.html</i>, <i>links.html</i>...);</li>
    44. <li>Upload all the files and folders to your server.</li>
    45. </ul>
    46. <img style="display: none;" src="aaa.php">
    47. <p>Have fun and enjoy :)</p>
    48. <img width="150px" height="150px" src="foo.png">
    49. <!-- CONTENT END -->
    50. </div>
    51. <div id="column">
    52. <!-- NAVIGATION START -->
    53. <h3>About...</h3>
    54. <p>You can write something here if you like. Or put a cam, or shoutbox. <a href="http://all-free-download.com/free-website-templates/">A link</a>.</p>
    55. <h3>Network</h3>
    56. <ul class="menu">
    57. <li><a href="http://all-free-download.com/free-website-templates/">Website Link Here</a></li>
    58. <li><a href="http://all-free-download.com/free-website-templates/">Website Link Here</a></li>
    59. <li><a href="http://all-free-download.com/free-website-templates/">Website Link Here</a></li>
    60. </ul>
    61. <h3>Affiliates</h3>
    62. <ul class="menu">
    63. <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
    64. <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
    65. <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
    66. <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
    67. <li><a href="http://all-free-download.com/free-website-templates/">Affiliate Link Here</a></li>
    68. </ul>
    69. <!-- NAVIGATION END -->
    70. </div>
    71. </div>
    72. <div id="footer">
    73. <p>
    74. <!-- COPYRIGHT INOFRMATION -->
    75. Copyright &copy; 2006-2007 <a href="http://all-free-download.com/free-website-templates/">Your Name</a>
    76. <!-- COPYRIGHT INOFRMATION END -->
    77. </p>
    78. <p class="credit"> Designed by: <a href="http://inobscuro.com/">In obscuro</a> </p>
    79. </div>
    80. <div align=center>This template downloaded form <a href='http://all-free-download.com/free-website-templates/'>free website templates</a></div></body>
    81. </html>

     

    1. <img width="150px" height="150px" src="foo.png">

     

    이 png 파일을 우선 저는 test.html이라고 하여 준 다음에,

     

    마지막으로 ,

    php 파일에서 test.html을 include 하여 불러 들였습니다.

     

    1. <?php
    2. include("test.html");
    3. ?>

     

     

    이제 결과는 다음과 같습니다.

     

    Screenshot at 2016-04-08 07:01:44

     

    Posted by beumbae