1. Go to this page and download the library: Download webcooking/zpl-to-image library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webcooking / zpl-to-image example snippets
use Webcooking\ZplToImage\ZplToSvg;
$zplContent = file_get_contents('path/to/your/label.zpl');
// Default: Noto Sans font
$svgContent = ZplToSvg::convert($zplContent);
// Use IBM VGA font
$svgContent = ZplToSvg::convert($zplContent, 4.0, 6.0, 300, 'ibm-vga');
// Use your own custom font
$svgContent = ZplToSvg::convert($zplContent, 4.0, 6.0, 300, '/path/to/your/font.ttf');
// Save to file
file_put_contents('output.svg', $svgContent);
// View SVG in browser or convert to PNG with ImageMagick:
// convert -density 300 -background white output.svg output.png
use Webcooking\ZplToImage\ZplToGdImage;
$zplContent = file_get_contents('path/to/your/label.zpl');
// Convert to GDImage with default font (Noto Sans)
$image = ZplToGdImage::convert($zplContent);
imagepng($image, 'output.png');
imagedestroy($image);
// With custom parameters and font
$image = ZplToGdImage::convert(
$zplContent,
4.0, // width in inches
6.0, // height in inches
300, // DPI
'ibm-vga' // font: 'noto', 'ibm-vga', or '/path/to/font.ttf'
);
imagepng($image, 'output.png');
imagedestroy($image);
use Webcooking\ZplToImage\ZplToGdImage;
$zplContent = file_get_contents('path/to/your/label.zpl');
// Save directly as PNG (best quality)
ZplToGdImage::toPng(
$zplContent,
'output.png', // output path
4.0, // width in inches
6.0, // height in inches
300, // DPI
'noto', // font renderer
9 // PNG compression (0-9, 9=max)
);
// Save directly as JPEG
ZplToGdImage::toJpeg(
$zplContent,
'output.jpg', // output path
4.0, // width in inches
6.0, // height in inches
300, // DPI
'noto', // font renderer
90 // JPEG quality (0-100)
);
// Just get SVG string (no rasterization)
$svg = ZplToGdImage::toSvg($zplContent, 4.0, 6.0, 300, 'noto');
file_put_contents('output.svg', $svg);
use Webcooking\ZplToImage\ZplToImagick;
$imagick = ZplToImagick::convert($zplContent, 4.0, 6.0, 300, 'noto');
// Save as PNG/JPEG using Imagick methods
$imagick->writeImage('output_imagick.png');
$imagick->setImageFormat('jpeg');
$imagick->setImageCompressionQuality(90);
$imagick->writeImage('output_imagick.jpg');
$imagick->clear();
$imagick->destroy();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.