def alignImage(self):
        if scribus.haveDoc():
            restore_units = scribus.getUnit(
            )  # since there is an issue with units other than points,
            scribus.setUnit(0)  # we switch to points then restore later.
            nbrSelected = scribus.selectionCount()
            objList = []
            for i in range(nbrSelected):
                objList.append(scribus.getSelectedObject(i))
            scribus.deselectAll()
            for i in range(nbrSelected):
                try:
                    obj = objList[i]
                    scribus.selectObject(obj)
                    frameW, frameH = scribus.getSize(obj)
                    saveScaleX, saveScaleY = scribus.getImageScale(obj)
                    scribus.setScaleImageToFrame(1, 0, obj)
                    fullScaleX, fullScaleY = scribus.getImageScale(obj)
                    scribus.setScaleImageToFrame(0, 0, obj)
                    scribus.setImageScale(saveScaleX, saveScaleY, obj)
                    imageW = frameW * (saveScaleX / fullScaleX)
                    imageH = frameH * (saveScaleY / fullScaleY)
                    imageX = 0.0
                    imageY = 0.0

                    if self.alignVar.get()[0] == "T":
                        imageY = 0.0
                    elif self.alignVar.get()[0] == "M":
                        imageY = (frameH - imageH) / 2.0
                    elif self.alignVar.get()[0] == "B":
                        imageY = (frameH - imageH)
                    if self.alignVar.get()[1] == "L":
                        imageX = 0.0
                    elif self.alignVar.get()[1] == "C":
                        imageX = (frameW - imageW) / 2.0
                    elif self.alignVar.get()[1] == "R":
                        imageX = (frameW - imageW)

                    scribus.setImageOffset(imageX, imageY, obj)
                    scribus.docChanged(1)
                    scribus.setRedraw(True)
                    scribus.deselectAll()
                except:
                    nothing = "nothing"
            scribus.setUnit(restore_units)

            self.master.destroy()
예제 #2
0
    def alignImage(self):
        if scribus.haveDoc():
	    restore_units = scribus.getUnit()   # since there is an issue with units other than points,
	    scribus.setUnit(0)			# we switch to points then restore later.
            nbrSelected = scribus.selectionCount()
            objList = []
            for i in range(nbrSelected):
                objList.append(scribus.getSelectedObject(i))
            scribus.deselectAll()
            for i in range(nbrSelected):
                try:
                    obj = objList[i]
                    scribus.selectObject(obj)
                    frameW, frameH = scribus.getSize(obj)
                    saveScaleX, saveScaleY = scribus.getImageScale(obj)
                    scribus.setScaleImageToFrame(1, 0, obj)
                    fullScaleX, fullScaleY = scribus.getImageScale(obj)
                    scribus.setScaleImageToFrame(0, 0, obj)
                    scribus.setImageScale(saveScaleX, saveScaleY, obj)
                    imageW = frameW * (saveScaleX / fullScaleX)
                    imageH = frameH * (saveScaleY / fullScaleY)
                    imageX = 0.0
                    imageY = 0.0
 
                    if self.alignVar.get()[0] == "T":
                        imageY = 0.0
                    elif self.alignVar.get()[0] == "M":
                        imageY = (frameH - imageH) / 2.0
                    elif self.alignVar.get()[0] == "B":
                        imageY = (frameH - imageH)
                    if self.alignVar.get()[1] == "L":
                        imageX = 0.0
                    elif self.alignVar.get()[1] == "C":
                        imageX = (frameW - imageW) / 2.0
                    elif self.alignVar.get()[1] == "R":
                        imageX = (frameW - imageW)
 
                    scribus.setImageOffset(imageX, imageY, obj)
                    scribus.docChanged(1)
                    scribus.setRedraw(True)
                    scribus.deselectAll()
                except:
                    nothing = "nothing"
	    scribus.setUnit(restore_units)
	    
	    self.master.destroy()
