打印 imagemagick 將輸出轉換為瀏覽器 (print imagemagick convert output to browser)


問題描述

打印 imagemagick 將輸出轉換為瀏覽器 (print imagemagick convert output to browser)

我有以下代碼:

import subprocess
convertargs = ['convert', 'image1.tif', 'img2.tif', 'pdf:‑']
print "Content‑type: application/pdf\r\n\r\n"

pdf = subprocess.Popen(convertargs, stdout=subprocess.PIPE)
pdf, error = pdf.communicate()

print pdf

它應該採用convertargs,使用imagemagick的convert將圖像轉換為pdf。

我知道這是可行的,因為當我運行在 shell 處跟隨:

./pdf.py > test.pdf

它為我創建了一個帶有正確圖像的整潔的小 PDF。但是,當我訪問 www.myhost.com/pdf.py 時,它不起作用。我不知道為什麼。這是我的 apache 錯誤日誌的內容:

Traceback (most recent call last):: /Library/WebServer/Documents/pdf.py
   File "/Library/WebServer/Documents/pdf.py", line 59, in <module>: /Library/WebServer/Documents/pdf.py
     pdf = subprocess.Popen(convertargs, stdout=subprocess.PIPE): /Library/WebServer/Documents/pdf.py
   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__: /Library/WebServer/Documents/pdf.py
     errread, errwrite): /Library/WebServer/Documents/pdf.py
   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child: /Library/WebServer/Documents/pdf.py
     raise child_exception: /Library/WebServer/Documents/pdf.py
OSError: [Errno 2] No such file or directory: /Library/WebServer/Documents/pdf.py

參考解法

方法 1:

subprocess.Popen can't find convert, probably because the webserver uses a different $PATH. Try feeding it the full path to convert instead of just convert.

(by Tom JJules G.M.)

參考文件

  1. print imagemagick convert output to browser (CC BY‑SA 2.5/3.0/4.0)

#imagemagick #Python #imagemagick-convert






相關問題

PHP ImageMagick setColorspace 不起作用 (PHP ImageMagick setColorspace not working)

從 Magick++ 圖像從內存 (libharu) 加載圖像 (Load Images from memory (libharu) from Magick++ images)

ImageMagick PDF to JPGs 有時會導致黑色背景 (ImageMagick PDF to JPGs sometimes results in black background)

使用 ImageMagick 改進從平面圖像到 3d 模型的轉換鏈 (Improve this conversion chain from flat images to 3d mockup with ImageMagick)

WampServer 和 Imagemagick,無法識別 imagick php 模塊 (WampServer and Imagemagick, imagick php module not recogized)

PHP Imagick - 顯示多圖像 TIFF 的第一片 (PHP Imagick - display first slice of mutli image TIFF)

打印 imagemagick 將輸出轉換為瀏覽器 (print imagemagick convert output to browser)

創建 ImageMagick Linux 腳本 (Create ImageMagick Linux script)

從照片生成漂亮的直方圖? (generating nice looking histogram from photo?)

iPhone中的imagemagick單色轉換 (imagemagick monochrome convert in iPhone)

為什麼從 PHP 腳本調用 (ImageMagick) convert.exe 會導致頁面無響應? (Why is calling (ImageMagick) convert.exe from PHP script resulting in an unresponsive page?)

如何使用 Python/ImageMagick/Wand 保存多層 PSD (How to save multi-layer PSD with Python/ImageMagick/Wand)







留言討論