在GIMP中附加路径上的文本

2024-10-01 00:19:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我发现gimpapi已经几天了(使用python-fu),我真的很喜欢它。 但是有件事我做不到:在路径上附加一个文本。在

使用用户界面执行此操作非常简单(创建路径>创建文本>单击工具箱中的“沿路径文本”)。。。但是,正如你所料,当事情很简单的时候,我并不爱你。这就是为什么我要用python来实现它。在

以下是我已经设法做到的:

  • 创建图层
  • 在上面添加一条路径
  • 创建新文本
  • 展示整个过程

我现在要做的就是学习如何让我的文章遵循路径。在

我们将非常感谢您的帮助。在

谢谢你


Tags: 文本路径图层过程文章工具箱用户界面事情
1条回答
网友
1楼 · 发布于 2024-10-01 00:19:51

在互联网右侧(上面没有裸体的人)做了一个又一个小时的研究之后,我对我的问题还没有找到太多的答案。这就是为什么我决定查看Gimp源代码,以了解神奇的“沿路径文本”实际上是如何工作的。。。而且似乎还没有通过pdb来实现这一行动。在

之后,为了确定,我在gimp开发人员的邮件列表上问过,有人(我不知道是否允许我在这里告诉他的名字)回答我:

The "text along path" function is basically a hack, and was never intended to be a final product. A proper text-along-path function would allow the path to be changed and alter the text accordingly. The way that the warped text is rendered is also less than ideal. Because the plan was always that the functionality would change, no PDB hook was ever created for it.

另一个告诉我如何创建自己的“沿路径文本”插件:

However, as far as I know, the Bezier strokes in a path have the following property, applying an affine transform to their control points and handles is equivalent to applying the same transform to every point of the curve. So you can do something like this:

  • determine a "reference path", that is, a straight path along the text (or running though the middle of it)
  • for each stroke iterate the control points, and on each point ("C"):
    • determine projection on reference path (distance from origin of reference path) (elt's call it "R") and distance to it
    • find the corresponding point on the target path (pdb.gimp_path_get_point_at_dist()), "R'"
    • find the position of the new control point C': same distance to target path, on perpendicular
    • compute the position of the handles:
      • compute dx/dy between H and C
      • compute equivalent position H' from the new control point C'
      • apply rotation, centered on C' with an angle that is the direction of the target path in R' (as returned by earlier gimp_path_get_point_at_dist()) to produce new handle position (H")
      • repeat for 2nd handle
      • add the triplet C', H"1, H"2 to the new stroke

然后他鼓励我看两个与向量类似的插件,分别名为ribbon path和slinky,它们在http://gimp-path-tools.sourceforge.net/上可用

我希望(多亏了这两个人)这篇文章会有所帮助。在

相关问题 更多 >