コード例 #1
0
def run():
  
  if gimp_shelf.has_key('socket_server') and gimp_shelf['socket_server']:
    gimp.message( "WARNING: '%s' is already running!" % SocketService.titleServer)
    return

  SocketService().run()
コード例 #2
0
def move_drawable_to(
        drawable,  # type: gimp.Image
        corner,  # type: Corner
        x,  # type: int
        y  # type: int
):
    # type: (...) -> None
    """Moves a corner of a drawable to the position (x, y)."""

    left, top = pdb.gimp_drawable_offsets(drawable)  # type: int, int
    width, height = pdb.gimp_drawable_mask_bounds(drawable)[
        3:]  # type: int, int
    right = left + width  # type: int
    bottom = top + height  # type: int
    dx, dy = 0, 0  # type: int
    if corner == Corner.TOP_LEFT:
        dx = x - left
        dy = y - top
    elif corner == Corner.TOP_RIGHT:
        dx = x - right
        dy = y - top
    elif corner == Corner.BOTTOM_LEFT:
        dx = x - left
        dy = y - bottom
    elif corner == Corner.BOTTOM_RIGHT:
        dx = x - right
        dy = y - bottom
    elif corner == Corner.CENTER:
        dx = x - (left + right) // 2
        dy = y - (top + bottom) // 2
    else:
        gimp.message("Invalid corner %s" % repr(corner))
        return
    pdb.gimp_layer_translate(drawable, dx, dy)
コード例 #3
0
    def checkFiles(self):

        nameMethod = self.nameClass + "::checkFiles"

        print("%s : Enter" % (nameMethod))

        if not path.isfile(self.filenameBackground):

            print("%s : The following doesn't appear to be a file : %s" %
                  (nameMethod, self.filenameBackground))

            gimp.message("Hello!!!")

            raise Exception("Plugin is about to terminate!!!")

        for filenameForeground in self.listFilenamesForeground:

            if (not path.isfile(filenameForeground)):

                print("%s : The following doesn't appear to be a file : %s" %
                      (nameMethod, filenameForeground))

                raise Exception("Plugin is about to terminate!!!")

        print("%s : Exit" % (nameMethod))
def file_load_lepton(filename, raw_filename):
    ''' Save the current layer into a PNG file, a JPEG file and a BMP file.

    Parameters:
    image : image The current image.
    layer : layer The layer of the image that is selected.
    file : string The file to open in a new layer.
    '''
    # Indicates that the process has started.
    gimp.progress_init("Opening '" + filename + "'...")

    try:
        tmpdirobj = mkdtemp()
        tmp_dirname = tmpdirobj
        jpeg_fn = os.path.join(tmp_dirname, "from_lep.jpeg")
        subprocess.check_call(["lepton", filename, jpeg_fn])
        fileImage = pdb.file_jpeg_load(jpeg_fn, filename)
        if (fileImage is None):
            gimp.message("The image could not be opened since" +
                         "it is not an image file.")
        shutil.rmtree(tmp_dirname)
        return fileImage
    except Exception as err:
        gimp.message("Unexpected error: " + str(err))
        raise err
コード例 #5
0
    def checkLists(self):

        nameMethod = self.nameClass + "::checkLists"

        print("%s : Enter" % (nameMethod))

        print("%s : Number of elements in list = %d" %
              (nameMethod, len(self.listFilenamesForeground)))

        if self.filenameBackground == None:

            gimp.message("A) You must specify a background image file.")

        elif ((len(self.listFilenamesForeground) == 0)
              or ((len(self.listFilenamesForeground) == 1) and
                  (self.listfilenamesForeground == ''))):

            gimp.message(
                "B) You must specify at least one foreground image file.")

            print("%s : Number of foreground image files = 0") % (nameMethod)

        else:

            self.checkFiles()

        print("%s : Exit" % (nameMethod))
def png(image=None):
    if not image:
        image = gimp.image_list()[0]
    prefix = pdb.gimp_image_get_filename(image)[:-4] + "_"
    gimp.progress_init("Save frames as {}_*.png".format(prefix))
    for (layer_index, layer) in enumerate(image.layers):
        try:
            filename = "{}{:02d}.png".format(prefix, int(layer.name))
        except ValueError:
            filename = "{}{}.png".format(prefix, layer.name)
        pdb.file_png_save(
            image,
            layer,
            filename,
            None,
            True,  # interlace
            9,  # compression
            True,  # bkgd
            True,  # gama
            True,  # offs
            True,  # phys
            True,  # time
        )
        gimp.progress_update(100 * (layer_index + 1) / len(image.layers))
    gimp.message("All frames saved as {}_*.png".format(prefix))