예제 #3
0
 def __init__(self, *args):
     """
     Optional argument "name" 
     """
     if len(args) > 0:
         self.name = args[0]
         self.path = sc.getImageFile(self.name)
         self.width, self.height = sc.getSize(self.name)
         self.offset_x, self.offset_y = sc.getImageOffset(self.name)
         self.scale_x, self.scale_y = sc.getImageScale(self.name)
예제 #4
0
def main():
    if sc.selectionCount() == 2:
        images = ( sc.getSelectedObject(0), sc.getSelectedObject(1) )
        for image in images:
            if sc.getObjectType(image) != "ImageFrame":
                logging.debug(f"Image type {sc.getObjectType(image)}, but 'ImageFrame' expected")
                error_msg(f'{image} not an image frame. But type {sc.getObjectType(image)}')
        image_files = (sc.getImageFile(images[0]), sc.getImageFile(images[1]))
        # keep Scale and Offset, before reset by image load
        image_0_offset = sc.getImageOffset(images[0])
        image_0_scale  = sc.getImageScale(images[0])
        image_1_offset = sc.getImageOffset(images[1])
        image_1_scale  = sc.getImageScale(images[1])
        sc.loadImage(image_files[1], images[0]) 
        sc.loadImage(image_files[0], images[1]) 
        if sc.getSize(images[0]) == sc.getSize(images[1]):
            # Frames have the same size swap scale and offset
            logging.debug(f"Frames have the same size {sc.getSize(images[0])}, swap offset and scale")
            logging.debug(f"Image 0: {images[0]}, Image 1: {images[1]}")
            logging.debug(f"Image properties: offset {sc.getImageOffset(images[0])}, scale {image_0_scale}")

            sc.setImageOffset(*image_1_offset, images[0])
            sc.setImageScale(*image_1_scale, images[0])
            sc.setImageOffset(*image_0_offset, images[1])
            sc.setImageScale(*image_0_scale, images[1])
        else:
            # scale and center
            logging.debug("Different size scale and center, both.")
            for name in images:
                x, y = sff.scale_to_frame(name)
                sff.center_image(name, x, y)


    else:
        logging.debug(f"{sc.selectionCount()} frames selected.")
        error_msg(f'{sc.selectionCount()} frames selected')
예제 #5
0
def center_image(name, image_x, image_y):
    """
    name: image naem
    image_x: original image width
    image_y: original image higth
    """

    scaleC, _ = sc.getImageScale(name)
    offX, offY = sc.getImageOffset(name)
    frame_x, frame_y = sc.getSize(name)
    ix = image_x * scaleC
    iy = image_y * scaleC

    if ix != frame_x:
        offX = (frame_x - ix) / 2
    if iy != frame_y:
        offY = (frame_y - iy) / 2
    sc.setImageOffset(offX, offY, name)
예제 #6
0
def scale_to_frame(obj):
    """
    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
    return scaled image size (X, Y) 
    """
    try:
        sc.setScaleImageToFrame(True, False, obj)
        scale_x, scale_y = sc.getImageScale(obj)
        frame_x, frame_y = sc.getSize(obj)
        sc.setScaleImageToFrame(False, False, obj)
        if scale_x > scale_y:
            scale = scale_x
        elif scale_y > scale_x:
            scale = scale_y
        sc.setImageScale(scale, scale, obj)
        image_x = int(round(frame_x / scale_x))
        image_y = int(round(frame_y / scale_y))
        return (image_x, image_y)
    except:
        logging.info("scaling for image {} failed".format(obj))
