---
title: Immagini
project: Total.js V4
version: 0.0.99
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/total-js-v4/0-0-99/reference/images/
updated: 2026-11-16T15:41:20.819Z
---

# Immagini

> L'oggetto globale Image, i metodi di un'immagine e le chiavi di configurazione delle immagini.

L'oggetto globale `Image` carica e misura le immagini, e un oggetto immagine costruisce i comandi per GraphicsMagick o ImageMagick. La guida [Immagini](../../guides/images/) spiega come usarli con degli esempi; questa pagina è il riferimento esatto.

## API

### new Image.Image(source, [converter], [width], [height])

Type: `class`

Un'immagine con un elenco di operazioni per GraphicsMagick o ImageMagick.

Returns: `Image`

Creala con `Image.load()`; il costruttore è `Image.Image` (alias `Image.Picture`). Proprietà:

- `filename` — il file sorgente, oppure `null` per uno stream o un buffer
- `outputType` — il formato di output; l'estensione del file, `jpg` per stream e buffer, oppure il valore di `output()`
- `width`, `height` — i valori passati a `Image.load()` (non vengono misurati)
- `builder` — l'elenco delle operazioni aggiunte finora

Tutti i metodi delle operazioni restituiscono l'immagine. Aggiungi i tuoi metodi con `F.prototypes()`, il cui argomento ha il prototipo `Image`.

Example: Estendere il prototipo
```js
F.prototypes(function(proto) {
	proto.Image.avatar = function() {
		return this.resizeCenter(128, 128).quality(80);
	};
});

Image.load(filename).avatar().save(target);
```

### Image.load(source, [converter], [width], [height])

Type: `method`

Crea un oggetto immagine da un file, uno stream o un buffer.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `source` | `String|Stream|Buffer` | yes |  | Un nome di file, uno stream leggibile o un buffer con l'immagine. |
| `converter` | `String` | no | `CONF.default_image_converter` | `gm` (GraphicsMagick), `im` (ImageMagick 6, `convert`) o `magick` (ImageMagick 7). |
| `width` | `Number` | no |  | Salvato in `image.width`; non usato dalle operazioni. |
| `height` | `Number` | no |  | Salvato in `image.height`; non usato dalle operazioni. |

Returns: `Image` Una nuova immagine.

Non viene ancora letto né eseguito nulla. Per un nome di file, il formato di output è l'estensione del file; per uno stream o un buffer, è `jpg` finché non chiami `output()`.

Example: Ridimensionare un file
```js
Image.load(PATH.public('photos/1.jpg')).resize(640).save(PATH.public('photos/1-small.jpg'));
```

Example: Da un buffer con ImageMagick 7
```js
var image = Image.load(buffer, 'magick');
image.output('png');
image.resize(64, 64);
image.pipe(res);
```

### Image.init(source, [converter], [width], [height])

Type: `method`

La stessa funzione di `Image.load()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `source` | `String|Stream|Buffer` | yes |  | Un nome di file, uno stream leggibile o un buffer con l'immagine. |
| `converter` | `String` | no | `CONF.default_image_converter` | `gm` (GraphicsMagick), `im` (ImageMagick 6, `convert`) o `magick` (ImageMagick 7). |
| `width` | `Number` | no |  | Salvato in `image.width`; non usato dalle operazioni. |
| `height` | `Number` | no |  | Salvato in `image.height`; non usato dalle operazioni. |

Returns: `Image` Una nuova immagine.

Crea un oggetto immagine; gli argomenti e il risultato sono gli stessi di `Image.load()`.

Example: Creare un'immagine
```js
var image = Image.init(filename);
image.grayscale().save(filename);
```

### Image.measure(type, buffer)

Type: `method`

Restituisce larghezza e altezza di un'immagine a partire dai suoi primi byte.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | Estensione o tipo MIME. |
| `buffer` | `Buffer` | yes |  | L'inizio del file (l'intero file per SVG; per JPEG, abbastanza byte da raggiungere l'header del frame). |

Returns: `Object` `{ width, height }`, oppure `undefined`/`null` quando non può essere letto.

Chiama la funzione di misura per il tipo. `type` è un'estensione con o senza punto, oppure un tipo MIME: `jpg`, `jpeg`, `png`, `gif`, `svg`, `webp`, `bmp`, `psd` (`image/jpeg`, `image/png`, `image/gif`, `image/svg+xml`, `image/webp`, `image/bmp`, `image/vnd.adobe.photoshop`). Per gli altri tipi restituisce `undefined`. Non serve alcuno strumento esterno.

Example: Misurare un buffer caricato
```js
var size = Image.measure('image/png', buffer);
if (size && size.width > 2000)
	console.log('Too large');