コード例 #7
0
def run(image, drawable):

    #startPyDevClient()
    if gimp_shelf.has_key('socket_server') and gimp_shelf['socket_server']:
        gimp.message("WARNING: '%s' is already running!" %
                     SocketService.titleServer)
        return

    SocketService().run(image)
コード例 #8
0
 def predict(self, *args, **kwargs):
     assert self.model_file is not None
     model_proxy = ModelProxy(self.model_file)
     try:
         return model_proxy(*args, **kwargs)
     except:
         error_info = self._format_error(traceback.format_exc())
         gimp.message(error_info)
         raise
コード例 #9
0
def exportCcodeBin(timg, tdrawable, filename, colormode):
    pr = tdrawable.get_pixel_rgn(0, 0, timg.width, timg.height, False, False)
    i = 0
    j = 0
    size = timg.width * timg.height  #image size
    if colormode == 0:
        gimp.message("12-bit mode not yet implemented")
    elif colormode == 1:
        data = []
        while (j < timg.height):
            while (i < timg.width):
                data.append(packColor(pr[i, j]))
                i += 1
            j += 1
            i = 0
        savefile = open(filename, "wb")
        for byte in data:
            savefile.write(struct.pack('H', byte))
        savefile.close()
    elif colormode == 2:
        gimp.message("18-bit mode not yet implemented")
    elif colormode == 3:
        gimp.message("24-bit mode not yet implemented")
    else:
        gimp.message("Error: No color mode selected")
コード例 #10
0
ファイル: fanim.py プロジェクト: avrj/gimp-fanim
    def destroy(self, widget):
        # if is closing and still playing try to stop and send a message with info.
        if self.is_playing:
            self.is_playing = False
            gimp.message(
                "Please do not close the image with FAnim playing the animation."
            )
        if widget != False:  # for when this function is called without valid image variable.
            # return to the normal layers order.
            pdb.script_fu_reverse_layers(self.image, None)
            self.on_goto(None, START)

        #save the settings before quit.
        Utils.save_conffile(CONF_FILENAME, self.get_settings())

        gtk.main_quit()
コード例 #11
0
def gif(image=None, suffix=None, fps=24):
    if not image:
        image = gimp.image_list()[0]
    file_path = pdb.gimp_image_get_filename(image)[:-4]
    if suffix:
        file_path += "_" + suffix.strip()
    file_path += ".gif"
    ms = int(1000.0 / fps)
    temp_image = False
    try:
        gimp.progress_init(
            "Save animated GIF @ {} fps = {} ms/frame as {}".format(
                fps, ms, file_path))
        if pdb.gimp_image_base_type(image) != 2:
            temp_image = True
            image = pdb.gimp_image_duplicate(image)
            pdb.gimp_image_convert_indexed(
                image,
                0,  # dither-type=CONVERT-DITHER-NONE
                0,  # palette-type=CONVERT-PALETTE-GENERATE
                255,  # num-cols
                False,  # alpha-dither
                False,  # remove-unused
                ""  # palette
            )
            gimp.progress_update(50)
        pdb.file_gif_save(
            image,
            image.layers[0],
            file_path,
            file_path,
            True,  # interlace
            True,  # loop
            ms,  # default-delay
            2  # default-dispose
        )
        gimp.progress_update(100)
        gimp.message("Saved animated GIF @ {} fps = {} ms/frame as {}".format(
            fps, ms, file_path))
    finally:
        if temp_image:
            pdb.gimp_image_delete(image)
