Difference between revisions of "Split Image Across Gutter"

From Scribus Wiki
Jump to: navigation, search
(Added GPL3 License as alternative to CC-BY)
(Changed license to GPL2 per cbradney's request)
 
Line 20: Line 20:
 
# Released under a Creative Commons Attribution 3.0 license (CC-BY)
 
# Released under a Creative Commons Attribution 3.0 license (CC-BY)
 
#
 
#
# Alternatively released under GPL3:
+
# Alternatively released under GPL2:
 
# This script is free software: you can redistribute it and/or modify
 
# 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
 
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
+
# the Free Software Foundation, either version 2 of the License, or
 
# (at your option) any later version.
 
# (at your option) any later version.
 
#
 
#

Latest revision as of 01:00, 11 February 2014

This article is part of the Scripts series.

Depending on the type of binding you use, parts of an image may not be visible if you have an image that spans two pages. This script helps you address this issue.

Select an image and run the script. You'll be asked for the width of the binding and the width the image should bleed into the binding area.

SplitImageAcrossGutter.png

SplitImageAcrossGutter2.png

The steps for this script were based on information found in this Scribus bug report: http://bugs.scribus.net/view.php?id=2683

This script has been tested in Scribus 1.4.0.

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

# -*- coding: utf-8 -*-
# Copyright (C) 2012 Jeremy Brown
# Released under a Creative Commons Attribution 3.0 license (CC-BY)
#
# Alternatively released under GPL2:
# 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.
#
#This script takes an image that crosses a page boundary in a two-page layout, and splits the image into two pieces,
#taking into account the blank space taken up by the binding, and including the option for the image to bleed into the
#binding area.
#
#You can set the default binding and bleed measurements and units by changing the defaultBinding and defaultBleed variables below.
#
#
from scribus import *

if haveDoc() == False:
    sys.exit(0)

def unitsToPoints(units, unitType):
    return units / getUnitValue(unitType)

def pointsToUnits(points, unitType):
    return points * getUnitValue(unitType)

def getUnitValue(unitType):
    if unitType == UNIT_POINTS:
        return pt
    elif unitType == UNIT_MILLIMETERS:
        return mm
    elif unitType == UNIT_INCHES:
        return inch
    elif unitType == UNIT_PICAS:
        return p
    elif unitType == UNIT_CENTIMETRES:
        return cm
    elif unitType == UNIT_CICERO:
        return c
        
def getUnitName(unitType):
    if unitType == UNIT_POINTS:
        return "points"
    elif unitType == UNIT_MILLIMETERS:
        return "millimeters"
    elif unitType == UNIT_INCHES:
        return "inches"
    elif unitType == UNIT_PICAS:
        return "picas"
    elif unitType == UNIT_CENTIMETRES:
        return "centimeters"
    elif unitType == UNIT_CICERO:
        return "ciceros"
        

#You can set the default binding and bleed measurements and units by changing these two variables:
defaultBinding = unitsToPoints(1.5, UNIT_CENTIMETRES)
defaultBleed = unitsToPoints(0.5, UNIT_CENTIMETRES)


pageUnit = getUnit()

#Query user for binding width
terminate = False
while terminate == False:
    bindingWidth = valueDialog("Binding Width", "How much of the inside of each page will be lost in binding (in " + getUnitName(pageUnit) + ")?", str(pointsToUnits(defaultBinding, pageUnit)))
    if bindingWidth == "":
        sys.exit(0)
    try:
        bindingWidth = float(bindingWidth)
        terminate = True
    except:
        messageBox('Scribus - Script Error',"The number you entered was invalid. (" + bindingWidth + ")", ICON_WARNING, BUTTON_OK)

#Query user for bleed width
terminate = False
while terminate == False:
    bleedWidth = valueDialog("Bleed Width", "How much should the image bleed on the inside margin (in " + getUnitName(pageUnit) + ")?", str(pointsToUnits(defaultBleed, pageUnit)))
    if bleedWidth == "":
        sys.exit(0)    
    try:
        bleedWidth = float(bleedWidth)
        terminate = True
    except:
        messageBox('Scribus - Script Error',"The number you entered was invalid. (" + bleedWidth + ")", ICON_WARNING, BUTTON_OK)


pageWidth, pageHeight = getPageSize()
nbrSelected = selectionCount()
objList = []

#Get all selected objects
for i in range(nbrSelected):
    objList.append(getSelectedObject(i))
    
#Loop over all selected objects
for i in range(nbrSelected):
    try:
        img = objList[i]
        #Only process ImageFrame objects
        if str(getObjectType(img)) == "ImageFrame":
            imgWidth, imgHeight = getSize(img)
            imgX, imgY = getPosition(img)
            #Get image offsets in points
            offX = pointsToUnits(getProperty(img, "imageXOffset"), pageUnit)
            offY = pointsToUnits(getProperty(img, "imageYOffset"), pageUnit)
            #Starting width of the image left of the page division
            leftWidth = pageWidth - imgX
            #Starting width of the image right of the page division
            rightWidth = imgWidth - leftWidth
            #Only process images that stick out past the right edge of the page
            if imgX + imgWidth >= pageWidth:
                #Make the second image frame
                duplicateObject(img)
                #Get reference to the second image
                img2 = getSelectedObject()
                #Set scaling on images so they won't be distorted when changing the frame size
                setScaleImageToFrame(False, False, img)
                setScaleImageToFrame(False, False, img2)
                #Move images to their new positions
                moveObject(-bindingWidth, 0, img)
                moveObjectAbs(pageWidth + bindingWidth - bleedWidth, imgY, img2)
                #Resize each image frame
                sizeObject(leftWidth + bleedWidth, imgHeight, img)
                sizeObject(rightWidth + bleedWidth, imgHeight, img2)
                #Offset img2 in its frame
                newOffX = offX - leftWidth + bleedWidth
                setProperty(img2, "imageXOffset", unitsToPoints(newOffX, pageUnit))
                docChanged(1)
                setRedraw(True)
    except:
        nothing = "nothing"