```

### Image.measureJPG(buffer)

Type: `method`

Restituisce larghezza e altezza di un'immagine JPG.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `buffer` | `Buffer` | yes |  | L'inizio del file. |

Returns: `Object` `{ width, height }`

Scorre i marker JPEG fino al primo header di frame (SOF). Restituisce `null` quando il buffer non è un JPEG o l'header non si trova nel buffer.

Example: Misurare un file
```js
var size = Image.measureJPG(Fs.readFileSync(filename));
console.log(size.width, size.height);
```

### Image.measurePNG(buffer)

Type: `method`

Restituisce larghezza e altezza di un'immagine PNG.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `buffer` | `Buffer` | yes |  | L'inizio del file. |

Returns: `Object` `{ width, height }`

Legge le dimensioni dal chunk IHDR; bastano 24 byte.

Example: Misurare un file
```js
var size = Image.measurePNG(Fs.readFileSync(filename));
console.log(size.width, size.height);
```

### Image.measureGIF(buffer)

Type: `method`

Restituisce larghezza e altezza di un'immagine GIF.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `buffer` | `Buffer` | yes |  | L'inizio del file. |

Returns: `Object` `{ width, height }`

Legge le dimensioni dello schermo logico; bastano 10 byte.

Example: Misurare un file
```js
var size = Image.measureGIF(Fs.readFileSync(filename));
console.log(size.width, size.height);
```

### Image.measureBMP(buffer)

Type: `method`

Restituisce larghezza e altezza di un'immagine BMP.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `buffer` | `Buffer` | yes |  | L'inizio del file. |

Returns: `Object` `{ width, height }`

Legge le dimensioni dall'header BMP. L'altezza è sempre positiva (le bitmap top-down hanno un'altezza negativa nel file).

Example: Misurare un file
```js
var size = Image.measureBMP(Fs.readFileSync(filename));
console.log(size.width, size.height);
```

### Image.measurePSD(buffer)

Type: `method`

Restituisce larghezza e altezza di un'immagine PSD.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `buffer` | `Buffer` | yes |  | L'inizio del file. |

Returns: `Object` `{ width, height }`

Legge le dimensioni dall'header di Photoshop.

Example: Misurare un file
```js
var size = Image.measurePSD(Fs.readFileSync(filename));
console.log(size.width, size.height);
```

### Image.measureWEBP(buffer)

Type: `method`

Restituisce la larghezza e l'altezza di un'immagine WebP lossy o lossless.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `buffer` | `Buffer` | yes |  | L'inizio del file. |

Returns: `Object` `{ width, height }`, oppure `undefined`.

Supporta immagini WebP lossy (`VP8 `) e lossless (`VP8L`). Servono i primi 30 byte. Restituisce `undefined` per un'intestazione sconosciuta.

Example: Misurare un file WebP
```js
var size = Image.measureWEBP(Fs.readFileSync(PATH.public('img/hero.webp')));
```

### Image.measureSVG(buffer)

Type: `method`

Restituisce larghezza e altezza di un'immagine SVG.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `buffer` | `Buffer` | yes |  | Il file SVG. |

Returns: `Object` `{ width, height }`, oppure `undefined`.

Cerca nel testo i primi attributi `width="N"` e `height="N"` con numeri interi. Le unità e `viewBox` non vengono letti. Restituisce `undefined` quando questi attributi non ci sono, e `0` per un lato mancante.

Example: Misurare un SVG
```js
var size = Image.measureSVG(Buffer.from('<svg width="120" height="40"></svg>'));
// { width: 120, height: 40 }
```

### Image.middleware(type, fn)

Type: `method`

Registra uno stream che elabora ogni output di un tipo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | Tipo di output, per esempio `png` o `.png`. |
| `fn` | `Function` | yes |  | Restituisce un nuovo stream di trasformazione. |

Returns: `undefined`

`fn()` deve restituire un nuovo stream di trasformazione (duplex) a ogni chiamata. L'output di `pipe()` e `stream()` per quel tipo passa attraverso di esso. Dopo `save()`, il file salvato viene letto, passato attraverso lo stream e scritto di nuovo prima della callback. Un solo middleware per tipo; uno nuovo sostituisce il precedente. Il tipo viene confrontato con il tipo di output (`png`, `jpg`...), quindi `jpeg` e `jpg` sono diversi.

Example: Far passare tutto l'output PNG attraverso uno stream
```js
var Stream = require('stream');