コード例 #12
0
def draw_mark(
        image,  # type: gimp.Image
        directions,
        x0,  # type: int
        y0,  # type: int
        size,  # type: int
        distance  # type: int
):
    # type: (...) -> None
    """Draws a mark at position where one must cut or fold the paper."""

    x, y, width, height = 0, 0, 0, 0  # type: int, int, int, int

    for direction in directions:  # type: Direction
        if direction == Direction.UP:
            x = x0 - 1
            y = y0 - distance - size
            width = 2
            height = size
        elif direction == Direction.DOWN:
            x = x0 - 1
            y = y0 + distance
            width = 2
            height = size
        elif direction == Direction.LEFT:
            x = x0 - distance - size
            y = y0 - 1
            width = size
            height = 2
        elif direction == Direction.RIGHT:
            x = x0 + distance
            y = y0 - 1
            width = size
            height = 2
        else:
            gimp.message("Invalid direction %s" % repr(direction))
            return

        pdb.gimp_image_select_rectangle(image, gimpfu.CHANNEL_OP_REPLACE, x, y,
                                        width, height)
        pdb.gimp_edit_fill(image.active_layer, gimpfu.FOREGROUND_FILL)
        pdb.gimp_selection_none(image)
コード例 #13
0
  def run(self):
    # Socket
    try:
      self.sock.bind( ( '127.0.0.1', self.port ) )
    except socket.error as msg_socket:
      msg = "Socket Error: %s" % str( msg_socket )
      gimp.message( "%s: %s!" % ( self.titleServer, msg ) )
      self.quit()
      return
    self.sock.listen( 1 )

    gimp.message( "'%s' is running..." % self.titleServer )
    gimp_shelf['socket_server'] = True  

    self.conn, client = self.sock.accept()
    while True:
      sdata = self.conn.recv(4096)
      if not sdata:
        self.quit() # Call by client sock.close()
        break

      try:
        data = json.loads( sdata )
      except ValueError:
        continue

      if not 'function' in data:
        continue

      if data['function'] == 'add_image':
        self.pathfileImage = data['filename']
        self.paramImage.clear() 
        self.paramImage = data['paramImage']
      else:
        self.pathfileImageSelect = data['filename']

      functions = {
        'add_image':              self.add_image,
        'create_selection_image': self.create_selection_image
      }
      functions[ data['function'] ]()
コード例 #14
0
def exportCcode(timg, tdrawable, iconname, filename, colormode):
    pr = tdrawable.get_pixel_rgn(0, 0, timg.width, timg.height, False, False)
    i = 0
    j = 0
    size = timg.width * timg.height  #LCD size
    output = "/*\nC code Exported from Gimp\n\nicon size in pixels: width=" + str(
        timg.width) + ", height:" + str(timg.height) + "\n*/\n\n"
    if colormode == 0:
        gimp.message("12-bit mode not yet implemented")
    elif colormode == 1:
        output += "uint16_t " + iconname + "[" + "%(size)d" % {
            "size": size
        } + "]={\n"
        while (j < timg.height - 1):
            while (i < timg.width - 1):
                output += packColor(pr[i, j]) + ","
                i += 1
            output += packColor(pr[i, j])  #the last column, no comma
            output += ",\n"  #end of each row
            j += 1
            i = 0
        while (i < timg.width - 1):  #the last row, no comma
            output += packColor(pr[i, j]) + ","
            i += 1
        output += packColor(pr[i, j])  #the last column, no comma
        output += "\n};"
        savefile = open(filename, "w")
        savefile.write(output)
        savefile.close()
    elif colormode == 2:
        gimp.message("18-bit mode not yet implemented")
    elif colormode == 3:
        output += "typedef struct{ \nunsigned char \nr,\ng,\nb;\n}RGB;\n\nRGB " + iconname + "[" + "%(size)d" % {
            "size": size
        } + "]={\n"
        while (j < timg.height - 1):
            while (i < timg.width - 1):
                output += array2struct(pr[i, j]) + ","
                i += 1
            output += array2struct(pr[i, j])  #the last column, no comma
            output += ",\n"  #end of each row
            j += 1
            i = 0
        while (i < timg.height - 1):  #the last row, no comma
            output += array2struct(pr[i, j]) + ","
            i += 1
        output += array2struct(pr[i, j])  #the last column, no comma
        output += "\n};"
        savefile = open(filename, "w")
        savefile.write(output)
        savefile.close()
    else:
        gimp.message("Error: No color mode selected"
                     )  #will hardly happen as we now have a default colormode
