Entiendo que puede ser posible usando imageMagicks:
convert image.mng out.pdf
sin embargo, ¿hay una manera gimp de hacer esto?
También vi este script/complemento que usa 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()
Sin embargo, no veo una /Applications/GIMP.app/Contents/Resources/share/gimp/2.0/plug-ins
carpeta, así que creé una y puse el script de python dentro de ella y ejecuté chmod +x
el script.
También vi algo en el navegador python-fu, pero no tengo idea de cómo usarlo:
"imágenes" no está definido:
Gimp 2.8.14 Mac OS X
También seguí algunos consejos para buscar /Library
pero no encontré nada:
➜ /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
¿Hay alguna forma de instalar fácilmente los complementos que me faltan aquí?
Con la ayuda de @tmanni en irc, pude encontrar la ruta del script /Applications/GIMP.app/Contents/Resources/lib/gimp/2.0/plug-ins
dentro de preferencias> complementos:
Sin embargo, el complemento saldría diciendo convert
que no está instalado.
Luego traté de agregar /usr/local/bin
a la ruta de complementos en el menú, pero luego falla con un estado de código de salida de -5.
Luego traté de hacerlo directamente, ln -s /usr/local/bin/convert /Applications/GIMP.app/Contents/Resources/bin/convert
pero tampoco allí.
Después de pasar la mayor parte de una semana jugando con esto:
➜ 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
Abrí un repositorio de git para este script, me sorprendió un poco lo difícil que era el registro de complementos para gimp, sin embargo, llegué a un punto en el que funcionará si el pdf se exporta con una calidad inferior a 100 :
Básicamente, lo que estaba sucediendo era que gimp estaba usando las bibliotecas predeterminadas que se incluyen con gimp (suena como una buena idea) hasta que abrí gimp desde la terminal:
➜ ~ /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 está instalado?:
➜ ~ 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
qué bibliotecas se convierten usando
➜ ~ 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)
¿Todo parece estar actualizado?
Entonces, ¿cuántos lugares es esa biblioteca?:
➜ ~ 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
Ah, claro:
➜ ~ 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)
Así que lo copio:
➜ ~ cp /usr/local/opt/freetype/lib/libfreetype.6.dylib /Applications/GIMP.app/Contents/Resources/lib
Y reintentar:
➜ ~ /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
así que pruebo libpng y lo copio en gimp:
➜ ~ locate libpng16
.
.
.
➜ ~ cp /usr/local/Cellar/libpng/1.6.18/lib/libpng16.16.dylib /Applications/GIMP.app/Contents/Resources/lib
Reinicie el gimp desde la terminal y vuelva a intentarlo usando el complemento:
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
bien, ¿de dónde está sacando esta biblioteca?
➜ ~ 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)
Y entonces copio ese archivo también:
cp /usr/local/lib/liblzma.5.dylib /Applications/GIMP.app/Contents/Resources/lib
Otro problema más después de vincular las nuevas bibliotecas:
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.
Vuelvo a intentarlo pero construyo desde la fuente esta vez:
brew install imagemagick --build-from-source
Vuelva a intentarlo y el mismo problema con el módulo PNG, así que ejecuto brew doctor
:
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc
Así que vuelvo a intentar instalar 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
y xz
:
brew uninstall xz
brew uninstall imagemagick; brew install imagemagick --build-from-source
Y finalmente ir a por una reconstrucción más difícil:
brew uninstall --force imagemagick; brew install -v imagemagick --build-from-source
Miré los documentos para ReadImage de convert:
open /usr/local/Cellar/imagemagick//6.9.1-10/share/doc/ImageMagick-6/www/api/constitute.html
Leí el código fuente de ReadImage
.
Me detengo y vuelvo a mirar el script de python. Obligo al script a usar jpeg en lugar de png .
Aquí está el historial de trabajo que intenté:
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
Pasé mi tarde lidiando con el mismo problema.
Puede aliviar completamente el problema cambiando la combine_images_into_pdf
función del complemento:
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?")
También deberá cambiar las importaciones, ya sea import subprocess
o from subprocess import Popen
en lugar de from subprocess import check_call
(en el bloque de código anterior que usé import subprocess
).
Consulte aquí para obtener información sobre Popen: https://docs.python.org/2/library/subprocess.html#subprocess.Popen https://stackoverflow.com/questions/2231227/python-subprocess-popen-with-a- ambiente modificado
La variable de entorno DYLD_LIBRARY_PATH se establece en el script de inicio de GIMP ubicado en /Applications/GIMP.app/Contents/MacOS/GIMP
. El valor predeterminado DYLD_LIBRARY_PATH
es necesario para que GIMP se inicie y comprima imágenes PNG (como se muestra en los errores con libfreetype
, libpng
y liblzma
), pero puede permitir convert
el uso de las bibliotecas adecuadas configurando esta variable de entorno dondequiera que estén las bibliotecas adecuadas cuando llame a Popen
. Como está usando homebrew como yo, supongo que usar /usr/local/lib/
para ese directorio funcionará.
De esta manera, no necesita eliminar nada para que el complemento funcione completamente; solo instale todas las dependencias y edite el script del complemento, y estará listo para comenzar. El código anterior no altera el entorno de GIMP en sí mismo, por lo que no causará ningún error si regresa y edita sus imágenes después de exportarlas.
Solucioné esto muy fácilmente agregando la ruta absoluta al ejecutable convertido dentro del script. En mi maquina es:
/opt/local/bin/convert
Esta función se convierte en:
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?")
Parece que Knigodej es una herramienta que hace exactamente lo que quieres:
Knigodej gem es una herramienta para hacer un PDF y libros DJVU desde la fuente XCF (imagen GIMP).
Joonas
AAGD
jmunsch
brew
de como en:which convert
salidas/usr/local/bin/convert
AAGD
jmunsch
convert *.jpg out.pdf
, pero la pregunta sigue en pie. He estado jugando con el script y he estado tratando de depurar por qué no funciona correctamente en Mac.AAGD
AAGD
jmunsch