gpt4 book ai didi

svg - TCPDF 指定 SVG 填充颜色

转载 作者:行者123 更新时间:2023-12-04 14:21:41 24 4
gpt4 key购买 nike

TCPDF 如何为 SVG 文件指定颜色?
https://tcpdf.org

即使文件中指定了其他颜色,我的还是纯黑色,我似乎无法超越它。
理想情况下,我希望能够动态设置颜色

$pdf->SetTextColor(255,255,255);
$pdf->SetTextColorArray(255,255,255);
$pdf->SetFillColor(255,255,255);
$pdf->SetFillColorArray(255,255,255);
$pdf->SetDrawColor(255,255,255);
$pdf->ImageSVG($file=get_stylesheet_directory_uri().'/images/icon-bath.svg', $x=155, $y=124, $w=10, $h=10, $link='', $align='', $palign='', $border=0, $fitonpage=false);

遵循这些示例

https://tcpdf.org/examples/example_058/

https://hotexamples.com/examples/-/TCPDF/ImageSVG/php-tcpdf-imagesvg-method-examples.html

最佳答案

改进了处理多个 SVG 文件的逻辑

function getModifiedSvgString($svg, $color) {
$doc = new DOMDocument;
$doc->load($svg);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');
$path_list = $xpath->query('svg:path');
$circle_list = $xpath->query('svg:circle');
foreach ($path_list as $path) {
$path->setAttribute('fill', $color);
}
foreach ($circle_list as $circle) {
$circle->setAttribute('fill', $color);
}
return $doc->saveXML();
}

// Icon 1
$svg = get_stylesheet_directory_uri() . '/images/icon-1.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 130, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);

// Icon 2
$svg = get_stylesheet_directory_uri() . '/images/icon-2.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 155, $y = 124, $w = 10, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);

// Icon 3
$svg = get_stylesheet_directory_uri() . '/images/icon-3.svg';
$svgString = getModifiedSvgString($svg, $UserCompanyColourSecondaryFontHex);
$pdf->ImageSVG($file = '@' . $svgString, $x = 178, $y = 124, $w = 18, $h = 10, $link = '', $align = '', $palign = '', $border = 0, $fitonpage = false);

关于svg - TCPDF 指定 SVG 填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53982203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com