Scale an Image to Fill a Frame Proportionally

From Scribus Wiki
Revision as of 06:39, 17 September 2007 by TrnsltLife (talk | contribs)
Jump to: navigation, search
This article is part of the Scripts series.

Scribus' Image Properties toolbar gives you the ability to "Scale to Frame Size: Proportional". This will proportionally scale the image to the largest size possible while still keeping the entire image within the confines of the frame: i.e., no cropping is done.

This script loops over every selected object, and for all image frames, it scales the image proportionally, filling the entire frame with your image. This means that some of the image will be cropped by the frame in either the horizontal or vertical dimension.

This script makes use of the getProperty(...) and setProperty(...) functions in order to access image properties that are not exposed by other functions. The script has been tested on Scribus and 1.3.4.

# -*- coding: utf-8 -*-
#This script scales the image so that it fills the frame completely. One dimension of the image (width/height) may overflow the frame, but at least one dimension will fill the frame exactly.
from scribus import *
if haveDoc():
    nbrSelected = selectionCount()

objList = []
for i in range(nbrSelected):
for i in range(nbrSelected):
        obj = objList[i]
        setScaleImageToFrame(True, False, obj)
        scaleX, scaleY = getImageScale(obj)
        setScaleImageToFrame(False, False, obj)
        if scaleX > scaleY:
            scale = scaleX
            scaleImage(scale, scale, obj)
        elif scaleY > scaleX:
            scale = scaleY
            scaleImage(scale, scale, obj)
	    nothing = "nothing"