Images
TCPDF-Next supporte l'intégration d'images raster et vectorielles dans les documents PDF. Le sous-système image vit dans le module Graphics et est accessible via l'API fluide Document.
Formats supportés
| Format | Extension | Alpha | Notes |
|---|---|---|---|
| JPEG | .jpg, .jpeg | Non | Baseline et progressif |
| PNG | .png | Oui | 8-bit, 24-bit, 32-bit avec transparence |
| WebP | .webp | Oui | Lossy et lossless |
| AVIF | .avif | Oui | Nécessite GD ou Imagick avec support AVIF |
| SVG | .svg | -- | Vecteur — rendu via SvgParser |
| EPS | .eps, .ai | -- | PostScript — rendu via EpsParser |
image()
php
use Yeeefang\TcpdfNext\Core\Document;
$pdf = Document::create()
->addPage()
->image('/path/to/logo.png', 10, 10, 50, 0); // Largeur=50mm, hauteur autoSignature
php
image(
string $file, // Chemin fichier, URL ou chaîne @base64
float $x = '', // Position X ('' = X actuel)
float $y = '', // Position Y ('' = Y actuel)
float $w = 0, // Largeur (0 = auto depuis ratio)
float $h = 0, // Hauteur (0 = auto depuis ratio)
string $type = '', // Forcer format : 'JPEG', 'PNG', 'WebP', etc.
mixed $link = '', // URL ou identifiant de lien interne
string $align = '', // Alignement après image : T, M, B, N
bool $resize = false,
int $dpi = 300,
string $palign = '', // Alignement image dans cellule : L, C, R
bool $fitbox = false,
bool $fitonpage = false
): staticPositionnement et mise à l'échelle
php
$pdf->image('/path/to/photo.jpg', 10, 60, 100, 80); // Absolu : 100x80mm à (10,60)
$pdf->image('/path/to/banner.png', 10, 10, 190, 0); // Hauteur auto depuis largeur
$pdf->image('/path/to/portrait.jpg', 10, 10, 0, 100); // Largeur auto depuis hauteur
$pdf->image('/path/to/photo.jpg', 10, 10, 80, 60, fitbox: true); // Ajuster dans boîte
$pdf->image('/path/to/chart.png', 10, 10, 0, 0, fitonpage: true); // Ajuster sur page- Position absolue — fournir coordonnées explicites
$x,$y(unité par défaut : mm). - Hauteur/largeur auto — définir une dimension à
0; l'autre est calculée depuis le ratio. - Ajuster dans boîte (
fitbox: true) — mettre à l'échelle pour ajuster$wx$hen préservant le ratio. - Ajuster sur page (
fitonpage: true) — assurer que l'image ne dépasse jamais la zone imprimable.
DPI et résolution
Le paramètre $dpi contrôle le mapping pixel-vers-taille-physique quand $w et $h sont tous deux 0 :
php
$pdf->image('/path/to/scan.jpg', 10, 10, 0, 0, dpi: 150); // Plus grand sur page
$pdf->image('/path/to/scan.jpg', 10, 10, 0, 0, dpi: 300); // Plus petit sur pageImage depuis chaîne ou URL
php
$pdf->image('https://example.com/logo.png', 10, 10, 50, 0); // Depuis URL
$pdf->image('@' . base64_encode($imageData), 10, 10, 50, 0, 'PNG'); // Depuis base64Lors du chargement depuis une chaîne base64, fournissez le paramètre $type pour que le parseur connaisse le format.
Images avec liens
php
$pdf->image('/path/to/logo.png', 10, 10, 40, 0, link: 'https://example.com');Images SVG
imageSvg() rend le SVG comme chemins vectoriels PDF natifs — pas de rastérisation :
php
imageSvg(string $file, float $x, float $y, float $w, float $h, mixed $link = '', string $align = '', string $palign = '', mixed $border = 0): staticphp
$pdf->imageSvg('/path/to/diagram.svg', 10, 150, 180, 100);Images EPS / PostScript
php
imageEps(string $file, float $x, float $y, float $w, float $h, mixed $link = '', bool $useBBox = true, string $align = '', string $palign = '', mixed $border = 0): staticphp
$pdf->imageEps('/path/to/illustration.eps', 10, 10, 80, 60);Exemple complet
php
use Yeeefang\TcpdfNext\Core\Document;
$pdf = Document::create()
->addPage()
->image('/path/to/logo.png', 10, 10, 50, 0)
->image('/path/to/photo.jpg', 10, 60, 100, 80)
->imageSvg('/path/to/diagram.svg', 10, 150, 180, 100)
->save('output.pdf');Conseils
- Les canaux alpha PNG sont entièrement préservés dans la sortie PDF.
- Pour la meilleure qualité d'impression, utilisez des images à 300 DPI ou plus.
- Le rendu SVG supporte la plupart des fonctionnalités statiques ; les animations et JavaScript sont ignorés.
- Lors de l'intégration de nombreuses images, envisagez de pré-redimensionner les gros fichiers pour contrôler l'utilisation mémoire.