Scale an Image to Fill a Frame Proportionally: Difference between revisions

From Scribus Wiki
Jump to navigation Jump to search
(New page: {{Scripting Index}} 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 w...)
 
(Changed license to GPL per cbradney's request)
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Scripting Index}}
{{Scripting Index}}


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.
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, and part of the frame may be filled with empty space or the background color of the image frame.


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 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.
Line 7: Line 7:
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 1.3.3.9 and 1.3.4.
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 1.3.3.9 and 1.3.4.


<pre><nowiki>
See also this script ([[Image Wizard: Scale and Align an Image]]) which can scale and align images.
 
Save this script with a filename of Image_FillFrameProportionally.py, for example.
 
<syntaxhighlight lang='python'>
# -*- 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.
 
# License
# Copyright 2007, Jeremy Brown (TrnsltLife)
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
 
from scribus import *
from scribus import *
if haveDoc():
if haveDoc():
     nbrSelected = selectionCount()
     nbrSelected = selectionCount()


objList = []
objList = []
 
for i in range(nbrSelected):
for i in range(nbrSelected):
     objList.append(getSelectedObject(i))
     objList.append(getSelectedObject(i))
Line 21: Line 36:
     try:
     try:
         obj = objList[i]
         obj = objList[i]
         props = ""
         setScaleImageToFrame(True, False, obj)
         propList = getPropertyNames(obj)
        scaleX, scaleY = getImageScale(obj)
         for p in propList:
         setScaleImageToFrame(False, False, obj)
             props = props + p + " (" + str(getPropertyCType(obj, p) + "): " + str(getProperty(obj, p))) + "\n"
         if scaleX > scaleY:
         messageBox("Property Info for " + obj, "Below is a property list for the selected object named " + obj + "\n" + props, ICON_INFORMATION)
             scale = scaleX
     except WrongFrameTypeError:
            scaleImage(scale, scale, obj)
        elif scaleY > scaleX:
            scale = scaleY
            scaleImage(scale, scale, obj)
        docChanged(1)
         setRedraw(True)
     except:
    nothing = "nothing"
    nothing = "nothing"
</nowiki></pre>
</syntaxhighlight>

Revision as of 22:58, 10 February 2014

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, and part of the frame may be filled with empty space or the background color of the image frame.

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 1.3.3.9 and 1.3.4.

See also this script (Image Wizard: Scale and Align an Image) which can scale and align images.

Save this script with a filename of Image_FillFrameProportionally.py, for example.

# -*- 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.

# License
# Copyright 2007, Jeremy Brown (TrnsltLife)
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

from scribus import *
if haveDoc():
    nbrSelected = selectionCount()

objList = []
	
for i in range(nbrSelected):
    objList.append(getSelectedObject(i))
	
for i in range(nbrSelected):
    try:
        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)
        docChanged(1)
        setRedraw(True)
    except:
	    nothing = "nothing"