0

I have a template in which I'm attempting to change the source of a picture from Image 1, to Image 2 - yet I want Image 2 to keep the original size it was uploaded to the server in. (I want it in the position of Image 1, but its own dimensions.)

To do this, I figured I needed to use the adjust parameter - which I have attempted. The description for adjust=100% is "The picture is adjusted to be proportional to the original size." - which sounded like what I needed to do.

However, in my docx output, this seems to set the image size to be 100% of page width, rather than related to image size. (In the word image properties, it shows my image to be 208%, so I don't think it's related to my file!)

Is this a bug in opentbs, or have I misunderstood the docs? If so, how should I be doing it, or otherwise, can anyone thing of a work around? I attempted not using adjust at all, however that seems to have the same behaviour as adjust=inside - which I presume is the default.

With the normal thanks for a great tool!

Edit: The Error causing tag is below. I've found the problem reproducible when starting from nothing, and with just an image in the word doc. Word 2010, OpenTBS 1.8.

[onshow.logo;ope=changepic;tagpos=after;adjust=100%]
4

2 回答 2

2

问题是由TbsPicAdjust()函数期望图像的尺寸以点而不是像素提供的,因为 php 的getimagesize()函数正在返回。

它是通过将TbsPicGetDim_OpenXML_dml()函数中的两个固定系数替换为 9,525 而不是最初编码的 12,700 来解决的。(如果尺寸以点为单位,而不是像素,这将是一个合适的值。)

经过一些研究,据我所知,getimagesize()总是返回以像素而不是点为单位的大小,所以在我看来这可能是一个潜在的错误?


系数的附加来源,结合个人计算: http: //openxmldeveloper.org/discussions/formats/f/15/p/396/933.aspx

于 2014-01-02T12:26:54.843 回答
1

解决方法:

这取决于您使用的是新 (.docx) 还是旧 (.doc) 样式的文档。如果您有较新的样式,我不确定您是否可以在不将标记直接放入 XML 的情况下更改图像大小。较旧的(我相信是 VML)样式用于<v:shape>描述图片而不是<pic:pic>. 使用v:shape,您可以将描述图像大小等的 CSS 样式字符串放在一起。就像是:

$imgStyle = "position:absolute;left:0;top:0;width:800;height:600"

然后你的标签旁边只有一个changepic标签;就像是:

[imgStyle;att=v:shape#style]

较新的样式不使用这样的样式字符串来调整图像的大小和位置,该pic:pic元素充满了描述图像的嵌套标签,因此更难获得细节(尽管您当然可以尝试)。我最终为我的图像切换创建了一个子模板,因为我的模板是新格式并且兼容旧格式(所以我必须维护两个图像块)。这使我可以直接为图像尺寸维护 XML,但仍然可以在 Word 中编辑我的主模板。我只是在我的主模板中使用了一个包含子模板的标签,例如:

[LineItem.template;block=w:r;file='img.xml']

分离手动控制的 XML 允许我在 Word 中编辑主模板,而不会损坏真正自定义的部分。但是,使用这种技术,您可能会在子模板中的 onload/onshow 标记上遇到一些问题——我在子模板中更改的所有内容都由一个块控制。

于 2013-12-30T20:11:01.767 回答