コード例 #15
0
ファイル: exportC.py プロジェクト: Muriukidavid/gimp-plugins
def exportCcode(timg, tdrawable,iconname,filename,colormode):
    pr =tdrawable.get_pixel_rgn(0, 0, timg.width,timg.height, False, False);
    i=0
    j=0
    size = timg.width*timg.height #LCD size
    output = "/*\nC code Exported from Gimp\n\nicon size in pixels: width="+str(timg.width)+", height:"+str(timg.height)+"\n*/\n\n" 
    if colormode==0:
        gimp.message("12-bit mode not yet implemented")
    elif colormode==1:
        output += "uint16_t "+iconname+"[" + "%(size)d" % {"size":size} + "]={\n" 
        while (j<timg.height-1):
            while (i<timg.width-1):
                output += packColor(pr[i,j]) + ","
                i+=1
            output += packColor(pr[i,j]) #the last column, no comma
            output += ",\n" #end of each row
            j+=1
            i=0
        while (i<timg.width-1): #the last row, no comma
            output += packColor(pr[i,j]) + ","
            i+=1
        output += packColor(pr[i,j]) #the last column, no comma
        output += "\n};"
        savefile = open(filename,"w")
        savefile.write(output)
        savefile.close() 
    elif colormode==2:
        gimp.message("18-bit mode not yet implemented")
    elif colormode==3:
        output += "typedef struct{ \nunsigned char \nr,\ng,\nb;\n}RGB;\n\nRGB "+iconname+"[" + "%(size)d" % {"size":size} + "]={\n" 
        while (j<timg.height-1):
            while (i<timg.width-1):
                output += array2struct(pr[i,j]) + ","
                i+=1
            output += array2struct(pr[i,j]) #the last column, no comma
            output += ",\n" #end of each row
            j+=1
            i=0
        while (i<timg.height-1): #the last row, no comma
            output += array2struct(pr[i,j]) + ","
            i+=1
        output += array2struct(pr[i,j]) #the last column, no comma
        output += "\n};"
        savefile = open(filename,"w")
        savefile.write(output)
        savefile.close() 
    else:
        gimp.message("Error: No color mode selected")#will hardly happen as we now have a default colormode   
コード例 #16
0
    def run(self, image):
        # Socket
        try:
            self.sock.bind(('', self.port))
        except socket.error as msg_socket:
            msg = "Socket Error: %s" % str(msg_socket)
            gimp.message("%s: %s!" % (self.titleServer, msg))
            self.quit()
            return
        self.sock.listen(1)

        gimp.message("'%s' is running..." % self.titleServer)
        gimp_shelf['socket_server'] = True

        self.filename = image.filename
        vreturn = self.isTifImage()
        if not vreturn['isOk']:
            gimp.message("%s Running -- CLOSE and OPEN the TIF image!" %
                         self.titleServer)

        self.conn, client = self.sock.accept()
        while True:
            sdata = self.conn.recv(4096)
            if not sdata:
                self.quit()  # Call by client sock.close()
                break

            try:
                data = json.loads(sdata)
            except ValueError, e:
                continue

            if not data.has_key('function'):
                continue

            self.filename = data['filename']
            functions = {
                'add_image': self.add_image,
                'add_image_overwrite': self.add_image_overwrite,
                'create_selection_image': self.create_selection_image
            }
            functions[data['function']]()
