API 參考
本頁列出應用程式可直接使用的 API。操作細節與安裝方式請閱讀對應指南。
Facade 操作
Dwg::thumbnail(UploadedFile|string|DwgBinary $source): ThumbnailExtraction
Dwg::toDxf(UploadedFile|string|DwgBinary $source): DxfConversion
Dwg::toJson(UploadedFile|string|DwgBinary $source): JsonConversion
Dwg::toImage(UploadedFile|string|DwgBinary $source): ImageConversion每個方法只指定來源,不會讀寫檔案或執行轉換,並回傳新的操作物件。請參考輸入與輸出。
ThumbnailExtraction
extract(): DwgOutput擷取內嵌 BMP、PNG 或 WMF 預覽。請參考擷取縮圖。
DxfConversion
toVersion(DxfVersion $version): self
convert(): DwgOutputtoVersion() 回傳已指定目標版本的新操作;convert() 建立 ASCII DXF。請參考 轉換為 DXF。
DxfVersion 可選值:R12、R14、R2000、R2004、R2007、R2010、R2013、R2018。
JsonConversion
convert(): DwgOutput建立 LibreDWG 結構 JSON,沒有目標版本或格式選項。請參考輸出結構 JSON。
ImageConversion
format(ImageFormat $format): self
usingDxfVersion(DxfVersion $version): self
atResolution(ImageResolution $resolution): self
convert(): DwgOutput每個選項都回傳新操作並保留其他選擇。請參考建立圖片預覽。
ImageFormat:PNG、JPEG、WEBP。ImageResolution:HIGH、MEDIUM、LOW。
DwgBinary
DwgBinary::from(string $contents): DwgBinary
$binary->contents(): string包裝原始位元組內容,避免直接傳入字串時被當成本機路徑。
DwgOutput
extension(): string
mimeType(): string
output(): string
storeAs(string $path, ?string $name = null, ?string $disk = null): stringextension() 與 mimeType() 可以重複讀取。每個結果只能選擇 output() 或 storeAs() 呼叫一次, 即使失敗也不能重試;需要重試時,請重新執行轉換。複製、序列化或反序列化 DwgOutput 都會拋出 LogicException。
storeAs() 會保留你提供的檔名,再視需要加上輸出格式的副檔名;副檔名已相同時,只會統一大小寫。 省略 name 時,本機檔案與上傳檔案會沿用去掉副檔名後的名稱。如果名稱不安全或沒有名稱 (例如 DwgBinary),就使用 converted- 加上 16 個小寫十六進位字元。WebP 的 test1.webp 維持 test1.webp、test1.png 變成 test1.png.webp,test1.WEBP 變成 test1.webp。
例外
LibreDwgUnavailable、InvalidDwg、DwgOperationFailed 都提供:
reason(): string
context(): array請參考錯誤與疑難排解。
版本之間的變更請參考 Changelog。