Importação automática de imagens através de script

From Scribus Wiki
Jump to navigation Jump to search
Este artigo é parte da seção de Scripts_e_Plugins.
Scripts para iniciantes Scripts de extensão/PyQt Questões sobre Py Plugins Outros
Voltar para a página principal

Versão em inglês.

Básico

A razão de eu ter criado esse scripts, primeiramente, foi a de aprender alguma coisa sobre Python, e poder cirar um arquivador de imagens ou album no Scribus. Geralmente eu uso o script para organizar as imagens digitais que eu tiro nas minhas viagens. Uma das vantagens do Scribus, é que o seu formato de arquivo .sla não inclui nenhum dado de imagem mas apenas suas referências, então este arquivo de catálogo é relativamente pequeno. Em algums coleções, eu irei adicionar anotações, fazer um PDF e as imprimir em um album de verdade.

Inicialmente eu criei um programa em Perl a parte (scribalbum.pl) para fazer isto fora do Scribus. Isto ainda funciona, mesmo tendo sido projetado para os formatos de arquivo da versão 1.2.x. Uma de suas vantagens é a velocidade com que ele gera diversas páginas com informações. Já sua desvantagem, é que ele foi criado para o formato 1.2.x, ou seja, potêncialmente incompatível com as novas versões (e até um tanto quanto perigoso). Ajustar-lo para gerar os documentos na nova versão é mais trabalho do que eu gostaria. Melhor carregar-lo no Scribus 1.3.x e então salvar de lá mesmo.

As implementações Python tem a vantagem de usar o próprio Scribus para criar i documento, então, enquanto o script funcionar, o arquivo resultante estará atualizado. Outro benefício é a facilidade de modificação do script para ser ajustado para outras necessidades.

scribalbum.pl

Eu não irei dizer nada sobre este programa. Se você conhece alguma coisa de Perl, você verá que isto não é "elegante", mas faz o trabalho. Ele opera através da linha de comando.

scribalbum.py and scribalbuma4.py

These are similar Python scripts. Both create a new document and as many pages as needed. scribalbum.py places 4 staggered images on a US Letter page, allowing for annotations in the remaining white space. scribalbuma4.py places 8 images per A4 page with little remaining white space. Both versions will make a text frame in the upper left corner of each page indicating the directory the images came from, and each image has a label showing the image's filename.

Here are some features that both share:

  • When you run the script from within Scribus, you will see two Tk windows, one of which is blank, the other of which asks for the name of the directory and has a number of checkboxes. You can use a relative path, but an absolute one is more precise.
  • You may check one or as many image formats as you like. ALL images of that type will be included -- you cannot pick and choose individual images. As written, they will appear in alphanumeric order in your document, left column filled first. You could go left-right-left right down the page by changing the logic.
  • PDFs will import, but only the first page.
  • Thus far, SVGs will not import with this script. What you get is a blank frame. One of those "to do" things.
  • All images are adjusted to fit the frame size, and the frame size is the same within each script version. Adjusting the frame for individual images is a job best done in Scribus after you have made and loaded the file. These scripts are just meant to do the grunt work, let Scribus do the tweaking.
  • Once you have entered the directory, selected the image formats, then click OK. Expect some time to go by, during which Scribus frames and icons may blink in and out.
  • When the script is done, the formerly blank Tk window now says, "Now click the X in the upper right corner of this window", meaning the X in the corner of the Tk window to delete this window. This ends the script, and Scribus takes over.
  • At this point, Scribus is, in essence, loading this file for display, so you may have some considerable time (minutes) go by, depending on the number and size of the images and the speed of your processor.
  • If at this point Scribus crashes, you most likely have used up all your RAM and swap memory, and at this time there is no protection built into the script. If you're lucky, Scribus may have saved an emergency file starting with "DocumentN...", but if it's too big (the file itself may not be very large, it's the memory requirements of all the images that's the source of the problem), Scribus still won't be able to load it, since it will still bump up against the memory problem.

Additional Notes

I have yet to try this on the brand-new Windows version of Scribus. An initial issue will be making sure you have Python on your Windows machine.

If I get some specific questions, I can add notes (or others can add them) about how to modify scribalbum.py and scribalbuma4.py to fit other needs.