コード例 #17
0
def create_wraps(
        src_image,  # type: gimp.Image
        box_width_mm,  # type: float
        box_height_mm,  # type: float
        box_depth_mm,  # type: float
        thickness_mm,  # type: float
        flap_size_mm,  # type: float
        inside_size_mm,  # type: float
        crop_mark_size_mm,  # type: float
        crop_mark_distance_mm  # type: float
):
    # type: (...) -> None
    """Creates two wrap images from a template image."""

    # Convert the dimensions from mm to px
    box_width = mm_to_px(box_width_mm)  # type: int
    box_height = mm_to_px(box_height_mm)  # type: int
    box_depth = mm_to_px(box_depth_mm)  # type: int
    thickness = mm_to_px(thickness_mm)  # type: int
    flap_size = mm_to_px(flap_size_mm)  # type: int
    inside_size = mm_to_px(inside_size_mm)  # type: int
    crop_mark_size = mm_to_px(crop_mark_size_mm)  # type: int
    crop_mark_distance = mm_to_px(crop_mark_distance_mm)  # type: int

    half_box_height = box_height // 2  # type: int
    half_box_height_plus_extra = \
        half_box_height + thickness + inside_size  # type: int

    # Coordinates in the source image
    src_xs, src_ys = template_coordinates(box_width, box_height,
                                          box_depth)  # type: int, int
    src_image_width = src_xs[-1] - src_xs[0]  # type: int
    src_image_height = src_ys[-1] - src_ys[0]  # type: int

    # Coordinates in the destination images
    dst_xs, dst_ys = wrap_coordinates(box_width, box_height, box_depth,
                                      thickness, inside_size, flap_size,
                                      crop_mark_size, crop_mark_distance)
    dst_image_width = dst_xs[-1] - dst_xs[0]  # type: int
    dst_image_height = dst_ys[-1] - dst_ys[0]  # type: int

    # Make sure we have the right dimensions
    if src_image.width != src_image_width or \
       src_image.height != src_image_height:
        gimp.message(
            "Template image has the wrong size. "
            "Expected %dpx x %dpx (%dmm x %dmm) "
            "but got %dpx x %dpx (%dmm x %dmm)." %
            (src_image_width, src_image_height, px_to_mm(src_image_width),
             px_to_mm(src_image_height), src_image.width, src_image.height,
             px_to_mm(src_image.width), px_to_mm(src_image.height)))
        return

    # Draw stuff onto both destination images in the same way
    def draw(dst_image, copy_and_rotate_definitions):
        """Copies regions from the input image to a wrap image."""

        dst_layer = gimp.Layer(dst_image, "Wrap", dst_image_width,
                               dst_image_height, gimpfu.RGB_IMAGE, 100,
                               gimpfu.NORMAL_MODE)  # type: gimp.Layer
        dst_layer.fill(gimpfu.WHITE_FILL)
        dst_image.add_layer(dst_layer, 0)

        # Add guides
        for x in dst_xs:  # type: int
            dst_image.add_vguide(x)
        for y in dst_ys:  # type: int
            dst_image.add_hguide(y)

        # Take the layers from the template and move and rotate them
        # into position
        for d in copy_and_rotate_definitions:
            pdb.gimp_progress_pulse()
            copy_and_rotate_rectangle(
                src_image,  # src_image
                d[0],  # src_x
                d[1],  # src_y
                d[2],  # src_width
                d[3],  # src_height
                dst_layer,  # dst_layer
                d[4],  # dst_x
                d[5],  # dst_y
                d[6],  # dst_corner
                d[7])  # rotation_angle

        # Copy strips from the sides to create the flaps on the front
        # and the back
        pdb.gimp_progress_pulse()
        copy_and_rotate_rectangle(dst_image, dst_xs[1], dst_ys[4],
                                  half_box_height_plus_extra, flap_size,
                                  dst_layer, dst_xs[5], dst_ys[4],
                                  Corner.BOTTOM_RIGHT, 90)

        pdb.gimp_progress_pulse()
        copy_and_rotate_rectangle(dst_image, dst_xs[1], dst_ys[6],
                                  half_box_height_plus_extra, flap_size,
                                  dst_layer, dst_xs[5], dst_ys[7],
                                  Corner.TOP_RIGHT, 270)

        pdb.gimp_progress_pulse()
        copy_and_rotate_rectangle(dst_image, dst_xs[6], dst_ys[4],
                                  half_box_height_plus_extra, flap_size,
                                  dst_layer, dst_xs[6], dst_ys[4],
                                  Corner.BOTTOM_LEFT, 270)

        pdb.gimp_progress_pulse()
        copy_and_rotate_rectangle(dst_image, dst_xs[6], dst_ys[6],
                                  half_box_height_plus_extra, flap_size,
                                  dst_layer, dst_xs[6], dst_ys[7],
                                  Corner.TOP_LEFT, 90)

        # Marks for cutting and folding
        draw_mark(dst_image, (Direction.UP, Direction.LEFT), dst_xs[4],
                  dst_ys[1], crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.UP, ), dst_xs[5], dst_ys[1],
                  crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.UP, ), dst_xs[6], dst_ys[1],
                  crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.UP, Direction.RIGHT), dst_xs[7],
                  dst_ys[1], crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.UP, Direction.LEFT), dst_xs[1],
                  dst_ys[4], crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.UP, Direction.RIGHT), dst_xs[10],
                  dst_ys[4], crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.DOWN, Direction.LEFT), dst_xs[1],
                  dst_ys[7], crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.DOWN, Direction.RIGHT), dst_xs[10],
                  dst_ys[7], crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.DOWN, Direction.LEFT), dst_xs[4],
                  dst_ys[10], crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.DOWN, ), dst_xs[5], dst_ys[10],
                  crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.DOWN, ), dst_xs[6], dst_ys[10],
                  crop_mark_size, crop_mark_distance)
        draw_mark(dst_image, (Direction.DOWN, Direction.RIGHT), dst_xs[7],
                  dst_ys[10], crop_mark_size, crop_mark_distance)

        pdb.gimp_selection_none(dst_image)

    # Define where from and where to we want to copy
    # Each line looks like this:
    # (src_x, src_y, src_width, src_height,
    #  dst_x, dst_y, dst_corner, rotation_angle)
    copy_and_rotate_definitions_top = (
        # Top
        (src_xs[1], src_ys[0], box_width, box_depth, dst_xs[5], dst_ys[4],
         Corner.TOP_LEFT, 0),
        # Left
        (src_xs[0], src_ys[1], box_depth, half_box_height_plus_extra,
         dst_xs[5], dst_ys[4], Corner.TOP_RIGHT, 90),
        # Front
        (src_xs[1], src_ys[1], box_width, half_box_height_plus_extra,
         dst_xs[5], dst_ys[7], Corner.TOP_LEFT, 0),
        # Right
        (src_xs[2], src_ys[1], box_depth, half_box_height_plus_extra,
         dst_xs[6], dst_ys[4], Corner.TOP_LEFT, 270),
        # Back
        (src_xs[3], src_ys[1], box_width, half_box_height_plus_extra,
         dst_xs[5], dst_ys[4], Corner.BOTTOM_LEFT, 180),
    )

    copy_and_rotate_definitions_bottom = (
        # Left
        (src_xs[0], src_ys[3] - half_box_height_plus_extra, box_depth,
         half_box_height_plus_extra, dst_xs[5], dst_ys[4], Corner.TOP_RIGHT,
         270),
        # Front
        (src_xs[1], src_ys[3] - half_box_height_plus_extra, box_width,
         half_box_height_plus_extra, dst_xs[5], dst_ys[1], Corner.TOP_LEFT, 0),
        # Right
        (src_xs[2], src_ys[3] - half_box_height_plus_extra, box_depth,
         half_box_height_plus_extra, dst_xs[6], dst_ys[4], Corner.TOP_LEFT, 90
         ),
        # Back
        (src_xs[3], src_ys[3] - half_box_height_plus_extra, box_width,
         half_box_height_plus_extra, dst_xs[5], dst_ys[10], Corner.BOTTOM_LEFT,
         180),
        # Bottom
        (src_xs[1], src_ys[3], box_width, box_depth, dst_xs[5], dst_ys[4],
         Corner.TOP_LEFT, 0),
    )

    with DefaultContext():
        dst_image_top = gimp.Image(dst_image_width, dst_image_height,
                                   gimpfu.RGB)  # type: gimp.Image
        with PausedUndo(dst_image_top):
            draw(dst_image_top, copy_and_rotate_definitions_top)
            gimp.Display(dst_image_top)

        dst_image_bottom = gimp.Image(dst_image_width, dst_image_height,
                                      gimpfu.RGB)  # type: gimp.Image
        with PausedUndo(dst_image_bottom):
            draw(dst_image_bottom, copy_and_rotate_definitions_bottom)
            gimp.Display(dst_image_bottom)
    gimp.displays_flush()