예제 #7
0
def main(argv):
    unit = scribus.getUnit()
    units = [' pts', 'mm', ' inches', ' picas', 'cm', ' ciceros']
    unitlabel = units[unit]
    if scribus.selectionCount() == 0:
        scribus.messageBox(
            'Scribus - Script Error',
            "There is no object selected.\nPlease select a text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox(
            'Scribus - Script Error',
            "You have more than one object selected.\nPlease select one text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    textbox = scribus.getSelectedObject()
    pageitems = scribus.getPageItems()
    boxcount = 1
    for item in pageitems:
        if (item[0] == textbox):
            if (item[1] != 4):
                scribus.messageBox('Scribus - Script Error',
                                   "This is not a textframe. Try again.",
                                   scribus.ICON_WARNING, scribus.BUTTON_OK)
                sys.exit(2)


# While we're finding out what kind of frame is selected, we'll also make sure we
# will come up with a unique name for our infobox frame - it's possible we may want
# more than one for a multicolumn frame.
        if (item[0] == ("infobox" + str(boxcount) + textbox)):
            boxcount += 1
    left, top = scribus.getPosition(textbox)
    o_width, o_height = scribus.getSize(textbox)
    o_cols = int(scribus.getColumns(textbox))
    o_gap = scribus.getColumnGap(textbox)

    columns_width = 0
    column_pos = 0
    o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols
    if (o_cols > 1):
        while (columns_width > o_cols or columns_width < 1):
            columns_width = scribus.valueDialog(
                'Width', 'How many columns width shall the ' + 'box be (max ' +
                str(o_cols) + ')?', '1')
            columns_width = int(columns_width)
        if (columns_width < o_cols):
            max = o_cols - columns_width
            while (column_pos <= max and column_pos <= 1):
                column_pos = scribus.valueDialog(
                    'Placement', 'In which column do you want '
                    'to place the box (1 to ' + str(o_cols) + ')?', '1')
            column_pos = int(column_pos) - 1
    if (o_cols == 1):
        columns_width = 1
    new_height = 0
    while (new_height <= 0):
        new_height = scribus.valueDialog(
            'Height', 'Your frame height is ' + str(o_height) + unitlabel +
            '. How tall\n do you want your ' + 'infobox to be in ' +
            unitlabel +
            '?\n If you load an image with the script, height will be\n calculated, so the value here will not\n matter in that case.',
            str(o_height))
        if (not new_height):
            sys.exit(0)
        new_height = float(new_height)
    new_top = -1
    while (new_top < 0):
        new_top = scribus.valueDialog(
            'Y-Pos',
            'The top of your infobox is currently\n' + str(top) + unitlabel +
            '. Where do you want \n' + 'the top to be in ' + unitlabel + '?',
            str(top))
        if (not new_top):
            sys.exit(0)
        new_top = float(new_top)
    framename = scribus.valueDialog(
        'Name of Frame', 'Name your frame or use this default name',
        "infobox" + str(boxcount) + textbox)
    if (not framename):
        sys.exit(0)
    frametype = 'text'
    frametype = scribus.valueDialog(
        'Frame Type',
        'Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image',
        frametype)
    if (not frametype):
        sys.exit(0)
    new_width = columns_width * o_colwidth + (columns_width - 1) * o_gap
    new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap)
    if (frametype == 'text'):
        new_textbox = scribus.createText(new_left, float(new_top), new_width,
                                         float(new_height), framename)
        scribus.setColumnGap(0, new_textbox)
        scribus.setColumns(1, new_textbox)
        scribus.textFlowMode(new_textbox, 1)
    else:
        if (frametype == 'imageL'):
            imageload = scribus.fileDialog(
                'Load image',
                'Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',
                haspreview=1)
            new_image = scribus.createImage(new_left,
                                            float(new_top), new_width,
                                            float(new_height), framename)
            scribus.textFlowMode(new_image, 1)
            scribus.loadImage(imageload, new_image)
            scribus.setScaleImageToFrame(1, 0, new_image)
            currwidth, currheight = scribus.getSize(new_image)
            Xscale, Yscale = scribus.getImageScale(new_image)
            if (Xscale != Yscale):
                scribus.sizeObject(currwidth, currheight * Xscale / Yscale,
                                   new_image)
            scribus.setScaleImageToFrame(1, 1, new_image)
        else:
            new_image = scribus.createImage(new_left,
                                            float(new_top), new_width,
                                            float(new_height), framename)
            scribus.textFlowMode(new_image, 1)
            scribus.setScaleImageToFrame(1, 1, new_image)
