def synth_image(a, tile_horiz=False, tile_vert=False, show=False): a_width = max(len(row) for row in a) a_height = len(a) i = gimp.Image(a_width * w, a_height * w) l = gimp.Layer(i, "Base", i.width, i.height) i.add_layer(l) mi = gimp.Image(i.width, i.height, gimpenums.GRAY) m = gimp.Layer(mi, "Mask", mi.width, mi.height, gimpenums.GRAY_IMAGE) mi.add_layer(m) # Copy up tiles that we have, and mask for y, row in enumerate(a): for x, tile in enumerate(row): # Mask t = tiles[tile] copy_tile(output_map, t[0], t[1], m, x, y) # Image if tile in result_dict: t = result_dict[tile] copy_tile(t[0], t[1], t[2], l, x, y) # Adjust selection to tiles we don't have # Also adjust selection in result, just # so users know what tiles are being generated pdb.gimp_selection_none(i) pdb.gimp_selection_none(result) for y, row in enumerate(a): for x, tile in enumerate(row): if tile in result_dict: continue if tile is EMPTY_TILE: continue pdb.gimp_image_select_rectangle(i, gimpenums.CHANNEL_OP_ADD, x * w, y * w, w, w) t = tiles[tile] pdb.gimp_image_select_rectangle(result, gimpenums.CHANNEL_OP_ADD, t[0] * w, t[1] * w, w, w) # Do the actual resynthesize call if True: pdb.plug_in_resynthesizer(i, l, int(tile_vert), int(tile_horiz), 1, source.ID, source_map.ID, m.ID, map_weight, autism, neighbourhood, trys) # Copy to result image for y, row in enumerate(a): for x, tile in enumerate(row): if tile in result_dict: continue t = tiles[tile] copy_tile(l, x, y, result_layer, t[0], t[1]) result_dict[tile] = (result_layer, t[0], t[1]) if show: # For debugging gimp.Display(i) gimp.Display(mi) else: pdb.gimp_image_delete(i) pdb.gimp_image_delete(mi)
def _get_basic_settings(): image = _create_test_image() return [ { "name": "integer", "type": settings_.SettingTypes.integer, }, { "name": "float", "type": settings_.SettingTypes.float, }, { "name": "boolean", "type": settings_.SettingTypes.boolean, }, { "name": "enumerated", "type": settings_.SettingTypes.enumerated, "items": [("interactive", "RUN-INTERACTIVE"), ("non_interactive", "RUN-NONINTERACTIVE"), ("run_with_last_vals", "RUN-WITH-LAST-VALS")], "default_value": "non_interactive", }, { "name": "string", "type": settings_.SettingTypes.string, "default_value": "Test", }, { "name": "image", "type": settings_.SettingTypes.image, "default_value": image, }, { "name": "item", "type": settings_.SettingTypes.item, "default_value": image.layers[0], }, { "name": "drawable", "type": settings_.SettingTypes.drawable, "default_value": image.layers[0], }, { "name": "layer", "type": settings_.SettingTypes.layer, "default_value": image.layers[0], }, { "name": "channel", "type": settings_.SettingTypes.channel, "default_value": image.channels[0], }, { "name": "selection", "type": settings_.SettingTypes.selection, "default_value": pdb.gimp_image_get_selection(image), }, { "name": "vectors", "type": settings_.SettingTypes.vectors, "default_value": image.vectors[0], }, { "name": "color", "type": settings_.SettingTypes.color, }, { "name": "parasite", "type": settings_.SettingTypes.parasite, }, { "name": "display", "type": settings_.SettingTypes.display, "default_value": gimp.Display(image), }, { "name": "pdb_status", "type": settings_.SettingTypes.pdb_status, }, { "name": "file_extension", "type": settings_.SettingTypes.file_extension, "default_value": "png", }, { "name": "directory", "type": settings_.SettingTypes.directory, }, { "name": "brush", "type": settings_.SettingTypes.brush, }, { "name": "font", "type": settings_.SettingTypes.font, }, { "name": "gradient", "type": settings_.SettingTypes.gradient, }, { "name": "palette", "type": settings_.SettingTypes.palette, }, { "name": "pattern", "type": settings_.SettingTypes.pattern, }, ]
def contact_sheet(file_type, location, all_subdirs, inc_filename, inc_extension, contact_name, contact_type, contact_location, contact_size, dpi, orient, num_col, num_rows, PageBorderLR, PageBorderTB, mmTHUMB_MARGIN, mmFONT_SIZE, Dump_Filename_list, Sorted_Images, Print_Contactsheet): # pdb.gimp_message (location) if os.path.exists(u'' + location): # pdb.gimp_message ("continuing1") # do nothing just set a variable xblot = 1 else: pdb.gimp_message(_("%s doesn't exist") % (location)) return if os.path.exists(u'' + contact_location): # pdb.gimp_message ("continuing2") # do nothing just set a variable xblot = 1 else: pdb.gimp_message(_("%s doesn't exist") % (contact_location)) return #collect 'all' images in the choosen directory and subdirs images = get_images(file_type, location, all_subdirs, Dump_Filename_list, Sorted_Images) num_images = len(images) #calculate number of images #if necessary make a txt file with image name and image directory if (Dump_Filename_list == True): Make_DirFile_List(images, contact_location, contact_name) #make a new drawing canvas of the correct size width, height = CalcPaperSize(contact_size, dpi) #dimensions in px #calculate the required size for the thumbs based on the number of images #per row. Sizes are in px and floored with maximum error of one px LEFT_PAGE_BORDER = (PageBorderLR / 25.4) * dpi RIGHT_PAGE_BORDER = (PageBorderLR / 25.4) * dpi BOTTOM_PAGE_BORDER = (PageBorderTB / 25.4) * dpi THUMB_MARGIN = (mmTHUMB_MARGIN / 25.4) * dpi FONT_SIZE = (mmFONT_SIZE / 25.4) * dpi TOP_PAGE_BORDER = (PageBorderTB / 25.4) * dpi + FONT_SIZE #include sheet .. of .. #number of rows is limited so is ThumbsPerSheet #Thumb sizes are in px, based on dpi setting if (orient == "port"): Thumb_width = ((width - LEFT_PAGE_BORDER - RIGHT_PAGE_BORDER) / num_col) - 2 * THUMB_MARGIN if (inc_filename == True): UsableRows = floor( (height - TOP_PAGE_BORDER - BOTTOM_PAGE_BORDER) / (Thumb_width + FONT_SIZE + 2 * THUMB_MARGIN)) else: UsableRows = floor( (height - TOP_PAGE_BORDER - BOTTOM_PAGE_BORDER) / (Thumb_width + 2 * THUMB_MARGIN)) else: Thumb_width = ((height - LEFT_PAGE_BORDER - RIGHT_PAGE_BORDER) / num_col) - 2 * THUMB_MARGIN if (inc_filename == True): UsableRows = floor((width - TOP_PAGE_BORDER - BOTTOM_PAGE_BORDER) / (Thumb_width + FONT_SIZE + 2 * THUMB_MARGIN)) else: UsableRows = floor((width - TOP_PAGE_BORDER - BOTTOM_PAGE_BORDER) / (Thumb_width + 2 * THUMB_MARGIN)) Thumb_height = Thumb_width #Number of chosen rows can never be bigger then usable rows if (num_rows > UsableRows): num_rows = UsableRows ThumbsPerSheet = int(num_col * num_rows) #added 'int' for python v2.6 img_no = 1 for sheetcount in range(int(ceil(num_images / float(ThumbsPerSheet)))): if (orient == "land"): sheetimg = gimp.Image(height, width, RGB) bklayer = gimp.Layer(sheetimg, "Background", height, width, RGB_IMAGE, 100, LAYER_MODE_NORMAL) else: sheetimg = gimp.Image(width, height, RGB) bklayer = gimp.Layer(sheetimg, "Background", width, height, RGB_IMAGE, 100, LAYER_MODE_NORMAL) sheetimg.disable_undo() sheetimg.add_layer(bklayer, 0) #set the image resolution sheetimg.resolution = (float(dpi), float(dpi)) #now calculate sizes; printable sheet dimensions are given #in px based on the dpi setting Canvas_width = sheetimg.width - LEFT_PAGE_BORDER - RIGHT_PAGE_BORDER Canvas_height = sheetimg.height - TOP_PAGE_BORDER - BOTTOM_PAGE_BORDER #print ("Canvas width %d height %d" % ( Canvas_width,Canvas_height)) #Log(str(sheetimg.resolution)) #now fill with white, How to fill with a other color????? bklayer.fill(FILL_WHITE) # gimp.set_background(bk_color) # gimp-bklayer-fill(bklayer, IMAGE-FILL-BG) # Log (str(bk_color)) # bklayer.fill(bk_color) # Log(str(gimp.get_background())) bklayer.flush() sheetdsp = gimp.Display(sheetimg) #print "sheet display" + str(sheetdsp) gimp.displays_flush() txtw, CalcTextHeight, txte, txtd = pdb.gimp_text_get_extents_fontname( _("Sheet %03d of %03d") % (sheetcount + 1, int(ceil(num_images / float(ThumbsPerSheet)))), FONT_SIZE, PIXELS, "Arial") ## txtfloat = pdb.gimp_text_fontname(sheetimg, sheetimg.active_layer, #only for me ## LEFT_PAGE_BORDER, TOP_PAGE_BORDER-CalcTextHeight, ## _("Sheet %03d of %03d"), ## contactsheet designed by R, Gilham (za) and E. Sullock Enzlin (nl)" ## % (sheetcount+1,int(ceil(num_images/float(ThumbsPerSheet)))), ## -1, False, FONT_SIZE, PIXELS, "Arial") txtfloat = pdb.gimp_text_fontname( sheetimg, sheetimg.active_layer, LEFT_PAGE_BORDER, TOP_PAGE_BORDER - CalcTextHeight, _("Sheet %03d of %03d") % (sheetcount + 1, int(ceil(num_images / float(ThumbsPerSheet)))), -1, False, FONT_SIZE, PIXELS, "Arial") pdb.gimp_floating_sel_anchor(txtfloat) CalcTextHeight = 0 txtw, txth, txte, txtd = (0, 0, 0, 0) if (inc_filename == True): txtw, CalcTextHeight, txte, txtd = pdb.gimp_text_get_extents_fontname( images[0]['base_name'], FONT_SIZE, PIXELS, "Arial") #print "CalcText Height %d " %(CalcTextHeight) files = images[sheetcount * ThumbsPerSheet:(sheetcount + 1) * ThumbsPerSheet] #now for each of the image files generate a thumbnail rcount = 0 ccount = 0 #generate thumb for file in files: thumbimg, x_size, y_size, valid_image = generate_thumb( file['image_file'], Thumb_width, Thumb_height) if valid_image == False: continue #next image cpy = pdb.gimp_edit_copy(thumbimg.active_layer) #center image within its minipage if (x_size > y_size): #landscape image, center vertical y_offset = (Thumb_width - y_size) / 2 x_offset = 0 else: #portrait image, center horizontal x_offset = (Thumb_height - x_size) / 2 y_offset = 0 gimp.delete(thumbimg) #now paste the new thumb into contact sheet newselect = pdb.gimp_edit_paste(sheetimg.active_layer, True) #print str(newselect) #print str(newselect.offsets) #positition in top left corner newselect.translate(-newselect.offsets[0], -newselect.offsets[1]) #now position in correct position, modified with x- and y-offset xpos = LEFT_PAGE_BORDER + ccount * ( Thumb_width + (2 * THUMB_MARGIN)) + THUMB_MARGIN + x_offset ypos = TOP_PAGE_BORDER + rcount * ( Thumb_height + (2 * THUMB_MARGIN) + CalcTextHeight) + THUMB_MARGIN + y_offset xpos = int( xpos ) #changed to int: on ubuntu type error integer expected got float. ypos = int(ypos) newselect.translate(xpos, ypos) pdb.gimp_floating_sel_anchor(newselect) if (inc_filename == True): if (inc_extension == True): ThumbName = file['base_name'] + file['extension'] else: ThumbName = file['base_name'] Size, txtwidth = CalcFontSize(ThumbName, "Arial", FONT_SIZE, CalcTextHeight, Thumb_width) #calculate text position, round the center of the image txt_xpos = xpos + (Thumb_width - txtwidth) / 2 - x_offset txt_ypos = ypos + Thumb_height + THUMB_MARGIN - y_offset txtfloat = pdb.gimp_text_fontname(sheetimg, sheetimg.active_layer, txt_xpos, txt_ypos, ThumbName, -1, False, Size, PIXELS, "Arial") pdb.gimp_floating_sel_anchor(txtfloat) ccount = ccount + 1 if (ccount >= num_col): ccount = 0 rcount = rcount + 1 gimp.displays_flush() #save contactsheet contact_filename = contact_name + "_%03d" % (sheetcount + 1) + contact_type contact_full_filename = os.path.join(contact_location, contact_filename) #print "File to save " + contact_full_filename if (contact_type == ".jpg"): save_jpeg(sheetimg, contact_full_filename, "") else: save_png(sheetimg, pdb.gimp_image_get_active_drawable(sheetimg), contact_full_filename, False) if (Print_Contactsheet == True): pdb.file_print_gtk(sheetimg) gimp.delete(sheetimg) pdb.gimp_display_delete(sheetdsp)
def make_blob_output(source, source_map, output_map, map_weight, autism, neighbourhood, trys): w = int(output_map.width / 10) assert w * 10 == output_map.width assert w * 5 == output_map.height def copy_tile(src, src_x, src_y, dest, dest_x, dest_y): pdb.gimp_image_select_rectangle(src.image, gimpenums.CHANNEL_OP_REPLACE, src_x * w, src_y * w, w, w) pdb.gimp_edit_copy(src) l = pdb.gimp_edit_paste(dest, 0) l.set_offsets(dest_x * w, dest_y * w) pdb.gimp_floating_sel_anchor(l) result = gimp.Image(w * 10, w * 5) result_layer = gimp.Layer(result, "Result", result.width, result.height) result.add_layer(result_layer) # Give the user something to look at while we're working # The resynthesis is slow enough there's little to be gained from # not updating the UI result_display = gimp.Display(result) # These special tiles are the first ones to be synthesized # and are used as the seed for generating others SOLID_TILE = Tile(SOLID, SOLID, SOLID, SOLID) HORIZ_TILE = Tile(BLANK, BOTH, BLANK, BOTH) TL_TILE = Tile(BLANK, LEFT, RIGHT, BLANK) TR_TILE = Tile(BLANK, BLANK, LEFT, RIGHT) BL_TILE = Tile(LEFT, RIGHT, BLANK, BLANK) BR_TILE = Tile(RIGHT, BLANK, BLANK, LEFT) VERT_TILE = Tile(BOTH, BLANK, BOTH, BLANK) result_dict = {} # Creates a temporary image with tiles given in the 2d array # If a tile is missing, it is an indication it needs to be synthesized def synth_image(a, tile_horiz=False, tile_vert=False, show=False): a_width = max(len(row) for row in a) a_height = len(a) i = gimp.Image(a_width * w, a_height * w) l = gimp.Layer(i, "Base", i.width, i.height) i.add_layer(l) mi = gimp.Image(i.width, i.height, gimpenums.GRAY) m = gimp.Layer(mi, "Mask", mi.width, mi.height, gimpenums.GRAY_IMAGE) mi.add_layer(m) # Copy up tiles that we have, and mask for y, row in enumerate(a): for x, tile in enumerate(row): # Mask t = tiles[tile] copy_tile(output_map, t[0], t[1], m, x, y) # Image if tile in result_dict: t = result_dict[tile] copy_tile(t[0], t[1], t[2], l, x, y) # Adjust selection to tiles we don't have # Also adjust selection in result, just # so users know what tiles are being generated pdb.gimp_selection_none(i) pdb.gimp_selection_none(result) for y, row in enumerate(a): for x, tile in enumerate(row): if tile in result_dict: continue if tile is EMPTY_TILE: continue pdb.gimp_image_select_rectangle(i, gimpenums.CHANNEL_OP_ADD, x * w, y * w, w, w) t = tiles[tile] pdb.gimp_image_select_rectangle(result, gimpenums.CHANNEL_OP_ADD, t[0] * w, t[1] * w, w, w) # Do the actual resynthesize call if True: pdb.plug_in_resynthesizer(i, l, int(tile_vert), int(tile_horiz), 1, source.ID, source_map.ID, m.ID, map_weight, autism, neighbourhood, trys) # Copy to result image for y, row in enumerate(a): for x, tile in enumerate(row): if tile in result_dict: continue t = tiles[tile] copy_tile(l, x, y, result_layer, t[0], t[1]) result_dict[tile] = (result_layer, t[0], t[1]) if show: # For debugging gimp.Display(i) gimp.Display(mi) else: pdb.gimp_image_delete(i) pdb.gimp_image_delete(mi) synth_image([[EMPTY_TILE]], tile_vert=True, tile_horiz=True) synth_image([[SOLID_TILE]], tile_vert=True, tile_horiz=True) synth_image([[EMPTY_TILE, VERT_TILE, EMPTY_TILE]], tile_vert=True) synth_image([[EMPTY_TILE], [HORIZ_TILE], [EMPTY_TILE]], tile_horiz=True) synth_image([[EMPTY_TILE, EMPTY_TILE, EMPTY_TILE, EMPTY_TILE], [EMPTY_TILE, TL_TILE, TR_TILE, EMPTY_TILE], [EMPTY_TILE, BL_TILE, BR_TILE, EMPTY_TILE], [EMPTY_TILE, EMPTY_TILE, EMPTY_TILE, EMPTY_TILE]]) # We've now synth'd a tile representative of every possible # border, the rest can be done from these top_border = {LEFT: TL_TILE, RIGHT: TR_TILE, BOTH: VERT_TILE} right_border = {LEFT: TR_TILE, RIGHT: BR_TILE, BOTH: HORIZ_TILE} bottom_border = {LEFT: BR_TILE, RIGHT: BL_TILE, BOTH: VERT_TILE} left_border = {LEFT: BL_TILE, RIGHT: TL_TILE, BOTH: HORIZ_TILE} for border in (top_border, right_border, bottom_border, left_border): border[BLANK] = EMPTY_TILE border[SOLID] = SOLID_TILE for tile in tiles.keys(): if tile in result_dict: continue a = [[EMPTY_TILE, EMPTY_TILE, EMPTY_TILE], [EMPTY_TILE, EMPTY_TILE, EMPTY_TILE], [EMPTY_TILE, EMPTY_TILE, EMPTY_TILE]] a[1][1] = tile a[0][1] = top_border[tile.top] a[1][2] = right_border[tile.right] a[2][1] = bottom_border[tile.bottom] a[1][0] = left_border[tile.left] # Should really do corners here too # but the lack of them doesn't seem # to be hurting the visual quality synth_image(a)
def make_blob_output_pattern(tile_width, inset, outer_radius, inner_radius): w = tile_width h = w inner_radius = min(inner_radius, inset) outer_radius = min(outer_radius, (w - 2 * inset) / 2.0) img = gimp.Image(10 * w, 5 * h, gimpenums.GRAY) l = gimp.Layer(img, "Base", img.width, img.height, gimpenums.GRAY_IMAGE, 100, gimpenums.NORMAL_MODE) img.add_layer(l) def get_range(face, face_type): if face_type == BLANK: return None if face_type == LEFT: r = (inset, w - inset) if face_type == SOLID: r = (0, w) if face_type == RIGHT: r = (0, w - inset) if face_type == BOTH: r = (inset, w - inset * 2) if face == "top": r = (r[0], 0, r[1], inset) if face == "right": r = (w - inset, r[0], inset, r[1]) if face == "bottom": r = (w - r[0] - r[1], w - inset, r[1], inset) if face == "left": r = (0, w - r[0] - r[1], inset, r[1]) return r for tile, pos in tiles.items(): if tile is None: continue x = pos[0] * w y = pos[1] * w color = ((pos[0] + pos[1]) % 2) * 100 + 100 color = (color, color, color) color = (255, 255, 255) pdb.gimp_context_set_foreground(color) pdb.gimp_context_set_background((0, 0, 0)) # Draw the center of the filled tile cx = x + w / 2.0 cy = y + h / 2.0 b = (w - 2 * inset) / 2.0 draw_rect(l, x + inset, y + inset, w - 2 * inset, h - 2 * inset, color) if outer_radius > 0: if tile.top == BLANK and tile.left == BLANK: pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, cx - b, cy - b, outer_radius, outer_radius) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_image_select_ellipse(img, gimpenums.CHANNEL_OP_INTERSECT, cx - b, cy - b, 2 * outer_radius, 2 * outer_radius) pdb.gimp_edit_fill(l, gimpenums.FOREGROUND_FILL) if tile.top == BLANK and tile.right == BLANK: pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, cx + b - outer_radius, cy - b, outer_radius, outer_radius) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_image_select_ellipse(img, gimpenums.CHANNEL_OP_INTERSECT, cx + b - 2 * outer_radius, cy - b, 2 * outer_radius, 2 * outer_radius) pdb.gimp_edit_fill(l, gimpenums.FOREGROUND_FILL) if tile.bottom == BLANK and tile.right == BLANK: pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, cx + b - outer_radius, cy + b - outer_radius, outer_radius, outer_radius) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_image_select_ellipse(img, gimpenums.CHANNEL_OP_INTERSECT, cx + b - 2 * outer_radius, cy + b - outer_radius * 2, 2 * outer_radius, 2 * outer_radius) pdb.gimp_edit_fill(l, gimpenums.FOREGROUND_FILL) if tile.bottom == BLANK and tile.left == BLANK: pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, cx - b, cy + b - outer_radius, outer_radius, outer_radius) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_image_select_ellipse(img, gimpenums.CHANNEL_OP_INTERSECT, cx - b, cy + b - outer_radius * 2, 2 * outer_radius, 2 * outer_radius) pdb.gimp_edit_fill(l, gimpenums.FOREGROUND_FILL) # Connect the center to the edge for i, face in enumerate(("top", "right", "bottom", "left")): t = getattr(tile, face) r = get_range(face, t) if r is None: continue draw_rect(l, x + r[0], y + r[1], r[2], r[3], color) # Draw the inner corners if inner_radius > 0: def is_corner(t1, t2): return (t1 == BOTH or t1 == RIGHT) and (t2 == BOTH or t2 == LEFT) if is_corner(tile.left, tile.top): pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, x, y, inset, inset) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, x + inset - inner_radius, y + inset - inner_radius, inner_radius, inner_radius) pdb.gimp_edit_fill(l, gimpenums.FOREGROUND_FILL) pdb.gimp_image_select_ellipse(img, gimpenums.CHANNEL_OP_INTERSECT, x + inset - inner_radius * 2, y + inset - inner_radius * 2, inner_radius * 2, inner_radius * 2) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) if is_corner(tile.top, tile.right): pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, x + w - inset, y, inset, inset) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, x + w - inset, y + inset - inner_radius, inner_radius, inner_radius) pdb.gimp_edit_fill(l, gimpenums.FOREGROUND_FILL) pdb.gimp_image_select_ellipse(img, gimpenums.CHANNEL_OP_INTERSECT, x + w - inset, y + inset - inner_radius * 2, inner_radius * 2, inner_radius * 2) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) if is_corner(tile.right, tile.bottom): pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, x + w - inset, y + h - inset, inset, inset) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, x + w - inset, y + h - inset, inner_radius, inner_radius) pdb.gimp_edit_fill(l, gimpenums.FOREGROUND_FILL) pdb.gimp_image_select_ellipse(img, gimpenums.CHANNEL_OP_INTERSECT, x + w - inset, y + h - inset, inner_radius * 2, inner_radius * 2) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) if is_corner(tile.bottom, tile.left): pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, x, y + h - inset, inset, inset) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_image_select_rectangle(img, gimpenums.CHANNEL_OP_REPLACE, x + inset - inner_radius, y + h - inset, inner_radius, inner_radius) pdb.gimp_edit_fill(l, gimpenums.FOREGROUND_FILL) pdb.gimp_image_select_ellipse(img, gimpenums.CHANNEL_OP_INTERSECT, x + inset - inner_radius * 2, y + h - inset, inner_radius * 2, inner_radius * 2) pdb.gimp_edit_fill(l, gimpenums.BACKGROUND_FILL) pdb.gimp_selection_none(img) d = gimp.Display(img)
def do_stuff(img, layer, mapswide, mapstall) : setup_palette() gimp.progress_init("Minecraft Mapifying " + layer.name + "...") # Disable Undo as we are creating a new window pdb.gimp_image_undo_disable(img) new_img = pdb.gimp_image_duplicate(img) gimp.Display(new_img) gimp.displays_flush() pdb.gimp_image_undo_disable(new_img) # Calculate the height and width of the new image img_ratio = float(layer.width) / float(layer.height) map_ratio = float(mapswide) / float(mapstall) offset_x = 0 offset_y = 0 width = 0 height = 0 # If the aspect ratio of the original image is greater than the aspect ratio of the maps, # then the original image needs padding above and below to fit the maps if img_ratio > map_ratio: width = mapswide * 128 height = int(float(width) / img_ratio) offset_y = ((map_ratio * 128) - height) / 2 # otherwise padding is needed to the left and right else: height = mapstall * 128 width = int(img_ratio * float(height)) offset_x = ((map_ratio * 128) - width) / 2 # Resize the image to the fit the maps requested pdb.gimp_context_set_interpolation(INTERPOLATION_CUBIC) pdb.gimp_image_scale(new_img, width, height) new_img.resize(mapswide * 128, mapstall * 128, int(offset_x), int(offset_y)) # Create a new background layer, fill it with the background color, and flatten the image to create the padding new_img.add_layer(new_img.active_layer.copy(), 1) new_img.layers[1].resize(mapswide * 128, mapstall * 128, int(offset_x), int(offset_y)) new_img.layers[1].fill(BACKGROUND_FILL) new_img.flatten() new_img.active_layer.name = layer.name # Turn the image into the map palette pdb.gimp_image_convert_indexed(new_img, CONVERT_DITHER_FS_LOWBLEED, CONVERT_PALETTE_CUSTOM, 0, False, True, "Minecraft Map In Order") gimp.displays_flush() # Create 2 duplicate layers as they will be used in outputing the build details new_img.add_layer(new_img.layers[0].copy(), 1) new_img.add_layer(new_img.layers[0].copy(), 2) new_img.layers[0].name = layer.name + " [Map]" new_img.layers[1].name = layer.name + " [Types]" new_img.layers[2].name = layer.name + " [Heights]" scan_image(new_img.layers[0], new_img.layers[1], new_img.layers[2]) # Enable undo again pdb.gimp_image_undo_enable(img) pdb.gimp_image_undo_enable(new_img)