コード例 #18
0
def \
superimpose_image_over_another_noninteractive(

        # image,
        # drawable,
        list_filenames,
        list_filenames_superimpose
    # horizontalLocation,
    # verticalLocation
) :

    nameFunction = "superimpose_image_over_another_interactive"

    print("----------------------------------------")
    print("%s : Enter" % (nameFunction))

    IFS = ";"

    # listFiles = fileContents.split(IFS)

    listFiles = list_filenames.split(IFS)
    listFiles_superimpose = list_filenames_superimpose.split(IFS)

    print("%s : Number of elements in list = %d" %
          (nameFunction, len(listFiles)))
    print("%s : File list = %s" % (nameFunction, listFiles))

    print("%s : Number of elements in list = %d" %
          (nameFunction, len(listFiles_superimpose)))
    print("%s : File list = %s" % (nameFunction, listFiles_superimpose))

    if (len(listFiles) == 0):

        print("%s : Number of background image files = 0 : a") % (nameFunction)

        # errdialog = gtk.MessageDialog(
        #                               None,
        #                               0,
        #                               gtk.MESSAGE_ERROR,
        #                               gtk.BUTTONS_OK,
        #                               "A) You must specify at least one background image file."
        #                              )
        # errdialog.show_all()
        # errdialog.run()

        # raise Exception("You must specify at least one background image file.")

    elif (len(listFiles_superimpose) == 0):

        gimp.message(
            "B) You must specify at least one superimpose image file.")
        print("%s : Number of superimpose image files = 0 : a") % (
            nameFunction)
        # raise Exception("You must specify at least one superimpose image file.")

    # elif (len(listFiles) == 1) : and
    elif (listFiles[0] == ''):

        gimp.message("C) You must specify at least one background image file.")
        print("%s : Number of background image files = 0 : b") % (nameFunction)
        # raise Exception("You must specify at least one background image file.")

    # elif (len(listFiles_superimpose) == 1) and
    elif (listFiles_superimpose[0] == ''):

        gimp.message(
            "D) You must specify at least one superimpose image file.")
        print("%s : Number of superimpose image files = 0 : b") % (
            nameFunction)
        # raise Exception("You must specify at least one superimpose image file.")

    elif len(listFiles) != len(listFiles_superimpose):

        gimp.message(
            "E) The number of files specified must be the same for both background and superimpose images."
        )
        print(
            "%s : The number of files specified must be the same for both background and superimpose images!"
        ) % (nameFunction)
        # raise Exception("The number of files specified must be the same for both background and superimpose images!")

    indexList = 0

    for filename in listFiles:

        indexList = indexList + 1

        print("%s : ========================================" % (nameFunction))
        print("%s : Filename = %s" % (nameFunction, filename))
        print("%s : ========================================" % (nameFunction))

        if (not path.isfile(filename)):

            print("%s :    > is NOT a file" % (nameFunction))

            continue

        filename_superimpose = listFiles_superimpose[indexList - 1]

        print("%s : ========================================" % (nameFunction))
        print("%s : Filename of image to superimpose = %s" %
              (nameFunction, filename_superimpose))
        print("%s : ========================================" % (nameFunction))

        if (not path.isfile(filename_superimpose)):

            print("%s :    > is NOT a file" % (nameFunction))

        gimp.progress_init("Superimposing one image over the other")

        image = pdb.gimp_file_load(filename, filename)
        drawable = pdb.gimp_image_get_active_layer(image)

        # Start a GIMP Undo group, as this will allow the actions of this Plugin to be undone in one step.

        pdb.gimp_undo_push_group_start(image)

        widthImage = image.width
        heightImage = image.height

        widthDrawable = drawable.width
        heightDrawable = drawable.height

        print("Width image             = %s" % widthImage)
        print("Height image            = %s" % heightImage)
        print("Width drawable          = %s" % widthDrawable)
        print("Height drawable         = %s" % heightDrawable)
        # print("Horizontal location     = %s" % horizontalLocation)
        # print("Vertical location       = %s" % verticalLocation)
        print("Image filename          = %s" % image.filename)

        # Open the image file to be superimposed and get its drawable object.

        image_super = pdb.gimp_file_load(filename_superimpose,
                                         filename_superimpose)
        drawable_super = pdb.gimp_image_get_active_layer(image_super)

        print("Width super image             = %s" % image_super.width)
        print("Height super image            = %s" % image_super.height)
        print("Width super drawable          = %s" % drawable_super.width)
        print("Height super drawable         = %s" % drawable_super.height)

        # How many layers does the current image now contain?
        #
        # Use gimp-edit-copy and gimp-edit-paste?

        copy_result = pdb.gimp_edit_copy(drawable_super)

        if (copy_result == True):

            print("True")

        else:

            print("False")

        print("Selection copy result = %s" % copy_result)

        # pdb.gimp_drawable_update(drawable, horizontalLocation, verticalLocation, 384, 216)

        # The following operation should paste the image which is in the buffer, into a new layer of the
        # original image.

        pdb.gimp_edit_paste(drawable, True)

        widthImage = image.width
        heightImage = image.height

        widthDrawable = drawable.width
        heightDrawable = drawable.height

        print("Width image             = %s" % widthImage)
        print("Height image            = %s" % heightImage)
        print("Width drawable          = %s" % widthDrawable)
        print("Height drawable         = %s" % heightDrawable)
        # print("Horizontal location     = %s" % horizontalLocation)
        # print("Vertical location       = %s" % verticalLocation)

        # Move the

        # pdb.gimp_drawable_update()

        drawable_new = pdb.gimp_image_flatten(image)

        pdb.gimp_file_save(image, drawable_new, filename, filename)

        # End the GIMP Undo group.

        pdb.gimp_undo_push_group_end(image)

        # Close the image now that we have finished with it, otherwise it will use up memory unnecessarily.

        pdb.gimp_image_delete(image)

    # End of for loop.

    print("%s : Exit" % (nameFunction))
