{"id":1340,"date":"2025-07-31T06:29:01","date_gmt":"2025-07-30T22:29:01","guid":{"rendered":"https:\/\/www.hgfwq.com\/blog\/?p=1340"},"modified":"2025-07-31T06:29:01","modified_gmt":"2025-07-30T22:29:01","slug":"fig-to-image%e8%83%bd%e5%90%a6%e5%b8%ae%e5%8a%a9%e4%bd%a0%e8%bd%bb%e6%9d%be%e5%b0%86latex%e5%9b%be%e5%bd%a2%e8%bd%ac%e6%8d%a2%e4%b8%ba%e9%ab%98%e8%b4%a8%e9%87%8f%e5%9b%be%e5%83%8f%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.hgfwq.com\/blog\/1340.html","title":{"rendered":"Fig to Image\u80fd\u5426\u5e2e\u52a9\u4f60\u8f7b\u677e\u5c06LaTeX\u56fe\u5f62\u8f6c\u6362\u4e3a\u9ad8\u8d28\u91cf\u56fe\u50cf\uff1f"},"content":{"rendered":"<p><p><strong>Fig to Image<\/strong> \u662f\u4e00\u79cd\u6280\u672f\uff0c\u5b83\u53ef\u4ee5\u5c06LaTeX\u4e2d\u7684\u56fe\u5f62\uff08\u5982eps\u3001pdf\u7b49\u683c\u5f0f\uff09\u8f6c\u6362\u4e3a\u56fe\u50cf\u683c\u5f0f\uff0c\u5982PNG\u6216JPEG\uff0c\u4ee5\u4fbf\u5728\u7f51\u9875\u3001\u62a5\u544a\u6216\u6f14\u793a\u6587\u7a3f\u4e2d\u4f7f\u7528\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u548cImageMagick\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u8f6c\u6362\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.hgfwq.com\/blog\/wp-content\/uploads\/2025\/07\/162i4W7.jpg\" alt=\"Fig to Image\u80fd\u5426\u5e2e\u52a9\u4f60\u8f7b\u677e\u5c06LaTeX\u56fe\u5f62\u8f6c\u6362\u4e3a\u9ad8\u8d28\u91cf\u56fe\u50cf\uff1f\" title=\"Fig to Image\u80fd\u5426\u5e2e\u52a9\u4f60\u8f7b\u677e\u5c06LaTeX\u56fe\u5f62\u8f6c\u6362\u4e3a\u9ad8\u8d28\u91cf\u56fe\u50cf\uff1f\"><\/p>\n<\/p>\n<p><h2>\u64cd\u4f5c\u524d\u7684\u51c6\u5907<\/h2>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u60a8\u7684\u7cfb\u7edf\u4e2d\u5df2\u5b89\u88c5\u4ee5\u4e0b\u8f6f\u4ef6\u548c\u5e93\uff1a<\/p>\n<\/p>\n<ul>\n<li>Python 3.x<\/li>\n<li>ImageMagick<\/li>\n<li>Python\u7684Pillow\u5e93<\/li>\n<\/ul>\n<p><p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Pillow\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install Pillow<\/code><\/pre>\n<\/p>\n<p><h2>\u8be6\u7ec6\u64cd\u4f5c\u6b65\u9aa4<\/h2>\n<\/p>\n<p><h3>\u6b65\u9aa41\uff1a\u5b89\u88c5ImageMagick<\/h3>\n<\/p>\n<p><p>\u6839\u636e\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5ImageMagick\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u5728Ubuntu\u4e0a\uff1a<\/li>\n<li>\n<p><pre><code>sudo apt-get install imagemagick<\/code><\/pre>\n<\/li>\n<li>\u5728CentOS\u4e0a\uff1a<\/li>\n<li>\n<p><pre><code>yum install imagemagick<\/code><\/pre>\n<\/li>\n<li>\u5728macOS\u4e0a\uff1a<\/li>\n<li>\n<p><pre><code>brew install imagemagick<\/code><\/pre>\n<\/li>\n<\/ul>\n<p><h3>\u6b65\u9aa42\uff1a\u7f16\u5199Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a `fig_to_image.py` \u7684Python\u811a\u672c\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code>from PIL import Image<\/p>\r\n<p>import subprocess<\/p>\r\n\r\n<p>def fig_to_image(fig_path, image_path, format='png'):<\/p>\r\n<p>     \u4f7f\u7528ImageMagick\u5c06LaTeX\u56fe\u5f62\u8f6c\u6362\u4e3a\u56fe\u50cf<\/p>\r\n<p>    command = ['convert', '-density', '300', '-quality', '100', fig_path, image_path]<\/p>\r\n<p>    subprocess.run(command, check=True)<\/p>\r\n\r\n<p> \u793a\u4f8b\u7528\u6cd5<\/p>\r\n<p>fig_to_image('example.eps', 'output.png')<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa43\uff1a\u8fd0\u884c\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u5207\u6362\u5230\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>python fig_to_image.py<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u628a\u540d\u4e3a `example.eps` \u7684LaTeX\u56fe\u5f62\u8f6c\u6362\u4e3a\u540d\u4e3a `output.png` \u7684\u56fe\u50cf\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h2>\u5173\u952e\u547d\u4ee4\u548c\u4ee3\u7801\u89e3\u91ca<\/h2>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u811a\u672c\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4ee5\u4e0b\u5173\u952e\u547d\u4ee4\u548c\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>from PIL import Image<\/strong>\uff1a\u5bfc\u5165Pillow\u5e93\u4e2d\u7684Image\u6a21\u5757\uff0c\u7528\u4e8e\u5904\u7406\u56fe\u50cf\u3002<\/li>\n<li><strong>import subprocess<\/strong>\uff1a\u5bfc\u5165subprocess\u6a21\u5757\uff0c\u7528\u4e8e\u8fd0\u884c\u5916\u90e8\u547d\u4ee4\u3002<\/li>\n<li><strong>fig_to_image(fig_path, image_path, format=&#8217;png&#8217;)<\/strong>\uff1a\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u5c06LaTeX\u56fe\u5f62\u8f6c\u6362\u4e3a\u56fe\u50cf\u3002<\/li>\n<li><strong>command = [&#8216;convert&#8217;, &#8216;-density&#8217;, &#8216;300&#8217;, &#8216;-quality&#8217;, &#8216;100&#8217;, fig_path, image_path]<\/strong>\uff1a\u6784\u5efa\u4e00\u4e2a\u547d\u4ee4\u5217\u8868\uff0c\u7528\u4e8e\u8c03\u7528ImageMagick\u7684 `convert` \u547d\u4ee4\u3002<\/li>\n<li><strong>subprocess.run(command, check=True)<\/strong>\uff1a\u8fd0\u884c\u5916\u90e8\u547d\u4ee4\uff0c\u5e76\u786e\u4fdd\u547d\u4ee4\u6267\u884c\u6210\u529f\u3002<\/li>\n<\/ul>\n<p><h2>\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u548c\u6ce8\u610f\u4e8b\u9879<\/h2>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5728\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u9047\u5230\u7684\u95ee\u9898\u548c\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fddImageMagick\u5df2\u6b63\u786e\u5b89\u88c5\u5e76\u914d\u7f6e\u3002<\/li>\n<li>\u5982\u679cLaTeX\u56fe\u5f62\u6587\u4ef6\u4e0d\u662feps\u6216pdf\u683c\u5f0f\uff0c\u53ef\u80fd\u9700\u8981\u5148\u4f7f\u7528LaTeX\u7f16\u8bd1\u5668\u5c06\u5176\u8f6c\u6362\u4e3a\u8fd9\u4e9b\u683c\u5f0f\u3002<\/li>\n<li>\u8c03\u6574\u547d\u4ee4\u4e2d\u7684\u53c2\u6570\uff08\u5982\u5bc6\u5ea6\u548c\u8d28\u91cf\uff09\u4ee5\u4f18\u5316\u8f93\u51fa\u56fe\u50cf\u7684\u8d28\u91cf\u3002<\/li>\n<li>\u5982\u679c\u9047\u5230\u6743\u9650\u95ee\u9898\uff0c\u53ef\u80fd\u9700\u8981\u4ee5root\u7528\u6237\u8eab\u4efd\u8fd0\u884c\u811a\u672c\u3002<\/li>\n<\/ul>\n<p>&#8220;`<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fig to Image \u662f\u4e00\u79cd\u6280\u672f\uff0c\u5b83\u53ef\u4ee5\u5c06LaTeX\u4e2d\u7684\u56fe\u5f62\uff08\u5982eps\u3001pdf\u7b49\u683c\u5f0f\uff09\u8f6c\u6362\u4e3a\u56fe\u50cf\u683c\u5f0f\uff0c\u5982PNG\u6216JPEG\uff0c\u4ee5\u4fbf\u5728\u7f51\u9875\u3001\u62a5\u544a\u6216\u6f14\u793a\u6587\u7a3f\u4e2d\u4f7f\u7528\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Python\u548cImageMagick\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u8f6c\u6362\u3002 \u64cd&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1341,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[519,520,134],"topic":[],"class_list":["post-1340","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-haiwai","tag-imagemagick","tag-pillow","tag-python"],"_links":{"self":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/1340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/comments?post=1340"}],"version-history":[{"count":1,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/1340\/revisions"}],"predecessor-version":[{"id":1343,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/posts\/1340\/revisions\/1343"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/media\/1341"}],"wp:attachment":[{"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/media?parent=1340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/categories?post=1340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/tags?post=1340"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hgfwq.com\/blog\/wp-json\/wp\/v2\/topic?post=1340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}