arindam/svg

一个将SVG代码转换为图像文件并下载的Laravel包

v1.0.1 2024-04-19 17:15 UTC

This package is auto-updated.

Last update: 2024-09-19 18:08:34 UTC


README

一个将SVG代码转换为图像文件并下载的Laravel包

安装

不依赖PHP版本和LARAVEL版本

步骤 1: 运行composer命令

composer require arindam/svg

步骤 2: Laravel没有自动发现

如果你不使用自动发现,请将ServiceProvider添加到config/app.php中的providers数组

在providers部分

Arindam\Svg\ArindamSvgServiceProvider::class,

在aliases部分

'SVG' => Arindam\Svg\Svg\SvgClassFacade::class,

全部完成!现在可以使用它了

// sample raw svg code
$rawSvgCode = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M192 384h192c53 0 96-43 96-96h32c70.6 0 128-57.4 128-128S582.6 32 512 32H120c-13.3 0-24 10.7-24 24v232c0 53 43 96 96 96zM512 96c35.3 0 64 28.7 64 64s-28.7 64-64 64h-32V96h32zm47.7 384H48.3c-47.6 0-61-64-36-64h583.3c25 0 11.8 64-35.9 64z"/></svg>';

**如果你想要将任何原始SVG代码转换为.svg图像文件

// just pass the raw svg code
SVG::svgCodeToImageSave($rawSvgCode));
// OUTPUT: 

// also want, you can pass file name as well
SVG::svgCodeToImageSave($rawSvgCode, "mysvg.svg"));
//OUTPUT: mysvg.svg

**如果你想要转换并下载它

$svg = SVG::svgCodeToImageDownload($rawSvgCode);
return response()->download($svg, "mysvg2.svg", array('Content-type' => 'image/svg+xml'));

**如果你想要直接在链接中渲染SVG

$svg = SVG::svgCodeToImageRender($rawSvgCode);
return response($svg, 200, array('Content-type' => 'image/svg+xml'));

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。

提交问题:如果发现任何问题

如果有任何问题,请联系我