Ich verstehe, dass es mit imageMagicks möglich sein kann:
convert image.mng out.pdf
aber gibt es eine Gimp-Methode, dies zu tun?
Ich habe auch dieses Skript/Plugin gesehen, das Folgendes verwendet convert
:
https://www.dropbox.com/s/jzdkgv2f0jrbw6i/export-layers-to-pdf.py?dl=0
#!/usr/bin/env python
#
# Author: helour
# Copyright: 2013-2015 helour
# Based on the cr33dog's script Export Layers as PNG (http://registry.gimp.org/node/18440)
# License: GPL v3+
#
# Version: 0.7
#
# GIMP plugin to export layers as a multiple pages PDF file
#
#
# Note for Windows users:
#
# You need add the ImageMagic directory (which consists the 'convert.exe' executable file)
# to the GIMP environment PATH variable into the file:
# C:\Program Files\GIMP 2\lib\gimp\2.0\environ\default.env
#
# like in the example here:
# PATH=${gimp_installation_dir}\bin;${gimp_installation_dir}\32\bin;C:\Program Files\ImageMagick-6.9.1-Q16
# PYTHONPATH=${gimp_installation_dir}\32\lib\gimp\2.0\python
import os
import gtk
from subprocess import check_call
from tempfile import mkstemp
from gimpfu import *
def mktmpfile(suffix):
fd, filename = mkstemp(suffix=suffix)
fptr = os.fdopen(fd)
return filename
def get_layers_to_export(layers, only_visible, gimp_version):
result = []
for layer in layers:
if gimp_version >= 2.8 and pdb.gimp_item_is_group(layer):
result += get_layers_to_export(layer.children, only_visible, gimp_version)
else:
if only_visible:
if layer.visible:
result.append(layer)
else:
result.append(layer)
return result
def combine_images_into_pdf(img_files, pdf_file):
try: # Run on shell because of conflict with windows system command 'convert.exe'
check_call(['convert'] + img_files + [pdf_file], shell = True if os.name == 'nt' else False)
except Exception as e:
pdb.gimp_message("Error while executing 'convert' command:\n" +
str(e) +
"\n\nHave you installed the ImageMagic package\nand/or\nset the GIMP environment PATH variable?")
def export_layers(image, only_visible, quality):
if not image.filename:
pdb.gimp_message("Please save your file first!")
return
chooser = gtk.FileChooserDialog(title = None, action = gtk.FILE_CHOOSER_ACTION_SAVE,
buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK))
chooser.set_current_folder(os.path.dirname(image.filename))
chooser.set_current_name(os.path.splitext(image.filename)[0] + '.pdf')
if chooser.run() != gtk.RESPONSE_OK:
return
filename = chooser.get_filename()
chooser.destroy()
version = gimp.version[0:2]
gimp_version = float(version[0]) + float(version[1]) / 10.0
layers_to_export = get_layers_to_export(image.layers, only_visible, gimp_version)
img_files = []
try:
for layer in layers_to_export:
ext = '.jpg' if quality < 100 else '.png'
fullpath = mktmpfile(ext)
img_files.append(fullpath)
pic_filename = os.path.basename(fullpath)
if quality < 100:
pdb.file_jpeg_save(image, layer, fullpath, pic_filename, quality / 100.0, 0, 1, 0, "", 0, 1, 0, 2)
else:
pdb.file_png_save(image, layer, fullpath, pic_filename, 0, 9, 1, 1, 1, 1, 1)
combine_images_into_pdf(img_files, filename)
finally:
for img in img_files:
try:
os.remove(img)
except:
pass
register(
"export-layers-to-pdf", #name
"Export layers to a multiple pages PDF file", #description
"Export all layers to a single multiple pages PDF file", #help
"helour", #author
"helour", #copyright
"2015", #year
"Export layers to PDF", #menu label
"*", # image format
[ #input args. Format (type, name, description, default [, extra])
(PF_IMAGE, "image", "Image", None),
(PF_BOOL, "only_visible", "Only Visible Layers?", True),
(PF_SLIDER, "quality", "Image quality", 100, (10, 100, 1)),
],
[], #results. Format (type, name, description)
export_layers, #callback
menu=("<Image>/File/Export/"),
)
main()
Ich sehe jedoch keinen /Applications/GIMP.app/Contents/Resources/share/gimp/2.0/plug-ins
Ordner, also habe ich einen erstellt und das Python-Skript darin abgelegt und chmod +x
das Skript ausgeführt.
Ich habe auch etwas im Python-Fu-Browser gesehen, habe aber keine Ahnung, wie man es benutzt:
"images" ist undefiniert:
Gimp 2.8.14 Mac OSX
Ich habe auch einige Ratschläge befolgt, um nachzusehen /Library
, aber nichts gefunden:
➜ /Library sudo find . | grep -i gimp
Password:
./Caches/Homebrew/brew-cask--git/Casks/gimp.rb
./Caches/Homebrew/brew-cask--git/Casks/lisanet-gimp.rb
./Caches/Homebrew/Formula/gimp.brewing
Gibt es trotzdem Plugins einfach zu installieren, die mir hier fehlen?
Mit Hilfe von @tmanni im IRC konnte ich den Skriptpfad in den Einstellungen /Applications/GIMP.app/Contents/Resources/lib/gimp/2.0/plug-ins
> Plug-Ins finden:
Das Plugin würde jedoch mit der Meldung beendet, dass convert
es nicht installiert ist.
/usr/local/bin
Ich habe dann versucht, den Plug-Ins-Pfad im Menü hinzuzufügen , aber es stürzt dann mit einem Exit-Code-Status von -5 ab.
Ich habe es dann direkt versucht, ln -s /usr/local/bin/convert /Applications/GIMP.app/Contents/Resources/bin/convert
aber es gab auch keine Würfel.
Nachdem ich den größten Teil einer Woche damit verbracht habe, damit herumzuspielen:
➜ gimp_export_layers_to_pdf git:(master) brew --config
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: b51d0bc7f7b3575227538f84151b3fa4318f2774
Last commit: 42 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: 8-core 64-bit haswell
OS X: 10.10.5-x86_64
Xcode: 7.1.1
CLT: 7.1.0.0.1.1444952191
Clang: 7.0 build 700
X11: N/A
System Ruby: 2.0.0-p481
Perl: /usr/bin/perl
Python: /usr/local/bin/python => /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
Java: 1.6.0_65-b14-468
Ich habe ein Git-Repo für dieses Skript geöffnet, ich war etwas überrascht, wie schwierig die Plugin-Registrierung für Gimp war, aber ich habe es an einen Punkt gebracht, an dem es funktioniert, wenn das PDF mit einer Qualität von weniger als 100 exportiert wird :
Im Grunde genommen verwendete Gimp die Standardbibliotheken, die in Gimp enthalten sind (klingt nach einer guten Idee), bis ich Gimp vom Terminal aus öffne:
➜ ~ /Applications/GIMP.app/Contents/MacOS/GIMP ~/Desktop/Export_These_Layers.xcf
...
dyld: Library not loaded: /usr/local/lib/libfreetype.6.dylib
Referenced from: /usr/local/bin/convert
Reason: Incompatible library version: convert requires version 19.0.0 or later, but libfreetype.6.dylib provides version 18.0.0
convert ist installiert?:
➜ ~ ls -la /usr/local/bin/convert
lrwxr-xr-x 1 jmunsch admin 41 Nov 26 15:47 /usr/local/bin/convert -> ../Cellar/imagemagick/6.9.2-6/bin/convert
welche Bibliotheken konvertiert wird
➜ ~ otool -L /usr/local/bin/convert
/usr/local/bin/convert:
/usr/local/Cellar/imagemagick/6.9.2-6/lib/libMagickCore-6.Q16.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/local/Cellar/imagemagick/6.9.2-6/lib/libMagickWand-6.Q16.2.dylib (compatibility version 3.0.0, current version 3.0.0)
/usr/local/opt/freetype/lib/libfreetype.6.dylib (compatibility version 19.0.0, current version 19.0.0)
/usr/local/opt/xz/lib/liblzma.5.dylib (compatibility version 8.0.0, current version 8.2.0)
/usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/local/opt/libtool/lib/libltdl.7.dylib (compatibility version 11.0.0, current version 11.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
Alles scheint aktuell zu sein?
Also, wie viele Orte hat diese Bibliothek?:
➜ ~ locate libfreetype
/Applications/GIMP.app/Contents/Resources/lib/libfreetype.6.dylib
/Applications/Steam.app/Contents/MacOS/libfreetype.dylib
/Volumes/Gimp 2.8.14/GIMP.app/Contents/Resources/lib/libfreetype.6.dylib
/usr/X11/lib/libfreetype.6.dylib
/usr/local/Cellar/freetype/2.6_1/lib/libfreetype.6.dylib
/usr/local/Cellar/freetype/2.6_1/lib/libfreetype.a
/usr/local/Cellar/freetype/2.6_1/lib/libfreetype.dylib
/usr/local/lib/libfreetype.6.dylib
/usr/local/lib/libfreetype.a
/usr/local/lib/libfreetype.dylib
Ach, ich sehe:
➜ ~ otool -L /Applications/GIMP.app/Contents/Resources/lib/libfreetype.6.dylib
/Applications/GIMP.app/Contents/Resources/lib/libfreetype.6.dylib:
/usr/local/lib/libfreetype.6.dylib (compatibility version 19.0.0, current version 18.0.0)
Also kopiere ich es rüber:
➜ ~ cp /usr/local/opt/freetype/lib/libfreetype.6.dylib /Applications/GIMP.app/Contents/Resources/lib
Und erneut versuchen:
➜ ~ /Applications/GIMP.app/Contents/MacOS/GIMP ~/Desktop/Export_These_Layers.xcf
Setting up environment...
Enabling internal Python...
Launching GIMP...
dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib
Referenced from: /Applications/GIMP.app/Contents/Resources/lib/libfreetype.6.dylib
Reason: Incompatible library version: libfreetype.6.dylib requires version 34.0.0 or later, but libpng16.16.dylib provides version 29.0.0
[1] 69814 trace trap /Applications/GIMP.app/Contents/MacOS/GIMP ~/Desktop/Export_These_Layers.xcf
also versuche ich libpng und kopiere es nach gimp:
➜ ~ locate libpng16
.
.
.
➜ ~ cp /usr/local/Cellar/libpng/1.6.18/lib/libpng16.16.dylib /Applications/GIMP.app/Contents/Resources/lib
Starten Sie Gimp vom Terminal aus neu und versuchen Sie es erneut mit dem Plugin:
dyld: Library not loaded: /usr/local/opt/xz/lib/liblzma.5.dylib
Referenced from: /usr/local/bin/convert
Reason: Incompatible library version: convert requires version 8.0.0 or later, but liblzma.5.dylib provides version 6.0.0
Okay, wo zieht es diese Bibliothek her:
➜ ~ otool -L /usr/local/lib/liblzma.5.dylib
/usr/local/lib/liblzma.5.dylib:
/usr/local/opt/xz/lib/liblzma.5.dylib (compatibility version 8.0.0, current version 8.2.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
➜ ~ otool -L /Applications/GIMP.app/Contents/Resources/lib/liblzma.5.dylib
liblzma.5.dylib:
/Users/gimpdev/gimp/10.6/inst/lib/liblzma.5.dylib (compatibility version 6.0.0, current version 6.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
Und so kopiere ich diese Datei auch herüber:
cp /usr/local/lib/liblzma.5.dylib /Applications/GIMP.app/Contents/Resources/lib
Noch ein weiteres Problem nach dem Linken der neuen Bibliotheken:
convert: unable to load module `/usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1300.
convert: no decode delegate for this image format `PNG' @ error/constitute.c/ReadImage/501.
convert: unable to load module `/usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1300.
convert: no decode delegate for this image format `PNG' @ error/constitute.c/ReadImage/501.
convert: unable to load module `/usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1300.
convert: no decode delegate for this image format `PNG' @ error/constitute.c/ReadImage/501.
convert: unable to load module `/usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1300.
convert: no decode delegate for this image format `PNG' @ error/constitute.c/ReadImage/501.
Ich versuche es erneut, aber baue diesmal aus der Quelle:
brew install imagemagick --build-from-source
Wiederholen und dasselbe Problem mit dem PNG-Modul, also führe ich aus brew doctor
:
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc
Also versuche ich die Installation erneut libpng
:
➜ ~ brew uninstall imagemagick; brew install imagemagick;brew install libpng; brew link libpng
Warning: libpng-1.6.19 already installed
Warning: Already linked: /usr/local/Cellar/libpng/1.6.19
To relink: brew unlink libpng && brew link libpng
➜ ~ brew unlink libpng && brew link libpng
Unlinking /usr/local/Cellar/libpng/1.6.19... 18 symlinks removed
Linking /usr/local/Cellar/libpng/1.6.19... 18 symlinks created
Und xz
:
brew uninstall xz
brew uninstall imagemagick; brew install imagemagick --build-from-source
Und schließlich zu etwas härterem Wiederaufbau:
brew uninstall --force imagemagick; brew install -v imagemagick --build-from-source
Ich habe mir die Dokumente für das ReadImage von convert angesehen:
open /usr/local/Cellar/imagemagick//6.9.1-10/share/doc/ImageMagick-6/www/api/constitute.html
Ich habe den Quellcode für ReadImage
.
Ich halte an und schaue zurück auf das Python-Skript. Ich zwinge das Skript, jpeg anstelle von png zu verwenden .
Hier ist die Arbeitsgeschichte, die ich versucht habe:
cd /Applications/GIMP.app/Contents/Resources/lib/gimp/2.0/plug-ins
chown jmunsch:admin export-layers-to-pdf.py
cd /var/folders/w1
/Applications/GIMP.app/Contents/MacOS/GIMP ~/Desktop/Export_These_Layers.xcf
otool -L /usr/local/bin/convert
brew update && brew upgrade
brew reinstall imagemagick
ls /usr/local/opt/freetype/lib/libfreetype.6.dylib
stat /usr/local/opt/freetype/lib/libfreetype.6.dylib
otool -L /usr/local/bin/convert
cp /usr/local/opt/freetype/lib/libfreetype.6.dylib /Applications/GIMP.app/Contents/Resources/lib
locate libpng16
cp /usr/local/Cellar/libpng/1.6.18/lib/libpng16.16.dylib /Applications/GIMP.app/Contents/Resources/lib
locate liblzma.5.dylib
otool -L /usr/local/lib/liblzma.5.dylib
otool -L /Applications/GIMP.app/Contents/Resources/lib/liblzma.5.dylib
cp /usr/local/lib/liblzma.5.dylib /Applications/GIMP.app/Contents/Resources/lib
which convert
ls -la /usr/local/bin/convert
ls /usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/
ls /usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/coders
/usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/coders/png.la
stat /usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/coders/png.la
convert '/var/folders/w1/gg1rwbxd17x07kv9swxwv84h0000gn/T/tmpsPHsvG.png' '/var/folders/w1/gg1rwbxd17x07kv9swxwv84h0000gn/T/tmpXGKL0S.png' '/var/folders/w1/gg1rwbxd17x07kv9swxwv84h0000gn/T/tmp196lyv.png' '/var/folders/w1/gg1rwbxd17x07kv9swxwv84h0000gn/T/tmprNZdlG.png' '/Users/jmunsch/Desktop/hggfd.pdf'
brew doctor
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc
ls /usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16
ls /usr/local/Cellar/imagemagick/6.9.2-6/lib/ImageMagick//modules-Q16/coders
cd ~/Desktop
python test.py
open /usr/local/Cellar/imagemagick//6.9.1-10/share/doc/ImageMagick-6/www/api/constitute.html
brew uninstall imagemagick; brew install imagemagick;brew install libpng; brew link libpng
brew --config
brew uninstall xz
brew uninstall imagemagick; brew install imagemagick --build-from-source
brew uninstall --force imagemagick; brew install -v imagemagick --build-from-source
cp /usr/local/lib/liblzma.5.dylib /Applications/GIMP.app/Contents/Resources/lib
brew uninstall --force imagemagick
brew update && brew upgrade && brew uninstall --force imagemagick && brew install -v imagemagick --build-from-source
which convert
ls -la /usr/local/bin/convert
Ich verbrachte meinen Nachmittag damit, mit dem gleichen Problem zu kämpfen.
Sie können das Problem vollständig lindern, indem Sie die combine_images_into_pdf
Funktion des Plugins ändern:
def combine_images_into_pdf(img_files, pdf_file):
try: # Run on shell because of conflict with windows system command 'convert.exe'
my_env = os.environ.copy()
my_env["DYLD_LIBRARY_PATH"] = "/usr/local/lib:"
p = subprocess.Popen(['convert'] + img_files + [pdf_file], env=my_env)
p.wait()
except Exception as e:
pdb.gimp_message("Error while executing 'convert' command:\n" +
str(e) + "\n\nHave you installed the ImageMagic package\nand/or\nset the GIMP environment PATH variable?")
Sie müssen auch die Importe ändern - entweder import subprocess
oder from subprocess import Popen
anstelle von from subprocess import check_call
(im obigen Codeblock habe ich import subprocess
) verwendet.
Siehe hier für Informationen über Popen: https://docs.python.org/2/library/subprocess.html#subprocess.Popen https://stackoverflow.com/questions/2231227/python-subprocess-popen-with-a- modifizierte Umgebung
Die Umgebungsvariable DYLD_LIBRARY_PATH wird im GIMP-Startskript unter /Applications/GIMP.app/Contents/MacOS/GIMP
. Die Standardeinstellung DYLD_LIBRARY_PATH
wird benötigt, damit GIMP sich selbst startet und PNG-Bilder komprimiert (wie die Fehler mit libfreetype
, libpng
, und liblzma
zeigen), aber Sie können zulassen convert
, dass die richtigen Bibliotheken verwendet werden, indem Sie diese Umgebungsvariable auf die Stelle setzen, an der sich die richtigen Bibliotheken befinden, wenn Sie aufrufen Popen
. Da Sie wie ich Homebrew verwenden, gehe ich davon aus, dass die Verwendung /usr/local/lib/
für dieses Verzeichnis funktioniert.
Auf diese Weise müssen Sie nichts löschen, damit das Plug-in vollständig funktioniert. Installieren Sie einfach alle Abhängigkeiten und bearbeiten Sie das Plug-in-Skript, und Sie können loslegen. Der obige Code ändert die Umgebung von GIMP selbst nicht, daher verursacht er keine Fehler, wenn Sie zurückgehen und Ihre Bilder nach dem Exportieren bearbeiten.
Ich habe dies sehr einfach behoben, indem ich den absoluten Pfad zur ausführbaren Konvertierungsdatei im Skript hinzugefügt habe. Auf meiner Maschine ist es:
/opt/local/bin/convert
Diese Funktion wird zu:
def combine_images_into_pdf(img_files, pdf_file):
try: # Run on shell because of conflict with windows system command 'convert.exe'
check_call(['/opt/local/bin/convert'] + img_files + [pdf_file], shell = True if os.name == 'nt' else False)
except Exception as e:
pdb.gimp_message("Error while executing 'convert' command:\n" +
str(e) +
"\n\nHave you installed the ImageMagic package\nand/or\nset the GIMP environment PATH variable?")
Es scheint, dass Knigodej ein Tool ist, das genau das tut, was Sie wollen:
Knigodej gem ist ein Tool zum Erstellen von PDF- und DJVU-Büchern aus der XCF-Quelle (GIMP-Bild).
Joonas
AAGD
jmünsch
brew
as in:which convert
Outputs installiert/usr/local/bin/convert
AAGD
jmünsch
convert *.jpg out.pdf
hat, aber die Frage steht immer noch. Ich habe mit dem Skript herumgespielt und versucht zu debuggen, warum es auf dem Mac nicht richtig funktioniert.AAGD
AAGD
jmünsch