예제 #8
0
# 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.

import scribus as sc

if sc.haveDoc():
    nbrSelected = sc.selectionCount()

objList = []

for i in range(nbrSelected):
    objList.append(sc.getSelectedObject(i))

for i in range(nbrSelected):
    try:
        obj = objList[i]
        sc.setScaleImageToFrame(True, False, obj)
        scaleX, scaleY = sc.getImageScale(obj)
        sc.setScaleImageToFrame(False, False, obj)
        if scaleX > scaleY:
            scale = scaleX
            sc.setImageScale(scale, scale, obj)
        elif scaleY > scaleX:
            scale = scaleY
            sc.setImageScale(scale, scale, obj)
        sc.docChanged(1)
        sc.setRedraw(True)
    except Exception:
        pass
if not scribus.haveDoc():
    scribus.messageBox('Usage Error',
                       'You need a Document open',
                       icon=0,
                       button1=1)
    sys.exit(2)

# TODO: ask for the range of pages (current page if empty)

unit = scribus.getUnit()
scribus.setUnit(unit)
scribus.setUnit(scribus.UNIT_MILLIMETERS)

item = scribus.getSelectedObject()

path = scribus.getImageFile(item)
if path == '':
    scribus.messageBox('Usage Error',
                       'You need to first load an image',
                       icon=0,
                       button1=1)
    sys.exit(2)

scribus.setScaleImageToFrame(True, False, item)
scribus.setScaleImageToFrame(False, False, item)
scale = scribus.getImageScale(item)
max_scale = max(scale)
scribus.setImageScale(max_scale, max_scale, item)

