在python中为scribus计算网格布局

时间:2018-01-29 23:51:53

标签: python-2.7 layout grid

我想在scribus中创建一个网格布局来创建一个相簿。网格布局应考虑图像大小并相应地放置图像。像pinterest布局/ masonry-layout一样。例如,如此处所示(摘自masonry.desandro.com

Masonry layout take from masonry.desandro.com

目前我试图找到一些我可以开始挖掘的信息,以便我可以构建这样一个编程网格。但是很难找到任何好的教程或解释如何创建这样的计算,或者我没有为我的搜索找到合适的关键字。

换句话说,我想开发一个脚本,我在一个页面上计算x和y位置,它会考虑图像比例并创建一个漂亮的页面。图像尺寸/比率将使用pillow中的信息进行计算。

我希望获得更多信息以深入了解此主题的任何提示和技巧。

我目前的做法目前并不是很有用

#!/usr/bin/env python
# run this script with 
# /Applications/Scribus.app/Contents/MacOS/Scribus -ns -py foobar.py

from scribus import *
from PIL import Image # Info: Scribus is build with python 2.7

# DIN A4 3508 x 2480 px = 29,7 x 21,0 cm; Ratio 3508/2480 = 1,41 = Portrait
# Ratio > 1 = Landscape 
# Ratio < 1 = Portrait 

# build a manuel grid for testing
# x,y,width, height 
pic1 = ( 15, 20, 270, 360 )
pic2 = ( 300, 20, 270, 360 )
pic3 = ( 15, 430, 270, 360 )
pic4 = ( 300, 430, 270, 360 )

layout = []
layout.append( pic1 )
layout.append( pic2 )
layout.append( pic3 )
layout.append( pic4 )

def doFrame( frame_layout ): 
    x,y,w,h = frame_layout
    createImage( x,y,w,h )

if newDocument(PAPER_A4, (10,10,10,10),PORTRAIT, 1, UNIT_POINTS, NOFACINGPAGES, FIRSTPAGERIGHT, 1):
    for frame in layout: 
        doFrame( frame )

    setRedraw(1)
    redrawAll()

else:
    result = messageBox ('Something is wrong',BUTTON_OK)

0 个答案:

没有答案