我正在尝试将页面上具有给定高度的图像列表组合在一起,以便它们首先沿页面向下流动,然后穿过页面,例如:
Image1 Image4 Image7
Image2 Image5 Image8
Image3 Image6 Image9
最大列数为3。问题是这些图像是动态传递的,但都有固定的宽度,即它们只能跨1/2/3列,因此可能会发生类似的情况:
Image1 Image4-Image4
Image2-Image2-Image2
Image3 Image5 Image6
此外,我的列表中每个图像的高度都是可变的,这意味着没有固定数量的行。因此,如果一个图像超出页面或与另一个图像重叠。还必须将其存储以备将来使用。允许空白,例如:
Image1 Image4
Image2-Image2 Image4
Image2-Image2 Image5
在上面的例子中,Image3占据了整个页面,或者可能占据了页面的3/4,这意味着它不适合,因此它被保留在另一个新页面上
如何实现这种组合图像的方法
你有一套相当复杂的规则。我认为,如果您想要实现这种精确的行为,可能需要编写一些代码
我试图避免做任何实际工作,因此我编写了一个小python来为您布局页面:
您可以这样运行它:
它似乎对我有用,并且实现了你所有的规则(我想)。我使用pyvips来进行页面渲染,因为我对它很熟悉,但是将它换成其他东西很简单
你可以通过一个技巧让ImageMagick在蒙太奇中首先垂直放置图像。首先对图像进行转置,蒙太奇,然后对结果进行转置
如果您不关心结果中图像的顺序,也不关心网格编号,只想获得给定输出大小的最佳匹配,那么ImageMagick有一个新功能来实现这一点。见ASHLAR:ouput.png,网址https://imagemagick.org/script/formats.php#pseudo
相关问题 更多 >
编程相关推荐