scribus.setUnit(unit)
예제 #10
0
파일: InfoBox.py 프로젝트: luzpaz/scribus
def main(argv):
    unit = scribus.getUnit()
    units = [' pts','mm',' inches',' picas','cm',' ciceros']
    unitlabel = units[unit]
    if scribus.selectionCount() == 0:
        scribus.messageBox('Scribus - Script Error',
            "There is no object selected.\nPlease select a text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox('Scribus - Script Error',
            "You have more than one object selected.\nPlease select one text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    textbox = scribus.getSelectedObject()
    pageitems = scribus.getPageItems()
    boxcount = 1
    for item in pageitems:
        if (item[0] == textbox):
            if (item[1] != 4):
                scribus.messageBox('Scribus - Script Error', 
                          "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
                sys.exit(2)

# While we're finding out what kind of frame is selected, we'll also make sure we
# will come up with a unique name for our infobox frame - it's possible we may want
# more than one for a multicolumn frame.
        if (item[0] == ("infobox" + str(boxcount) + textbox)):
                boxcount += 1
    left, top = scribus.getPosition(textbox)
    o_width, o_height = scribus.getSize(textbox)
    o_cols = int(scribus.getColumns(textbox))
    o_gap = scribus.getColumnGap(textbox)
            
    columns_width = 0
    column_pos = 0
    o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols
    if (o_cols > 1):
        while (columns_width > o_cols or columns_width < 1):
            columns_width = scribus.valueDialog('Width',
                                            'How many columns width shall the '+
                                            'box be (max ' + str(o_cols) + ')?','1')
            columns_width = int(columns_width)
        if (columns_width < o_cols):
            max = o_cols - columns_width
            while (column_pos <= max and column_pos <= 1):
                column_pos = scribus.valueDialog('Placement',
                                         'In which column do you want '
                                         'to place the box (1 to ' +
                                         str(o_cols) + ')?','1')
            column_pos = int(column_pos) - 1 
    if (o_cols == 1):
	columns_width = 1
    new_height = 0
    while (new_height <= 0):
        new_height = scribus.valueDialog('Height','Your frame height is '+ str(o_height) +
                                                 unitlabel +'. How tall\n do you want your ' +
                                                 'infobox to be in '+ unitlabel +'?\n If you load an image with the script, height will be\n calculated, so the value here will not\n matter in that case.', str(o_height))
        if (not new_height) :
            sys.exit(0)
        new_height = float(new_height)
    new_top = -1
    while (new_top < 0):
        new_top = scribus.valueDialog('Y-Pos','The top of your infobox is currently\n'+ str(top) +
                                                 unitlabel +'. Where do you want \n' +
                                                 'the top to be in '+ unitlabel +'?', str(top))
        if (not new_top) :
            sys.exit(0)
        new_top = float(new_top)
    framename = scribus.valueDialog('Name of Frame','Name your frame or use this default name',"infobox" + str(boxcount) + textbox)
    if (not framename) :
        sys.exit(0)
    frametype = 'text'
    frametype = scribus.valueDialog('Frame Type','Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image',frametype)
    if (not frametype) :
        sys.exit(0)
    new_width = columns_width * o_colwidth + (columns_width-1) * o_gap
    new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap)
    if (frametype == 'text'):
        new_textbox = scribus.createText(new_left, float(new_top), new_width, float(new_height),framename)
        scribus.setColumnGap(0, new_textbox)
        scribus.setColumns(1, new_textbox)
        scribus.textFlowMode(new_textbox, 1)
    else:
        if (frametype == 'imageL'):
            imageload = scribus.fileDialog('Load image','Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',haspreview=1)
            new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename)
            scribus.textFlowMode(new_image, 1)
            scribus.loadImage(imageload, new_image)
            scribus.setScaleImageToFrame(1,0,new_image)
            currwidth, currheight = scribus.getSize(new_image)
            Xscale, Yscale = scribus.getImageScale(new_image)
            if (Xscale != Yscale):
                scribus.sizeObject(currwidth, currheight*Xscale/Yscale, new_image)
            scribus.setScaleImageToFrame(1,1,new_image)
        else:
            new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename)
            scribus.textFlowMode(new_image, 1)
            scribus.setScaleImageToFrame(1,1,new_image)
     layercount].elements[elementcount].position.x - (
         size_x / 2)
 y_pos = albumdata.pages[pagenum].layers[
     layercount].elements[elementcount].position.y - (
         size_y / 2)
 f = scribus.createImage(x_pos, y_pos, size_x, size_y)
 scribus.loadImage(
     imagedir + albumdata.pages[pagenum].layers[layercount].
     elements[elementcount].picture.id + ".JPG", f)
 scribus.setScaleImageToFrame(scaletoframe=1,
                              proportional=0,
                              name=f)
 # https://wiki.scribus.net/canvas/Fitting_an_Image_to_its_Frame
 # fitimage2frame_v2.py --> An advantage of this method is that will work regardless of the proportions of the image.
 # If you want to use this in Scribus versions >=1.5.0, you will need to change the scaleImage() command to setImageScale(), otherwise with the same parameters inside
 xscale, yscale = scribus.getImageScale(f)
 width_pi = int(albumdata.pages[pagenum].layers[layercount].
                elements[elementcount].picture.dimension.
                width)  #original image width in pixels
 height_pi = int(
     albumdata.pages[pagenum].layers[layercount].
     elements[elementcount].picture.dimension.height
 )  #original image height in pixels
 scribus.setScaleImageToFrame(scaletoframe=0,
                              proportional=1,
                              name=f)
 if (xscale > yscale):
     scale = xscale
     scribus.setImageScale(scale, scale, f)
     dpmm = width_pi / size_x  # dots per mm of the current image
     offset_x = 0