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()
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()
def replace(self, image_frame): """ replace the image. If frame has the same size, keep scale and offset else fall and center """ self.path = image_frame.path sc.loadImage(self.path, self.name) if self.width == image_frame.width and self.height == image_frame.height: self.scale_x = image_frame.scale_x self.scale_y = image_frame.scale_y sc.scaleImage(self.scale_x, self.scale_y, self.name) self.offset_x = image_frame.offset_x self.offset_y = image_frame.offset_y sc.setImageOffset(self.scale_x, self.scale_y, self.name) else: x, y = scale_to_frame(self.name) center_image(self.name, x, y)
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)
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')
) / 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 = -( width_pi / dpmm - size_x ) / 2 / scribus.mm # scribus.mm --> scribus constant: millimetres in 1 pt offset_y = 0 if albumdata.pages[pagenum].layers[layercount].elements[ elementcount].contentRotation > 0.1: # I don't know why sometimes it mixes dimensions width and height offset_x = -( height_pi / dpmm - size_y ) / 2 / scribus.mm # scribus.mm --> scribus constant: millimetres in 1 pt scribus.setImageOffset( offset_x, offset_y, f) # offset comes in scribus units pts #If there is cropping, the image is "shifted" within the image frame, by a certain scale in points. if albumdata.pages[pagenum].layers[layercount].elements[ elementcount].cropping: #Apply zoom and recenter zoom_x = float( albumdata.pages[pagenum].layers[layercount]. elements[elementcount].cropping.width) zoom_y = float( albumdata.pages[pagenum].layers[layercount]. elements[elementcount].cropping.height) if (zoom_x > zoom_y): scale = scale / zoom_x dpmm = dpmm * zoom_x elif (zoom_y > zoom_x):
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()