使用VIP在图像上添加SVG路径

问题描述

我正在使用vips PHP库。我想在图像上添加svg路径。我为此实现了以下代码,但没有给我预期的输出。问题是如何根据实际图像的高度和宽度设置svg路径。我尝试使用调整大小和缩略图,但没有给我预期的输出。我也想在实际的图像块上填充灰色,就像预期的输出图像一样。

使用imagick生成的预期输出图像

$background = Vips\Image::newFromFile($arg[1],['access' => 'sequential']);
$svg = Vips\Image::svgload_buffer('<svg>
  <path 
    d="M0 200 v-200 h200 
    a100,100 90 0,1 0,200
    a100,1 -200,0
    z" stroke="#fff" fill="transparent"/>
</svg>');
// $svg = $svg->resize(2.5);
$svg = $svg->thumbnail_image(700,['height' => 700,'size' => 'both']);
$image = $background->composite($svg,'dest-in');
$image->writetoFile([$arg2],['background' => [128,128,128],'Q' => 100]);

以下是我添加了svg路径的图像

enter image description here

我的vips输出图像

enter image description here

预期的输出图像

enter image description here

解决方法

尝试:

subView.centerXAnchor.constraint(equalTo: parentView.centerXAnchor).isActive = true
subView.centerYAnchor.constraint(equalTo: parentView.centerYAnchor).isActive = true

相关的github问题:https://github.com/libvips/php-vips/issues/109

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...