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()
Exemplo n.º 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()
Exemplo n.º 3
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))
Exemplo n.º 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')
Exemplo n.º 5
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)
 # 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
     offset_y = -(
         height_pi / dpmm - size_y
     ) / 2 / scribus.mm  # scribus.mm --> scribus constant: millimetres in 1 pt
     if albumdata.pages[pagenum].layers[layercount].elements[
             elementcount].contentRotation > 0.1:  # I don't know why sometimes it mixes dimensions width and height
         offset_y = -(
             width_pi / dpmm - size_x
         ) / 2 / scribus.mm  # scribus.mm --> scribus constant: millimetres in 1 pt
 else:
     scale = yscale
     scribus.setImageScale(scale, scale, f)
     dpmm = height_pi / size_y  # dots per mm of the current image
     offset_x = -(
Exemplo n.º 8
0
def frontPage(LogoPath, ChurchPath, ChurchImage, Citation, CitationLocation):
    #scribus.setText('Gemeindebrief   DIGITAL Buxtehude',"Oben")

    #Line upper left corner
    l_line = scribus.createLine(10,10,10,33,"l_Line")
    scribus.setLineWidth(0.75, l_line)
    scribus.setLineColor("NAK-blau 100%", l_line)
    scribus.setLineShade("NAK-blau 100%", l_line)

    #Headline
    t_headline = scribus.createText(10,22,128,20,"t_Headline")
    scribus.setText("Gemeindebrief", t_headline)
    scribus.selectText(1, 100, t_headline)
    scribus.setCharacterStyle(
        "Erste Seite - Gemeindebrief - gross", t_headline)
    scribus.deselectAll()
    # Digital - Text
    t_digitalText = scribus.createText(107,27,30,7, "t_Digital")
    scribus.selectText(1, 100, t_digitalText)
    scribus.setCharacterStyle(
        "Erste Seite - Gemeindebrief - gross", t_digitalText)
    scribus.deselectAll()
    # Congregation - Text
    t_congregationText = scribus.createText(10,35.250, 70, 6, "t_Congregation")
    scribus.selectText(1, 100, t_congregationText)
    scribus.setCharacterStyle(
        "Erste Seite - Gemeindebrief - klein", t_congregationText)
    scribus.deselectAll()

    # Month Year
    t_monthYear = scribus.createText(56, 46.500, 82, 10, "t_MonthYear")
    scribus.selectText(1, 100, t_monthYear)
    scribus.setCharacterStyle(
        "Erste Seite - Gemeindebrief - Monat", t_monthYear)
    scribus.deselectAll()

    # Logo charitable
    i_charitable = scribus.createImage(10, 46, 35.5, 9, "i_NAC_charitable")
    scribus.loadImage(LogoPath + "Logo_NAK_karitativ_HQ.tiff", i_charitable)
    scribus.setImageScale(0.0613, 0.0613, i_charitable)
    
    # Church image
    i_churchImage = scribus.createImage(10,57,128,100,"i_Church")
    scribus.loadImage(ChurchPath + ChurchImage, i_churchImage)
    scribus.setImageScale(1, 1, i_churchImage)
    scribus.setImageOffset(-18.244, -0.342, i_churchImage)
    
    # Citation
    t_citation = scribus.createText(42.500, 162.500,95.500,4.500, "t_Citation")
    # OverflowCheck
    scribus.setText(Citation, t_citation)
    scribus.selectText(1, 100, t_citation)
    scribus.setCharacterStyle("Erste Seite - Bibelzitat - Text", t_citation)
    scribus.deselectAll()
    # Citation Location
    t_citationLocation = scribus.createText(42.500, 170, 95.500, 3, "t_CitationLocation")
    scribus.setText(CitationLocation, t_citationLocation)
    scribus.selectText(1, 100, t_citationLocation)
    scribus.setCharacterStyle(
        "Erste Seite - Bibelzitat - Ort", t_citationLocation)
    scribus.deselectAll()

    # NAC
    t_nac = scribus.createText(52.500,195,66,5,"t_NAC")
    scribus.setText("Neuapostolische Kirche", t_nac)
    scribus.selectText(1, 100, t_nac)
    scribus.setCharacterStyle("Erste Seite - NAK", t_nac)
    scribus.deselectAll()
    # North and east germany
    t_northEastGermany = scribus.createText(52.500, 195, 66, 5, "t_NorthEastGermany")
    scribus.setText("Nord- und Ostdeutschland", t_northEastGermany)
    scribus.selectText(1, 100, t_northEastGermany)
    scribus.setCharacterStyle(
        "Erste Seite - Nord- und Ostdeutschland", t_northEastGermany)
    scribus.deselectAll()

    # NAC Logo
    i_nacLogo = scribus.createImage(122, 184, 16, 16,"i_Logo")
    scribus.loadImage("L:\\GB\\Bilder\\Logos\\Logo_NAK_HQ.tif", i_nacLogo)
    scribus.setImageScale(0.0384, 0.0384, i_nacLogo)

    scribus.saveDocAs()