Image.middleware('png', function() {
	return new Stream.PassThrough();
});
```

### image.resize([w], [h], [options])

Type: `method`

Ridimensiona l'immagine mantenendo le proporzioni.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `w` | `Number` | no |  | Larghezza in pixel. Usa `0` o `null` per calcolarla dall'altezza. |
| `h` | `Number` | no |  | Altezza in pixel. Omettila per calcolarla dalla larghezza. |
| `options` | `String` | no |  | Un suffisso della dimensione: `!` (ignora le proporzioni), `>` (solo riduce), `<` (solo ingrandisce), `^` (riempie), `%` (percentuale). |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-resize WxH`. Con la sola larghezza, l'altezza viene calcolata, e viceversa. L'immagine si adatta al riquadro; aggiungi `options` per cambiare questo comportamento.

Example: Dimensioni comuni
```js
image.resize(800);           // width 800
image.resize(null, 600);     // height 600
image.resize(800, 600, '!'); // exactly 800x600
image.resize(1920, 1920, '>'); // only shrink
```

### image.resizeCenter(w, h, [color])

Type: `method`

Riempie la dimensione e ritaglia il resto attorno al centro.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `w` | `Number` | yes |  | Larghezza in pixel. |
| `h` | `Number` | yes |  | Altezza in pixel. |
| `color` | `String` | no | `'white'` | Colore di sfondo, per esempio `white` o `#F0F0F0`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Ridimensiona con `^` in modo che l'immagine copra `w` x `h`, poi ritaglia la parte centrale. Il risultato ha esattamente la dimensione indicata. `resize_center()` è un alias.

Example: Un avatar quadrato
```js
Image.load(filename).resizeCenter(200, 200).save(target);
```

### image.resizeAlign(w, h, [align], [color])

Type: `method`

Riempie la dimensione e ritaglia il resto attorno a un lato o a un angolo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `w` | `Number` | yes |  | Larghezza in pixel. |
| `h` | `Number` | yes |  | Altezza in pixel. |
| `align` | `String` | no | `'center'` | Quale parte mantenere. |
| `color` | `String` | no | `'white'` | Colore di sfondo, per esempio `white` o `#F0F0F0`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Come `resizeCenter()`, ma mantiene la parte indicata da `align` (i valori di `align()`, per esempio `top`, `bottom`, `top left`). `resize_align()` è un alias.

Example: Mantenere la parte superiore
```js
image.resizeAlign(1200, 400, 'top');
```

### image.miniature(w, h, [color], [filter])

Type: `method`

