Il montaggio dei dorsi

Preparazione dei file per la stampa dei dorsi
I dorsi ritagliati

Il programma MontaggioDorsi, accorpa sei dorsi su una superficie 20x27cm che faccio stampare su un cartoncino patinato solo dal lato dell'immagine.

Recentemente è stato reso disponibile un nuovo cartoncino 15x20 sul quale possono essere accorpati tre dorsi; può essere selezionato con il parametro --paper=Medium.

Come ultima opzione di formato è stato aggiunto anche l'A4, richiamato con il parametro --paper=A4, sul quale vengono stampati 8 dorsi.

Attraverso gli script utente è possibile utilizzare qualsiasi altro formato in uscita: in tal caso l'opzione --paper= definisce solo il layout delle immagini.

Il programma chiamato con il parametro -h o --help mostra la sintassi di utilizzo, come riportato di seguito:

Casasoft Contemporary Carte de Visite MontaggioDorsi
Copyright (c) 2020-2023 Roberto Ceccarelli - Casasoft

Usage: MontaggioDorsi [options]* inputfile+

Options:
      --paper=VALUE          Output paper size:
                               Large (default) 20x27cm
                               Medium 15x20cm
                               A4 210x297mm
      --gravity=VALUE        canvas gravity, valid values are:
                               Northwest
                               North
                               Northeast
                               West
                               Center
                               East
                               Southwest
                               South
                               Southeast
      --fillcolor=VALUE      set the color used to fill the images
                               (default #FFFFFF)
      --bordercolor=VALUE    set the color used to border the images
                               (default #000000)
      --dpi=VALUE            set output resolution (default 300)
      --json=VALUE           parameters in json format,
                               use --helpjson for sample template
                               Text can be stored in a file instead of a string
                               The file must be referenced as '@filename'
      --script=VALUE         c# script for custom processing,
                               use --helpscript for sample template
                               Text can be stored in a file instead of a string
                               The file must be referenced as '@filename'
  -o, --output=VALUE         set output dir/filename
      --extension=VALUE      file extension for output file (default 'jpg')
      --tag=VALUE            extra info for user scripts
                               Text can be stored in a file instead of a string
                               The file must be referenced as '@filename'
      --nobanner             suppress the banner
  -h, --help                 show this message and exit
      --helpjson             show json parameters template
      --helpscript           show script template
      --man                  show the man page source and exit
      --colors               list available colors by name
      --license              show program license (AGPL 3.0)

Colors can be written in any of these formats:
  #rgb
  #rrggbb
  #rrggbbaa
  #rrrrggggbbbb
  #rrrrggggbbbbaaaa
  colorname    (use MontaggioDorsi --colors  to see all available colors)

Environment variables
The program can read values from these variables:
  CDV_OUTPATH                     Base path for output files
  CDV_DPI                         Resolution for output files
  CDV_FILL                        Color used to fill images
  CDV_BORDER                      Border color


Built-in images and renders
Instead of a filename you can use the following built-in templates:
  xc:color                        Fill the image with the specified color
  gradient:color1-color2          Fill the image with linear gradient
                                    from color1 to color2,
                                    if colors are omitted is white to black
  radial-gradient:color1-color2   Radial gradient as above
  plasma:color1-color2            Plasma gradient from color1 to color2,
                                    if colors are omitted is black to black
  plasma:fractal                  Creates a random plasma
  label:text                      Render the plain text with no word-wrap
  caption:text                    Render the plain text with auto word-wrap
  pango:text                      Render the text with pango markup

The parameters can be stored in a file instead of a string.
The file must be referenced as '@filename'

Per chi la preferisse è anche disponibile la man page (Nuova pagina) Unix

La man page, in formato MarkDown, può essere ottenuta chiamando il programma con l'opzione --man

I parametri possono essere passati in un file in formato json le cui struttura può essere ottenuta con il comando montaggiodorsi --helpjson il cui output è riportato di seguito:

Casasoft Contemporary Carte de Visite MontaggioDorsi
Copyright (c) 2020-2023 Roberto Ceccarelli - Casasoft

Json parameters template for: MontaggioDorsi

{
  "Paper": null,
  "CanvasGravity": 0,
  "FillColor": "#FFFFFF",
  "BorderColor": "#000000",
  "Dpi": 300,
  "OutputName": "",
  "Extension": "jpg",
  "Script": null,
  "Tag": null,
  "FilesList": []
}

Possono essere passate una o più immagini (anche con l'utilizzo delle wildcards), se sono meno di sei verranno duplicate un numero di volte sufficienti a riempire il foglio.

Le immagini fornite verranno scalate alla dimensione di un dorso da carte de visite (65x100mm) e possono essere sia orizzontali che verticali: la funzione RotateResizeAndFill, già descritta in precedenza, provvede alla rotazione, se necessaria.

L'opzione --dpi= (non esiste forma breve) specifica la risoluzione, in dpi, del file di uscita.
Se non indicata viene impostata a 300dpi.

L'opzione -o, o la versione lunga --output=, permette di specificare il pathname (senza estensione) del file generato: se non specificata il file si chiamerà dorsi.jpg e si troverà nella stessa directory del programma.

Questa immagine mostra un esempio del risultato ottenuto.

I dorsi pronti per la stampa

A partire dalla versione 22.03.13 è stata aggiunta la possibilità di richiamare uno script personalizzato, scritto in C#, che permette elaborazioni specializzate.

Con il comando MontaggioDorsi --helpscript si può ottenere un template, riportato di seguito, per scrivere il proprio script.

Casasoft Contemporary Carte de Visite MontaggioDorsi
Copyright (c) 2020-2023 Roberto Ceccarelli - Casasoft

-----
// Script template for MontaggioDorsi

/// <summary>
/// Custom class initialization
/// </summary>
public void Init() { }

/// <summary>
/// Image for final output
/// </summary>
/// <returns></returns>
public MagickImage OutputImage() => null;

/// <summary>
/// Preprocesses the loaded image
/// </summary>
/// <param name="image">The loaded image</param>
/// <returns>The Processed image</returns>
public MagickImage ProcessOnLoad(MagickImage image) => image;
-----

Lo script viene compilato internamente dal programma, non necessita quindi di alcun programma aggiuntivo per crearlo (basta il semplice notepad).

Riporto un esempio che ignora l'immagine e crea una numerazione in successione; il numero iniziale viene passato attraverso il parametro --tag che può essere utilizzato liberamente dagli script.

// copyright (c) 2020-2023 Roberto Ceccarelli - Casasoft
// http://strawberryfield.altervista.org
//
// This file is part of Casasoft Contemporary Carte de Visite Tools
// https://github.com/strawberryfield/Contemporary_CDV
//
// Casasoft CCDV Tools is free software:
// you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Casasoft CCDV Tools is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU AGPL v.3
// along with Casasoft CCDV Tools.  
// If not, see <http://www.gnu.org/licenses/>.

int counter = 0;

public void Init()
{
    counter = Convert.ToInt16(engine.Tag);
}

public MagickImage ProcessOnLoad(MagickImage image)
{
    // Get the image path
    string filedir = Path.GetDirectoryName(image.FileName);

    // Get the text to render
    MagickReadSettings settings = new();
    settings.BackgroundColor = MagickColors.Transparent;
    string pangoback = File.ReadAllText(Path.Combine(filedir, "author.txt"));
    MagickImage text = new($"pango:{pangoback}", settings);

    // Render the big number
    string pangonumber = $"pango:<span size='800000' face='arial' color='lightgray'><b>{counter}</b></span>";
    MagickImage number = new(pangonumber);

    // Compose the images
    image = engine.img.CDV_Full_o();
    image.Composite(number, Gravity.East,  CompositeOperator.Over);
    image.Composite(text, Gravity.Southwest, engine.fmt.ToPixels(5), engine.fmt.ToPixels(5), CompositeOperator.Over);

    counter++;
    return image;
}
 

Questo invece è il batch che richiama il programma passando lo script

rem test for montaggiodorsi scripting

set projectdir=C:\projects\Contemporary_CDV\
set bin=%projectdir%bin\build\net6.0\
set samples=%projectdir%Test\

%bin%MontaggioDorsi ^
 --script=@%samples%Numbers.cs ^
 --tag=1 ^
 --output=%samples%Numbers ^
 %samples%dorso_o.jpg
 
Inizio pagina
 
Precedente
Sommario
Successivo