def displayDiagnostics_pre(self) : nameMethod = self.nameClass + "::displayDiagnostics_pre" print("%s : Enter" % (nameMethod)) layerList = pdb.gimp_image_get_layers(image) print("%s Number of layers in image = %d" % (nameMethod, len(layerList))) if pdb.gimp_drawable_is_layer(drawable) : print("Drawable is a layer") else : print("Drawable is NOT a layer") activeLayer = pdb.gimp_image_get_active_layer(image) print("Desired horizontal resolution of image = %s" % horizontalResolution) print("Desired vertical resolution of image = %s" % verticalResolution) print("Current width of image = %s" % self.widthImage_original) print("Current height of image = %s" % self.heightImage_original) print("%s : Exit" % (nameMethod))
def caches(inImg, inNameLayerFleche, inNameLayerFond): path_cadenas = GRAPH_PATH + "images/cadenas.png" imagecadenas = pdb.gimp_file_load(path_cadenas, path_cadenas) layercadenas = pdb.gimp_image_get_active_layer(imagecadenas) pdb.gimp_selection_all(imagecadenas) pdb.gimp_edit_copy(layercadenas) pdb.gimp_image_delete(imagecadenas) layerfond = pdb.gimp_image_get_layer_by_name(inImg, inNameLayerFond) layerfleche = pdb.gimp_image_get_layer_by_name(inImg, inNameLayerFleche) _, alayers = pdb.gimp_image_get_layers(inImg) for layercurrent in alayers: pdb.gimp_selection_none(inImg) layercurrent = gimp.Item.from_id(layercurrent) pdb.script_fu_add_bevel(inImg, layercurrent, 5, 0, 0) pdb.gimp_item_set_visible(layercurrent, False) layername = pdb.gimp_item_get_name(layercurrent) if not (layername == inNameLayerFleche or layername == inNameLayerFond): cree_background(layercurrent, layerfond, inImg) cache = pdb.gimp_image_merge_visible_layers(inImg, CLIP_TO_IMAGE) pdb.script_fu_add_bevel(inImg, cache, 5, 0, 0) pdb.gimp_item_set_name(cache, "cache.png") pdb.gimp_image_lower_item_to_bottom(inImg, layerfleche) pdb.gimp_image_lower_item_to_bottom(inImg, cache) pdb.gimp_image_lower_item_to_bottom(inImg, layerfond)
def change_num(image, inNumero): layer = pdb.gimp_image_get_active_layer(image) pdb.gimp_context_set_sample_transparent(True) pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE,layer, 1, 1) pdb.gimp_selection_invert(image) _, x, y, x2, y2 = pdb.gimp_selection_bounds(image) xthird=x + ((x2 - x) // 4 * 3) y = _find_black_not_transparent(image, layer, xthird, y) pdb.gimp_context_set_sample_transparent(False) pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE, layer, xthird, y) pdb.gimp_edit_clear(layer) if inNumero > 1: _, x, y, x2, y2 = pdb.gimp_selection_bounds(image) ymiddle = y + ( (y2 - y) // 2) keep = True while keep: if not _is_transparent(image, layer, x, ymiddle): keep = False pdb.gimp_context_set_sample_transparent(False) pdb.gimp_context_set_sample_threshold(1) pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE, layer, x+1, ymiddle) pdb.gimp_context_set_sample_threshold(0.1) x += 1 pdb.gimp_edit_clear(layer) _, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image) pdb.gimp_image_select_rectangle(image, CHANNEL_OP_REPLACE, x1, y1, x2-x1, y2-y1) filename = GRAPH_PATH + str(inNumero) + ".png" imagechiffre = pdb.gimp_file_load(filename, filename) layerchiffre = pdb.gimp_image_get_active_layer(imagechiffre) pdb.gimp_selection_all(imagechiffre) pdb.gimp_edit_copy(layerchiffre) pdb.gimp_image_delete(imagechiffre) floating_sel = pdb.gimp_edit_paste(layer,False) pdb.gimp_floating_sel_anchor(floating_sel)
def set_layer_opacity(self, opacity): print "Setting layer opacity to {}".format(opacity) try: image = gimp.image_list()[0] layer = pdb.gimp_image_get_active_layer(image) value = opacity / float(9.0) if value > 100.0: layer.opacity = 100.0 else: layer.opacity = value except: print "ERROR"
def rotate(layer, angle): """ rotate a layer """ pdb.gimp_edit_copy(layer) tmp_image = pdb.gimp_edit_paste_as_new() tmp_layer = pdb.gimp_image_get_active_layer(tmp_image) pdb.gimp_item_transform_rotate(tmp_layer, angle, False, tmp_layer.width / 2, tmp_layer.height / 2) print(tmp_layer.width, tmp_layer.height) pdb.gimp_image_resize(tmp_image, tmp_layer.width, tmp_layer.height, 0, 0) pdb.gimp_layer_set_offsets(tmp_layer, 0, 0) pdb.gimp_display_new(tmp_image) pdb.gimp_displays_flush()
def flip(file): fileabs = os.path.abspath(file) print(fileabs) file_dir, filename = os.path.split(fileabs) filename = filename.lower().replace('.png', '_mini.jpg') file_new = os.path.join(file_dir, filename) image = pdb.gimp_file_load(file, file) drawable = pdb.gimp_image_get_active_layer(image) #pdb.gimp_image_flip(image, ORIENTATION_HORIZONTAL) #pdb.gimp_file_save(image, drawable, file_new, file_new) pdb.file_jpeg_save(image, drawable, file_new, file_new, 0.8, 0, 1, 1, '', 0, 1, 0, 0) pdb.gimp_image_delete(image)
def __getForegroundImageAndDrawable(self, filename_foreground): """ Use GIMP to get the image and drawable objects from the forground image. Parameters: filename_forground (String) : The filename of the forground image file. Returns: NA Invoked by : OverlayImageAgent.runMultipleFromList Invokes : NA """ nameProcedure = "OverlayImageAgent::__getImageAndDrawable" print("%s : Enter" % (nameProcedure)) # Get the following from both the foreground image file; # # - image # - drawable # # and save them into the appropriate global variables. self.image_foreground = pdb.gimp_file_load(filename_foreground, filename_foreground) self.drawable_foreground = pdb.gimp_image_get_active_layer( self.image_foreground) print("Filename foreground image = %s" % self.image_foreground.filename) gimp.progress_init( "Have got image and drawable from Foreground Image file") print("%s : Exit" % (nameProcedure))
def displayDiagnostics_post(self) : nameMethod = self.nameClass + "::displayDiagnostics_post" print("%s : Enter" % (nameMethod)) layerActive = pdb.gimp_image_get_active_layer(image) print layerActive [numLayers, listLayers] = pdb.gimp_image_get_layers(image) print("Number of layers in the image = %d" % numLayers) print("Layer ID = %d" % listLayers[0]) layerActive.set_offsets(offset_x, offset_y) widthImage = image.width heightImage = image.height print("Image width = %s" % widthImage) print("Image height = %s" % heightImage) print("Drawable width = %s" % pdb.gimp_drawable_width(drawable)) print("Drawable height = %s" % pdb.gimp_drawable_height(drawable)) if (resizeAmountVertical > resizeAmountHorizontal) : resizeAmount = resizeAmountHorizontal print("resizeAmountVertical > resizeAmountHorizontal") print("x difference = %d" % (widthImage_original - widthImage)) print("y difference = %d" % (heightImage_original - heightImage)) else : resizeAmount = resizeAmountVertical print("resizeAmountVertical <= resizeAmountHorizontal") print("x difference = %d" % (widthImage_original - widthImage)) print("y difference = %d" % (heightImage_original - heightImage)) print("%s : Exit" % (nameMethod))
def plugin_main(file): """ Main plugin method """ image = pdb.gimp_file_load(file, file) drawable = pdb.gimp_image_get_active_layer(image) fileabs = os.path.abspath(file) #gprint('=== Input ==== ' + fileabs) file_dir, filename = os.path.split(fileabs) filename = filename[:-4] + '.jpg' file_new = os.path.join(OUTPUT_PATH, filename) pdb.file_jpeg_save(image, drawable, file_new, file_new, QUALITY, 0, 1, 1, '', 0, 1, 0, 0) pdb.gimp_image_delete(image) gprint('=== Output === ' + file_new)
def effet_texte(inColor, inImg): layer = pdb.gimp_image_get_active_layer(inImg) pdb.gimp_context_set_sample_transparent(True) pdb.gimp_image_select_contiguous_color(inImg, CHANNEL_OP_REPLACE, layer, 1, 1) pdb.gimp_selection_invert(inImg) _, x, _, x2, y2 = pdb.gimp_selection_bounds(inImg) xmiddle = x + (x2 - x) // 2 y = y2 - 1 keep = True while keep: if y < 0: print("Error in effet_texte for img {} : y < 0 !".format(inImg)) return if (not _is_transparent(inImg, layer, xmiddle, y)) and _is_black(inImg, layer, xmiddle, y): keep = False pdb.gimp_context_set_sample_transparent(False) pdb.gimp_image_select_contiguous_color(inImg, CHANNEL_OP_REPLACE, layer, xmiddle, y) pdb.gimp_edit_clear(layer) y -= 1 _, x1, y1, x2, y2 = pdb.gimp_selection_bounds(inImg) newlayer = pdb.gimp_layer_copy(layer, True) pdb.gimp_image_select_rectangle(inImg, CHANNEL_OP_REPLACE, x1, y1, x2-x1, y2-y1) pdb.gimp_context_set_sample_transparent(True) pdb.gimp_image_select_contiguous_color(inImg, CHANNEL_OP_SUBTRACT, layer, x1, y1) pdb.gimp_edit_clear(layer) pdb.gimp_selection_invert(inImg) pdb.gimp_image_insert_layer(inImg, newlayer, None, 0) pdb.gimp_edit_clear(newlayer) pdb.script_fu_layerfx_outer_glow(inImg, newlayer, inColor, 75, 0, 0, 0, 0, 5, 0, 1) pdb.gimp_image_merge_visible_layers(inImg, CLIP_TO_IMAGE) pdb.gimp_selection_none(inImg) pdb.gimp_displays_flush()
def createTechIcons(timg, tdrawable,file,folder, outFolder,scaleTo): for fileName in os.listdir(folder): # backGroundImage=pdb.gimp_file_load(file, file) # backGroundLayer=backGroundImage.layers[0] if fileName[-4:]!=".dds": continue outFile=outFolder+"/"+"tech_"+fileName image=pdb.gimp_file_load(folder+"/"+fileName, folder+"/"+fileName) pdb.gimp_image_scale(image,scaleTo,scaleTo) pdb.gimp_image_resize(image,52,52,-1,-1) for layer in image.layers: pdb.gimp_layer_resize_to_image_size(layer) # layer_group = pdb.gimp_layer_group_new(image) layer_group=pdb.gimp_item_get_parent(image.layers[0]) layer=pdb.gimp_file_load_layer(image, file) pdb.gimp_image_insert_layer(image,layer,layer_group,1)#(image, layer, parent, position) for layer in image.layers: pdb.gimp_item_set_visible(layer,True) layer = pdb.gimp_image_merge_visible_layers(image, 0) pdb.gimp_image_set_active_layer(image, layer) drawable = pdb.gimp_image_get_active_layer(image) # with open("E:/out.txt",'w') as outTxt: # outTxt.write(outFile) pdb.file_dds_save(image, drawable, outFile,outFile,0,0,0,0,0,0,0)
def layerToDDS(timg, tdrawable, file, argumentFile, outFolder, byName, scaleBool, scaleTo): #, argumentFile,hmm,blub): # num_layers, layer_ids = pdb.gimp_image_get_layers(image) # with open("E:/out.txt",'w') as outTxt: # outTxt.write(str(os.getcwd())) outFolder = os.path.dirname(file) + "/" + outFolder if not os.path.exists(outFolder): os.makedirs(outFolder) if argumentFile.lower() == "all": image = pdb.gimp_file_load(file, file) fileContent = [] for layer in image.layers: layername = pdb.gimp_item_get_name(layer) fileContent.append(layername + " " + layername) byName = True else: with open(argumentFile, 'r') as argfile: fileContent = [line for line in argfile] for l in fileContent: image = pdb.gimp_file_load(file, file) if scaleBool: if scaleTo: pdb.gimp_image_resize(image, 52, 52, -26, -26) else: pdb.gimp_image_scale(image, 52, 52) line = shlex.split(l) outFile = outFolder + "/" + line[0] if outFile[-4:] != ".dds": outFile += ".dds" for layer in image.layers: # layer = pdb.gimp_image_get_layer_by_name(image, id) pdb.gimp_item_set_visible(layer, False) layers = [] for i, word in enumerate(line[1:]): if byName: if word[:4] == "MOVE": word2 = word[5:] layer = pdb.gimp_image_get_layer_by_name(image, word2) # pdb.gimp_item_set_visible(layer,True) pdb.gimp_layer_scale(layer, 40, 40, False) pdb.gimp_image_set_active_layer(image, layer) drawable = pdb.gimp_image_get_active_layer(image) if word[4] == "L": pdb.script_fu_move_layer_to(image, drawable, -2.5, 5) elif word[4] == "R": pdb.script_fu_move_layer_to(image, drawable, 17.5, 5) line[1 + i] = line[1 + i][5:] # pdb.gimp_item_set_visible(layer,False) for word in line[1:]: #outTxt.write(word+"\n") #layers.append(pdb.gimp_layer_copy(image.layers[int(word)],False)) #pdb.gimp_image_insert_layer(image, layer,image.layers[int(word)], 0) try: if byName: pdb.gimp_item_set_visible( pdb.gimp_image_get_layer_by_name(image, word), True) else: pdb.gimp_item_set_visible(image.layers[int(word)], True) except: pdb.gimp_message("Error parsing line " + " ".join(line) + ". Probably a missing/invalid item") raise if scaleBool and scaleTo: for word in line[2:]: if byName: layer = pdb.gimp_image_get_layer_by_name(image, word) else: layer = image.layers[int(word)] pdb.gimp_layer_scale(layer, scaleTo, scaleTo, False) pdb.gimp_layer_resize(layer, 52, 52, -1, -1) # for layer in layers: # outTxt.write("{!s}".format(layer)) # pdb.gimp_item_set_visible(layer, True) #pdb.gimp_item_set_visible(image.layers[3], True) #pdb.gimp_item_set_visible(image.layers[5], True) layer = pdb.gimp_image_merge_visible_layers(image, 0) pdb.gimp_image_set_active_layer(image, layer) drawable = pdb.gimp_image_get_active_layer(image) for layerIt in image.layers: if layerIt != layer or not scaleTo: pdb.gimp_layer_resize_to_image_size(layerIt) try: pdb.file_dds_save(image, drawable, outFile, outFile, 0, 0, 0, 0, 0, 0, 0) except: pdb.file_dds_save(image, drawable, outFile, outFile, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
def runMultipleFromList(self, filenames_foreground, seperator_character): """ Copy and paste the foreground image onto the background image, flatten the background image down into one layer, and then save the result to file. Parameters: NA Returns: NA Invoked by : runPlugin_multiple_fromList OverlayImageAgent.runMultipleFromFile Invokes : OverlayImageAgent.__getForegroundImageAndDrawable OverlayImageAgent.__displayDiagnosticData OverlayImageAgent.__run """ nameProcedure = "OverlayImageAgent::runMultipleFromList" print("%s : Enter" % (nameProcedure)) print("%s : filenames_foreground = %s" % (nameProcedure, filenames_foreground)) print("%s : seperator_character = %s" % (nameProcedure, seperator_character)) # Ascertain how many Foreground Images were passed to this Plugin. self.filenames_foreground = filenames_foreground.split( seperator_character) print("%s : Number of Foreground filenames = %d" % (nameProcedure, len(self.filenames_foreground))) gimp.progress_init( "Have got image and drawable from Background Image file") # Start a GIMP Undo group. # # This will allow the actions of this Plugin to be undone in one step. # pdb.gimp_image_undo_group_start(self.image_background) for filename_foreground in self.filenames_foreground: print("%s : filename_foreground = %s" % (nameProcedure, filename_foreground)) if path.isfile(filename_foreground): self.filename_foreground = filename_foreground print("%s : Filename Foreground image = %s" % (nameProcedure, self.filename_foreground)) print("%s : Length of filename = %d chars" % (nameProcedure, len(self.filename_foreground))) self.filename_result = self.__constructFilenameResult( self.filename_foreground) self.image_background = pdb.gimp_file_load( self.filename_background, self.filename_background) self.drawable_background = pdb.gimp_image_get_active_layer( self.image_background) print("%s : Filename background image = %s" % (nameProcedure, self.image_background.filename)) self.__getForegroundImageAndDrawable(self.filename_foreground) message = "<span foreground=\"black\" style=\"italic\">" + nameProcedure + " : Processing next Foreground Image</span>" self.__displayDiagnosticData(message) self.__run() # Close the GIMP Images now that we have finished with them, otherwise they will use up # memory unnecessarily. pdb.gimp_image_delete(self.image_foreground) pdb.gimp_image_delete(self.image_background) else: print("%s : Filename Foreground image DOESN'T exist = %s" % (nameProcedure, self.filename_foreground)) # ---------------------------------------------------------------------------------------------- # End the GIMP Undo group which was started at the beginning of this Plugin. # ---------------------------------------------------------------------------------------------- # pdb.gimp_image_undo_group_end(self.image_background) print("%s : Exit" % (nameProcedure))
def \ scale_and_set_size_file_noninteractive( horizontalResolution, verticalResolution, interpolationMode, # 0,1,2,3 : 3 = INTERPOLATION_LANCZOS listFiles ) : nameFunction = "scale_and_set_size_noninteractive" print("%s : Enter" % (nameFunction)) print("%s : Checking if Interpolation mode value is valid" % (nameFunction)) if (interpolationMode == INTERPOLATION_LANCZOS): interpolationMode = 3 # if ((int(interpolationMode) < 0) or (int(interpolationMode) > 3)) : else: print("%s : Interpolation mode value is NOT valid = %s" % (nameFunction, str(interpolationMode))) raise Exception("Invalid value for parameter : interpolationMode") print("%s : Interpolation mode value IS valid = %s" % (nameFunction, interpolationMode)) debug = False fileHandle = open(listFiles, "r") filesList = fileHandle.read() fileHandle.close() listFiles = filesList.split("\n") print("%s : Number of elements in list = %d" % (nameFunction, len(listFiles))) print("%s : File list = %s" % (nameFunction, listFiles)) for filename in listFiles: try: 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 # Open the image file and get its drawable object. image = pdb.gimp_file_load(filename, filename) drawable = pdb.gimp_image_get_active_layer(image) # scale_and_set_size_interactive(image, drawable, horizontalResolution, verticalResolution, interpolationMode, filename) # Close the image now that we have finished with it, otherwise it will use up memory unnecessarily. pdb.gimp_image_delete(image) print("%s : Exit" % (nameFunction)) except: print("########################################") print("########################################") print("Something went wrong while attempting to") print("process the previous file; ") print("") print(" %s" % (filename)) print("") print("########################################") print("########################################")
def cutter_single_image( image, drawable, limit, sl_thresh, sz_thresh, bg_manual, bg_color, bg_corner, bg_x, bg_y, padding, deskew, sq_crop, autoclose, save_same, save_dir, save_ftype, save_dpi, jpg_qual, save_suffix ): img_width = pdb.gimp_image_width(image) img_height = pdb.gimp_image_height(image) img_fullpath = pdb.gimp_image_get_filename(image) img_filename = os.path.basename(img_fullpath) img_name = '.'.join(img_filename.split('.')[:-1]) img_ext = save_ftype or img_filename.split('.')[-1].lower() new_filename_tpl = ''.join([ img_name, '-', save_suffix, '-', '%0', str(len(str(int(limit + 1)))), 'd', '.', img_ext ]) new_fullpath_tpl = os.path.join( os.path.dirname(img_fullpath) if save_same else save_dir, new_filename_tpl ) # gimp.message(new_fullpath_tpl) # function code goes here... gimp.context_push() pdb.gimp_image_undo_disable(image) # If the background wasn't manually defined, pick the colour from one of the four corners # (using radius 5 average) if not bg_manual: if bg_corner in (1, 3): bg_x = img_width - bg_x if bg_corner in (2, 3): bg_y = img_height - bg_y bg_color = pdb.gimp_image_pick_color(image, drawable, bg_x, bg_y, True, True, 5) pdb.gimp_context_set_defaults() pdb.gimp_context_set_antialias(True) pdb.gimp_context_set_sample_transparent(True) pdb.gimp_context_set_sample_threshold_int(sl_thresh) pdb.gimp_context_set_feather(True) fr = min(img_width, img_height) / 100.0 # NOTE why??? pdb.gimp_context_set_feather_radius(fr, fr) pdb.gimp_context_set_background(bg_color) pdb.gimp_image_select_color(image, gimpfu.CHANNEL_OP_REPLACE, drawable, bg_color) # convert inverted copy of the background selection to a path pdb.gimp_selection_sharpen(image) pdb.gimp_selection_invert(image) # _, before = pdb.gimp_image_get_vectors(image) pdb.plug_in_sel2path(image, drawable) # _, after = pdb.gimp_image_get_vectors(image) # newpath_id = list(set(after) - set(before))[0] # newpath = gimp.Vectors.from_id(newpath_id) # looks like newly created vector is always active, so this should be sufficent newpath = pdb.gimp_image_get_active_vectors(image) pdb.gimp_context_set_feather(False) _, strokes = pdb.gimp_vectors_get_strokes(newpath) extracted = 0 for stroke_id in strokes: stroke_points = pdb.gimp_vectors_stroke_get_points(newpath, stroke_id) # skip not closed paths if not stroke_points[3]: continue temp_vector = pdb.gimp_vectors_new(image, '-temp-') pdb.gimp_image_insert_vectors(image, temp_vector, None, -1) pdb.gimp_vectors_stroke_new_from_points(temp_vector, *stroke_points) pdb.gimp_image_select_item(image, gimpfu.CHANNEL_OP_REPLACE, temp_vector) pdb.gimp_image_remove_vectors(image, temp_vector) # check for minimum size bounds = pdb.gimp_selection_bounds(image) sizex = bounds[3] - bounds[1] sizey = bounds[4] - bounds[2] if (min(sizex, sizey) < sz_thresh or sizex >= img_width or sizey >= img_height): continue buffname = "dsibuff" if deskew and pdb.gimp_procedural_db_proc_exists('gimp_deskew_plugin'): pdb.gimp_progress_set_text('Running deskew plugin...') pdb.gimp_image_select_rectangle( image, gimpfu.CHANNEL_OP_REPLACE, bounds[1], bounds[2], sizex, sizey ) buffname = pdb.gimp_edit_named_copy(drawable, buffname) temp_image = pdb.gimp_edit_named_paste_as_new(buffname) temp_layer = pdb.gimp_image_get_active_layer(temp_image) pdb.gimp_image_undo_disable(temp_image) pdb.gimp_layer_flatten(temp_layer) # RUN_NONINTERACTIVE causes 'calling error' exception pdb.gimp_deskew_plugin(temp_image, temp_layer, 0, 0, 0, 0, True, run_mode=gimpfu.RUN_INTERACTIVE) pdb.gimp_image_resize_to_layers(temp_image) pdb.gimp_layer_flatten(temp_layer) pdb.gimp_image_select_contiguous_color( temp_image, gimpfu.CHANNEL_OP_REPLACE, temp_layer, 0, 0 ) pdb.gimp_selection_invert(temp_image) bounds = pdb.gimp_selection_bounds(temp_image) sizex = bounds[3] - bounds[1] sizey = bounds[4] - bounds[2] pdb.gimp_selection_none(temp_image) pdb.gimp_image_crop(temp_image, sizex, sizey, bounds[1], bounds[2]) if (sq_crop and sizex != sizey and pdb.gimp_procedural_db_proc_exists('script_fu_addborder')): if sizex > sizey: dx = 0 dy = (sizex - sizey) * 0.5 else: dx = (sizey - sizex) * 0.5 dy = 0 pdb.script_fu_addborder(temp_image, temp_layer, dx, dy, bg_color, 0) pdb.gimp_image_raise_item_to_top(temp_image, temp_layer) pdb.gimp_image_merge_visible_layers(temp_image, gimpfu.EXPAND_AS_NECESSARY) temp_layer = pdb.gimp_image_get_active_layer(temp_image) else: temp_image = image pdb.gimp_image_undo_disable(temp_image) temp_layer = pdb.gimp_image_get_active_layer(temp_image) if sq_crop: c_x = 0.5 * (bounds[1] + bounds[3]) c_y = 0.5 * (bounds[2] + bounds[4]) hl = padding + max(sizex, sizey) * 0.5 sel_x = c_x - hl sel_y = c_y - hl sel_w = sel_h = 2 * hl else: sel_x = bounds[1] sel_y = bounds[2] sel_w = sizex sel_h = sizey pdb.gimp_image_select_rectangle( temp_image, gimpfu.CHANNEL_OP_REPLACE, sel_x, sel_y, sel_w, sel_h ) buffname = pdb.gimp_edit_named_copy(drawable, buffname) temp_image = pdb.gimp_edit_named_paste_as_new(buffname) temp_layer = pdb.gimp_image_get_active_layer(temp_image) if padding and pdb.gimp_procedural_db_proc_exists('script_fu_addborder'): pdb.script_fu_addborder(temp_image, temp_layer, padding, padding, bg_color, 0) pdb.gimp_image_merge_visible_layers(temp_image, gimpfu.EXPAND_AS_NECESSARY) temp_layer = pdb.gimp_image_get_active_layer(temp_image) pdb.gimp_image_undo_enable(temp_image) temp_display = pdb.gimp_display_new(temp_image) extracted += 1 filename = new_fullpath_tpl % (extracted, ) pdb.gimp_image_set_resolution(temp_image, save_dpi, save_dpi) if img_ext == 'jpg': pdb.file_jpeg_save( temp_image, temp_layer, filename, filename, jpg_qual, 0.1, 1, 1, '', 2, 0, 0, 1 ) else: pdb.gimp_file_save(temp_image, temp_layer, filename, filename) if autoclose: pdb.gimp_display_delete(temp_display) if extracted >= limit: break pdb.gimp_progress_set_text('Extracted %d images' % (extracted, )) pdb.gimp_image_remove_vectors(image, newpath) pdb.gimp_selection_none(image) pdb.gimp_image_undo_enable(image) pdb.gimp_progress_end() pdb.gimp_displays_flush() gimp.context_pop() return extracted
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))
def flip(file): image = pdb.gimp_file_load(file, file) drawable = pdb.gimp_image_get_active_layer(image) pdb.gimp_image_flip(image, ORIENTATION_HORIZONTAL) pdb.gimp_file_save(image, drawable, file, file) pdb.gimp_image_delete(image)
def despeckle(fin, fout): image = pdb.gimp_file_load(fin, fin) drawable = pdb.gimp_image_get_active_layer(image) pdb.plug_in_despeckle(image, drawable, 3, 1, 7, 248) pdb.gimp_file_save(image, drawable, fout, fout) pdb.gimp_image_delete(image)
def processList(self): nameMethod = self.nameClass + "::run" print("%s : Enter" % (nameMethod)) # 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) indexList = 0 for filenameForeground in self.listFilenamesForeground: indexList = indexList + 1 # self.checkFiles(filename, filenameOverlay) self.imageBackground = pdb.gimp_file_load(self.filenameBackground, self.filenameBackground) self.drawableBackground = pdb.gimp_image_get_active_layer( self.imageBackground) self.imageForeground = pdb.gimp_file_load(filenameForeground, filenameForeground) self.drawableForeground = pdb.gimp_image_get_active_layer( self.imageForeground) print("%s : Processing ..." % (nameMethod)) print("%s : Background image = %s" % (nameMethod, self.filenameBackground)) print("%s : Overlay image = %s" % (nameMethod, filenameForeground)) # Display information about both of the current images. self.displayImageData() # How many layers does the current image now contain? # # Use gimp-edit-copy and gimp-edit-paste? self.overlayImage() # Move the # pdb.gimp_drawable_update() # self.drawableNew = pdb.gimp_image_flatten(self.imageNew) pdb.gimp_file_save(self.imageForeground, self.drawableForeground, filenameForeground, filenameForeground) # Close the images now that we have finished with it, otherwise they will use up memory unnecessarily. pdb.gimp_image_delete(self.imageForeground) pdb.gimp_image_delete(self.imageBackground) # End of for loop. # End the GIMP Undo group. # pdb.gimp_undo_push_group_end(image) print("%s : Enter" % (nameMethod))
def simple_plugin(filename_background, filename_foreground, filename_result): nameProcedure = "simple_plugin" sleep_timer = 0 counter = 1 print("%s : Enter" % (nameProcedure)) # ---------------------------------------------------------------------------------------------- # Get the following from both the background and foreground image files; # # - image # - drawable # ---------------------------------------------------------------------------------------------- image_background = pdb.gimp_file_load(filename_background, filename_background) drawable_background = pdb.gimp_image_get_active_layer(image_background) image_foreground = pdb.gimp_file_load(filename_foreground, filename_foreground) drawable_foreground = pdb.gimp_image_get_active_layer(image_foreground) display_diagnostics(counter, image_background, image_foreground, drawable_background, drawable_foreground) counter = counter + 1 gimp.progress_init("Have got image and drawable from both files") time.sleep(sleep_timer) # ---------------------------------------------------------------------------------------------- # Start a GIMP Undo group, as this will allow the actions of this Plugin to be undone in one # step. # ---------------------------------------------------------------------------------------------- pdb.gimp_image_undo_group_start(image_background) # ---------------------------------------------------------------------------------------------- # Copy the foreground image. # ---------------------------------------------------------------------------------------------- copy_result = pdb.gimp_edit_copy(drawable_foreground) print("%s : Copy result = %s" % (nameProcedure, str(copy_result))) gimp.progress_init("Have copied foreground image into Buffer") time.sleep(sleep_timer) # ---------------------------------------------------------------------------------------------- # Paste the foreground image onto the background image. # ---------------------------------------------------------------------------------------------- use_gimp_edit_paste_as_new = False if use_gimp_edit_paste_as_new: pdb.gimp_edit_paste(drawable_background, True) else: image_background_new = pdb.gimp_edit_paste_as_new( drawable_background, True) if (image_background_new == -1): print( "%s : Attempted to paste from the Edit buffer, but it appears to be empty." % (nameProcedure)) exception_message = "\n\nAn Exception has been raised by the method;\n\n " + \ nameProcedure + \ "\n\nThis method attempted to paste from the Edit buffer, but it appears to be empty.\n\nAs a result, this Plugin is about to terminate!" raise Exception(exception_message) gimp.progress_init( "Have pasted foreground image from Buffer onto background image") time.sleep(sleep_timer) display_diagnostics(counter, image_background, image_foreground, drawable_background, drawable_foreground) counter = counter + 1 # ---------------------------------------------------------------------------------------------- # Flatten the modified background image down into one layer. # ---------------------------------------------------------------------------------------------- drawable_background = pdb.gimp_image_flatten(image_background) gimp.progress_init("Have flattened the background image") time.sleep(sleep_timer) display_diagnostics(counter, image_background, image_foreground, drawable_background, drawable_foreground) # ---------------------------------------------------------------------------------------------- # Save the background image into a specified file. # ---------------------------------------------------------------------------------------------- if use_gimp_edit_paste_as_new: pdb.gimp_file_save(image_background, drawable_background, filename_result, filename_result) else: pdb.gimp_file_save(image_background_new, drawable_background, filename_result, filename_result) gimp.progress_init("Have saved the background image") time.sleep(sleep_timer) # ---------------------------------------------------------------------------------------------- # End the GIMP Undo group which was started at the beginning of this Plugin. # ---------------------------------------------------------------------------------------------- pdb.gimp_image_undo_group_end(image_background) # ---------------------------------------------------------------------------------------------- # Close the GIMP images now that we have finished with them, otherwise they will use up memory # nnecessarily. # ---------------------------------------------------------------------------------------------- pdb.gimp_image_delete(image_foreground) pdb.gimp_image_delete(image_background) print("%s : Exit" % (nameProcedure))