Adatta l'intera immagine alla dimensione e riempie l'area vuota.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `w` | `Number` | yes |  | Larghezza in pixel. |
| `h` | `Number` | yes |  | Altezza in pixel. |
| `color` | `String` | no | `'white'` | Colore di sfondo, per esempio `white` o `#F0F0F0`. |
| `filter` | `String` | no | `'Hamming'` | Filtro di ridimensionamento. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Esegue `thumbnail(w, h)` con il filtro, centra il risultato e lo estende esattamente a `w` x `h` con il colore di sfondo. Non viene tagliato nulla.

Example: Foto di prodotto su bianco
```js
image.miniature(300, 300);
image.miniature(300, 300, '#000000', 'Lanczos');
```

### image.thumbnail([w], [h], [options])

Type: `method`

Ridimensiona l'immagine con l'opzione `-thumbnail`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `w` | `Number` | no |  | Larghezza in pixel. Usa `0` o `null` per calcolarla dall'altezza. |
| `h` | `Number` | no |  | Altezza in pixel. Omettila per calcolarla dalla larghezza. |
| `options` | `String` | no |  | Un suffisso della dimensione: `!` (ignora le proporzioni), `>` (solo riduce), `<` (solo ingrandisce), `^` (riempie), `%` (percentuale). |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Funziona come `resize()`. Lo strumento rimuove anche i profili, quindi è una buona scelta per piccole anteprime.

Example: Anteprima
```js
image.thumbnail(150, 150);
```

### image.scale([w], [h], [options])

Type: `method`

Ridimensiona l'immagine senza filtro di ricampionamento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `w` | `Number` | no |  | Larghezza in pixel. Usa `0` o `null` per calcolarla dall'altezza. |
| `h` | `Number` | no |  | Altezza in pixel. Omettila per calcolarla dalla larghezza. |
| `options` | `String` | no |  | Un suffisso della dimensione: `!` (ignora le proporzioni), `>` (solo riduce), `<` (solo ingrandisce), `^` (riempie), `%` (percentuale). |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-scale`. È più veloce di `resize()` e dà una qualità inferiore.

Example: Metà dimensione
```js
image.scale(50, 50, '%');
```

### image.crop(w, h, [x], [y])

Type: `method`

Ritaglia un rettangolo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `w` | `Number` | yes |  | Larghezza in pixel. |
| `h` | `Number` | yes |  | Altezza in pixel. |
| `x` | `Number` | no | `0` | Offset da sinistra. |
| `y` | `Number` | no | `0` | Offset dall'alto. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-crop WxH+X+Y`. L'offset è relativo alla gravity impostata con `align()` (in alto a sinistra per impostazione predefinita). L'offset deve essere zero o positivo.

Example: Ritagliare una regione
```js
image.crop(400, 300, 50, 20);
```

### image.extent([w], [h], [x], [y])

Type: `method`

Imposta la dimensione della tela.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `w` | `Number` | no |  | Larghezza in pixel. Usa `0` o `null` per calcolarla dall'altezza. |
| `h` | `Number` | no |  | Altezza in pixel. Omettila per calcolarla dalla larghezza. |
| `x` | `Number` | no |  | Offset orizzontale. |
| `y` | `Number` | no |  | Offset verticale. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-extent`. Una tela più grande viene riempita con il colore di sfondo; una più piccola taglia l'immagine. `x` e `y` spostano l'immagine (sono ammessi valori negativi).

Example: Tela quadrata
```js
image.background('white').align('center').extent(500, 500);
```

### image.align(type)

Type: `method`

Imposta la gravity di `crop()`, `extent()` e `watermark()`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | La posizione. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-gravity`. Valori: `top left`, `top`, `top right`, `left`, `center` (o `middle`), `right`, `bottom left`, `bottom`, `bottom right`; le parole possono essere in qualsiasi ordine (`left top`) e si può aggiungere `center` (`top center`). Gli altri valori passano allo strumento invariati, per esempio `NorthEast`. `gravity()` è un alias.