コード例 #19
0
def plugin_hello():
    gimp.message("Hello, GIMP world!\n")
コード例 #20
0
 def quit(self):
   gimp.message( "%s: Stopped!" % self.titleServer)
   gimp_shelf['socket_server'] = False
   self.conn = None
コード例 #21
0
#!/usr/bin/python

import traceback
from gimpfu import pdb, gimp
import gimpfu as gfu

infile = "test.jpg"
outfile = "out.png"
try:
    image = pdb.gimp_file_load(infile, infile, run_mode=gfu.RUN_NONINTERACTIVE)
    # w = 200
    # h = round(w * image.height / float(image.width))
    # pdb.gimp_image_scale(image, w, h)
    pdb.python_fu_super_resolution(image, image.active_layer)
    image.flatten()
    pdb.gimp_file_save(image, image.active_layer, outfile, outfile, run_mode=gfu.RUN_NONINTERACTIVE)
except:
    gimp.message("ERROR:\n" + traceback.format_exc())
pdb.gimp_quit(1)
コード例 #22
0
 def printMessage(message):
     pdb.gimp_progress_end()
     gimp.message(message)
コード例 #23
0
 def quit(self):
     gimp.message("%s: Stopped!" % self.titleServer)
     gimp_shelf['socket_server'] = False
     self.conn = None
