Veröffentlichung 6. Juli 2018 @ 17:27
Letzte Änderung 9. April 2021 @ 18:32
Überblick
- (Unerwünschte) Ghostscript-Fehlermeldungen auf Standardausgabe bei Umwandlung fehlerhafter PDF-Dateien mit ImageMagick-Werkzeug convert
- keine Exception-Auslösung durch PHP-Klasse Imagick => keine Ausnahmebehandlungsmöglichkeit
Voraussetzungen
Software
- Ghostscript 9.18 #gs -version
- ImageMagick 6.8.9 #convert -version
- Ubuntu Server 16.04.04 LTS #lsb_release -a
Ordner und Dateien
- Konfiguration /etc/ImageMagick-6/delegates.xml
[Optional] ImageMagick mit PHP-Unterstützung installieren
apt install imagemagick php-imagick
Fehlerhafte PDF-Datei erzeugen
convert xc:none test.pdf #leere PDF-Datei erstellen sed -i '1s/^/Müll/' test.pdf #Textzeile am Anfang der Datei einfügen
Zuständiges Delegate-Programm ermitteln
convert -verbose test.pdf test.png ... "gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=/tmp/magick-2392UDXCXqvMp7DW%d" "-f/tmp/magick-2392fVIoMgmi7o4U" "-f/tmp/magick-2392MGmFX8AyDNuT" **** Warning: File has some garbage before %PDF- . ...
keine Ausgabe bei convert -list Delegate
, da stealth="True"
Delegates-Datei anpassen
... <!--<delegate decode="ps:alpha" stealth="True" command=""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>--> <delegate decode="ps:alpha" stealth="True" command=""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s" -sstdout=%%stderr 2> /dev/null"/> ...
Quellen
https://stackoverflow.com/questions/3351967/prevent-ghostscript-from-writing-errors-to-standard-output
https://www.ghostscript.com/
https://www.ghostscript.com/doc/current/Use.htm#Interaction_related_parameters
https://www.imagemagick.org/
https://www.imagemagick.org/script/resources.php