Example: Filigrana nell'angolo
```js
image.align('bottom right');
image.watermark(PATH.public('img/logo.png'), 10, 10);
```

### image.filter(type)

Type: `method`

Imposta il filtro di ricampionamento per il ridimensionamento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | Nome del filtro. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-filter`, per esempio `Lanczos`, `Box`, `Hamming`, `Triangle`. Consulta la documentazione del tuo strumento per tutti i nomi.

Example: Riduzione nitida
```js
image.filter('Lanczos').resize(800);
```

### image.quality([percentage])

Type: `method`

Imposta la qualità di compressione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `percentage` | `Number` | no | `80` | Da 1 a 100. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-quality`. Senza argomento, il valore è `80`.

Example: Impostare la qualità
```js
image.quality(85);
```

### image.rotate(deg)

Type: `method`

Ruota l'immagine.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `deg` | `Number` | yes | `0` | Gradi. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-rotate`. I valori positivi ruotano in senso orario. Viene eseguito dopo le operazioni di ridimensionamento e ritaglio (priorità 8).

Example: Ruotare
```js
image.rotate(90);
```

### image.flip()

Type: `method`

Specchia l'immagine verticalmente (dall'alto in basso).

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-flip`.

Example: Flip
```js
image.flip();
```

### image.flop()

Type: `method`

Specchia l'immagine orizzontalmente (da sinistra a destra).

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-flop`.

Example: Flop
```js
image.flop();
```

### image.blur(radius)

Type: `method`

Sfoca l'immagine.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `radius` | `Number|String` | yes |  | Il raggio della sfocatura. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-blur`. Il valore viene passato allo strumento, quindi può essere un numero o `radiusxsigma`, per esempio `0x8`.

Example: Sfocare
```js
image.blur('0x8');
```

### image.grayscale()

Type: `method`

Converte l'immagine in scala di grigi.

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-colorspace Gray`.

Example: Grigio
```js
image.grayscale();
```

### image.sepia()

Type: `method`

Dà all'immagine un tono seppia.

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-modulate 115,0,100` e `-colorize 7,21,50`.

Example: Seppia
```js
image.sepia();
```

### image.normalize()

Type: `method`

Estende il contrasto all'intera gamma.

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-normalize`.

Example: Normalizzare
```js
image.normalize();
```

### image.colors(value)

Type: `method`

Riduce il numero di colori.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Number` | yes |  | Il numero massimo di colori. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-colors`. Utile per piccoli file PNG e GIF.

Example: 256 colori
```js
image.output('png').colors(256);
```

### image.bitdepth(value)

Type: `method`

Imposta la profondità di bit di un canale.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `Number` | yes |  | Bit per canale, per esempio `8`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-depth`.

Example: 8 bit
```js
image.bitdepth(8);
```

### image.background(color)

Type: `method`

Imposta il colore di sfondo.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `color` | `String` | yes |  | Il nome di un colore o `#RRGGBB`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-background` e `-extent 0x0`. Il colore riempie le aree trasparenti e l'area aggiunta da `extent()`, `rotate()` e `miniature()`.

Example: Sfondo bianco
```js
image.background('#FFFFFF');
```

### image.fill(color)

Type: `method`

Imposta il colore di riempimento per il disegno.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `color` | `String` | yes |  | Il nome di un colore o `#RRGGBB`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-fill`. Usalo con le opzioni di `command()` che disegnano, per esempio `-colorize`.

Example: Riempimento
```js
image.fill('red');
```

### image.watermark(filename, [x], [y], [w], [h])

Type: `method`