コード例 #24
0
def sheet(image=None, cols=0):
    if not image:
        image = gimp.image_list()[0]
    if not cols:
        best = (1, 10000000)
        for cols in range(1, len(image.layers) + 1):
            rows = (len(image.layers) + (cols - 1)) // cols
            (sheet_width, sheet_height) = (cols * image.width,
                                           rows * image.height)
            sheet_aspect_ratio = sheet_width / sheet_height if sheet_width > sheet_height else sheet_height / sheet_width
            if sheet_aspect_ratio < best[1]:
                best = (cols, sheet_aspect_ratio)
        cols = best[0]
    file_path = "{}_sheet_{}_frames_{}_columns_{}x{}.png".format(
        pdb.gimp_image_get_filename(image)[:-4], len(image.layers), cols,
        image.width, image.height)
    gimp.progress_init("Save sheet as {}".format(file_path))
    rows = (len(image.layers) + (cols - 1)) // cols
    sheet = pdb.gimp_image_new(image.width * cols, image.height * rows, 0)
    try:
        sheet_layer = pdb.gimp_layer_new(
            sheet,
            sheet.width,
            sheet.height,
            1,  # type = RGBA-IMAGE
            "sprite sheet",
            100,  # opacity = 100 %
            0  # mode = LAYER-MODE-NORMAL-LEGACY
        )
        pdb.gimp_image_insert_layer(sheet, sheet_layer, None, 0)

        (row, col) = (0, 0)
        for (layer_index, layer) in enumerate(image.layers):
            pdb.gimp_selection_none(image)
            pdb.gimp_layer_resize_to_image_size(layer)
            pdb.gimp_edit_copy(layer)
            floating = pdb.gimp_edit_paste(sheet_layer, True)
            (left, top) = floating.offsets
            pdb.gimp_layer_translate(floating, col * image.width - left,
                                     row * image.height - top)
            pdb.gimp_floating_sel_anchor(floating)
            col += 1
            if col >= cols:
                col = 0
                row += 1
            gimp.progress_update(100 * (layer_index + 1) / len(image.layers))
        pdb.file_png_save(
            sheet,
            sheet_layer,
            file_path,
            None,
            True,  # interlace
            9,  # compression
            True,  # bkgd
            True,  # gama
            True,  # offs
            True,  # phys
            True,  # time
        )
        gimp.message("All frames saved as {}".format(file_path))
    finally:
        pdb.gimp_image_delete(sheet)
コード例 #25
0
def hello_world():
    gimp.message("Hello, GIMP world!\n")