Skip to content

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 7 magick. See External tools.

Create the default PNG ​

php
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 ​

php
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 ​

CaseExtensionMIME typeNote
ImageFormat::PNGpngimage/pngDefault
ImageFormat::JPEGjpgimage/jpegFlattened onto white and re-encoded after trimming
ImageFormat::WEBPwebpimage/webp

SVG is not supported.

Resolution presets ​

CaseExport canvas
ImageResolution::HIGH4096 × 5792
ImageResolution::MEDIUM2048 × 2896
ImageResolution::LOW1024 × 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.

Last updated:

Released under the MIT License.