Disegna un'altra immagine sopra questa.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | yes |  | Il file della filigrana. |
| `x` | `Number` | no | `0` | Offset orizzontale. |
| `y` | `Number` | no | `0` | Offset verticale. |
| `w` | `Number` | no | `0` | Larghezza della filigrana. |
| `h` | `Number` | no | `0` | Altezza della filigrana. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-draw` con `image over X,Y W,H filename`. Il nome del file non deve contenere spazi né virgolette. La posizione è relativa alla gravity di `align()`. Con `w` e `h` impostati a `0`, la filigrana mantiene le sue dimensioni.

Example: Logo nell'angolo in basso a destra
```js
Image.load(filename)
	.resize(1200)
	.align('bottom right')
	.watermark(PATH.public('img/logo.png'), 20, 20)
	.save(target);
```

### image.limit(type, value)

Type: `method`

Limita le risorse che lo strumento può usare.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | La risorsa. |
| `value` | `Number|String` | yes |  | Il limite, nelle unità dello strumento. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `-limit type value`, per esempio `memory`, `map`, `disk`, `threads`. Quando la chiami, `default_image_consumption` non viene applicato a questa immagine.

Example: Due thread
```js
image.limit('threads', 2);
```

### image.minify()

Type: `method`

Rimuove i profili e i metadati.

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Aggiunge `+profile "*"`, che rimuove EXIF, ICC e altri profili e rende il file più piccolo. `save()`, `pipe()` e `stream()` la chiamano da soli quando l'immagine non ha alcuna operazione.

Example: Rimuovere i metadati
```js
Image.load(filename).minify().save(filename);
```

### image.output(type)

Type: `method`

Imposta il formato di output.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | yes |  | Per esempio `png`, `webp`, `.jpg`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Cambia `image.outputType` (un punto iniziale viene rimosso). `pipe()` e `stream()` lo usano come formato, e `res.image()` lo usa per il `Content-Type`. `save()` prende il formato dall'estensione del file di destinazione.

Example: Convertire uno stream in PNG
```js
Image.load(stream).output('png').resize(100).pipe(res);
```

### image.make(fn)

Type: `method`

Chiama una funzione con l'immagine.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `Function(image)` | yes |  | Aggiunge le operazioni. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

`fn` viene chiamata con l'immagine come `this` e come argomento. Usala per riutilizzare un insieme di operazioni.

Example: Preset riutilizzabile
```js
function preview(image) {
	image.resize(300).quality(70);
}

Image.load(filename).make(preview).save(target);
```

### image.command(key, [value], [priority], [escape])

Type: `method`

Aggiunge qualsiasi opzione dello strumento.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `key` | `String` | yes |  | L'opzione, per esempio `-sharpen`. |
| `value` | `String|Number` | no |  | Il valore dell'opzione. |
| `priority` | `Number|Boolean` | no | `10` | Ordine dell'opzione. |
| `escape` | `Boolean` | no | `false` | Mette il valore tra virgolette. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Usala per le opzioni senza un metodo dedicato, per esempio `-strip`, `-sharpen` o `-define`. Le opzioni vengono eseguite nell'ordine della loro priorità (vedi la guida). `escape` mette il valore tra virgolette e ne rimuove `'`; usalo per i valori che arrivano dagli utenti. Con `priority` impostato a `true`, la priorità è `0` e il valore viene sottoposto a escape.

Example: Nitidezza e interlacciamento
```js
image.resize(800);
image.command('-sharpen', '0x1');
image.command('-interlace', 'Plane');
```

### image.clear()

Type: `method`

Rimuove tutte le operazioni.

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Svuota `image.builder`. `save()` la chiama dopo l'esecuzione, così lo stesso oggetto immagine può essere riutilizzato.

Example: Ricominciare
```js
image.clear().resize(100);
```

### image.measure(callback)

Type: `method`

