Creating image previews
Use Dwg::toImage($source)->convert() to render a preview of the whole model space and trim its white margins. Choose PNG, JPEG, or WebP and one of three preset resolutions.
Requires LibreDWG
dwg2dxf, LibreOffice 7.4+soffice, and ImageMagick 7magick. See External tools.
Create the default PNG
use Mattmy\DwgConverter\Facades\Dwg;
$image = Dwg::toImage(storage_path('app/private/floor-plan.dwg'))->convert();
$path = $image->storeAs('drawing-previews', 'floor-plan.png');The defaults are PNG, no explicit intermediate DXF version, and ImageResolution::HIGH.
Choose format, DXF version, and resolution
use Mattmy\DwgConverter\DxfVersion;
use Mattmy\DwgConverter\ImageFormat;
use Mattmy\DwgConverter\ImageResolution;
$image = Dwg::toImage($request->file('drawing'))
->format(ImageFormat::WEBP)
->usingDxfVersion(DxfVersion::R2018)
->atResolution(ImageResolution::MEDIUM)
->convert();usingDxfVersion() sets the version of the intermediate DXF. Each option method returns a new operation and keeps the other settings. The conversion starts when you call convert().
Formats
| Case | Extension | MIME type | Note |
|---|---|---|---|
ImageFormat::PNG | png | image/png | Default |
ImageFormat::JPEG | jpg | image/jpeg | Flattened onto white and re-encoded after trimming |
ImageFormat::WEBP | webp | image/webp |
SVG is not supported.
Resolution presets
| Case | Export canvas |
|---|---|
ImageResolution::HIGH | 4096 × 5792 |
ImageResolution::MEDIUM | 2048 × 2896 |
ImageResolution::LOW | 1024 × 1448 |
These dimensions describe the canvas before white-margin trimming. Final dimensions depend on drawing content; the presets are not compression-quality settings.
Preview limitations
The result is a best-effort preview of the entire model space. It does not split multiple drawings, promise paper-space or viewport fidelity, supply missing fonts or xrefs, or guarantee an AutoCAD-identical image.