Legge larghezza e altezza del file sorgente.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function(err, size)` | yes |  | `size` è `{ width, height }`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Legge l'inizio del file e lo misura in JavaScript. Funziona solo per un'immagine caricata da un nome di file con estensione `.jpg`, `.png`, `.gif` o `.webp` (minuscola o maiuscola); le altre estensioni, compresa `.jpeg`, danno un errore. Per uno stream o un buffer usa `Image.measure()`, e per gli altri formati `identify()`.

Example: Misurare un file
```js
Image.load(PATH.public('img/a.jpg')).measure(function(err, size) {
	console.log(size.width, size.height);
});
```

### image.identify(callback)

Type: `method`

Legge il tipo e le dimensioni del file sorgente con lo strumento esterno.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function(err, info)` | yes |  | `info` è `{ type, width, height }`, per esempio `{ type: 'JPEG', width: 800, height: 600 }`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Esegue `gm identify` (o `identify` per `im` e `magick`) e analizza la prima riga. Richiede un'immagine caricata da un nome di file.

Example: Identificare
```js
Image.load(filename).identify(function(err, info) {
	err && console.error(err);
	info && console.log(info.type, info.width, info.height);
});
```

### image.save([filename], [callback], [writer])

Type: `method`

Esegue le operazioni e salva il risultato in un file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | no | `the source file` | Il file di destinazione. |
| `callback` | `Function(err, saved)` | no |  | `saved` è `true` in caso di successo e `false` in caso di errore. |
| `writer` | `Function(stdin)` | no |  | Riceve lo stream di input dello strumento, per scrivere tu la sorgente. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

Senza `filename`, il file sorgente viene sovrascritto. Il formato segue l'estensione di `filename`. Un `Image.middleware()` registrato per il tipo di output viene eseguito dopo la scrittura del file. Dopo l'esecuzione, le operazioni vengono cancellate.

Example: Salvare una copia come WebP
```js
Image.load(PATH.public('img/photo.jpg'))
	.resize(1024)
	.quality(75)
	.save(PATH.public('img/photo.webp'), function(err, saved) {
		if (err)
			console.error(err);
	});
```

### image.pipe(stream, [type], [options])

Type: `method`

Esegue le operazioni e invia il risultato in pipe a uno stream scrivibile.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `stream` | `Stream` | yes |  | Uno stream scrivibile, per esempio uno stream di file o `res`. |
| `type` | `String` | no | `image.outputType` | Formato di output. |
| `options` | `Object` | no |  | Opzioni di `pipe()`. |

Returns: `Image` La stessa immagine, per concatenare le chiamate.

`type` è il formato di output: `jpg`, `jpeg`, `png`, `gif`, `apng`, `heif`, `heic`, `webp` o `ico`. Un altro valore o nessun valore usa `image.outputType`. `options` vengono passate a `stream.pipe()`. Gli errori dello strumento vengono emessi come eventi `error` di `stream`.

Example: Scrivere in uno stream di file
```js
var target = Fs.createWriteStream(PATH.temp('thumb.png'));
Image.load(buffer).resize(64, 64).pipe(target, 'png');
```

### image.stream([type], [writer])

Type: `method`

Esegue le operazioni e restituisce il risultato come stream leggibile.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | no | `image.outputType` | Formato di output. |
| `writer` | `Function(stdin)` | no |  | Scrive i dati sorgente. |

Returns: `ReadableStream` L'output dello strumento (attraverso il middleware, se ne è registrato uno).

`type` funziona come in `pipe()`. `writer(stdin)` ti permette di scrivere tu la sorgente nello strumento.

Example: Caricare un'immagine ridimensionata
```js
var stream = Image.load(filename).resize(500).stream('jpg');
stream.pipe(Fs.createWriteStream(PATH.temp('small.jpg')));
```

### default_image_consumption : 0

Type: `config`

Limita la memoria di GraphicsMagick o ImageMagick, in percentuale.

Returns: `Number`

Quando non è `0`, ogni immagine senza un proprio `limit()` riceve `-limit memory` (15 × valore) e `-limit map` (30 × valore). È disattivata per impostazione predefinita perché alcune versioni di GraphicsMagick falliscono con questi limiti. Nel file di configurazione è ammesso il segno `%`.

Predefinito: `0` (disattivato).

Example: Metà dei limiti predefiniti
```text
default_image_consumption : 50
```
