def create_base_alphabet(font, font_size, directory_base): suffix = '.xbm' for c_gen, c_prefix in ( (map(chr, xrange(ord('A'), ord('Z') + 1)), 'upper'), (map(chr, xrange(ord('a'), ord('z') + 1)), 'lower'), (map(chr, xrange(ord('0'), ord('9') + 1)), 'number'), ): for c in c_gen: prefix = '%s%c' % (c_prefix, c) filename = '%s%s' % (prefix, suffix) image = gimp.Image(1, 1, INDEXED) image.disable_undo() # necessary ? pdb.gimp_context_push() gimp.set_foreground((0.0, 0.0, 0.0)) x = y = border = 0 layer = pdb.gimp_text_fontname(image, None, x, y, c, border, True, font_size, PIXELS, font) image.resize(layer.width, layer.height, 0, 0) filepath = join(directory_base, filename) pdb.gimp_file_save(image, layer, filepath, '?') #pdb.file_xbm_save(RUN_NONINTERACTIVE, image, None, filename, filepath, '', 0, 0, 0) # find out how to properly call file_xbm_save so we can avoid this crap with open(filepath, 'r+b') as file_h: lines = file_h.readlines() file_h.seek(0) for line in lines: if '_' in line: if '_hot' not in line: file_h.write(line.replace('_', prefix + '_')) else: file_h.write(line) file_h.truncate() pdb.gimp_image_delete(image) # necessary ? pdb.gimp_context_pop()
def cookie_cutter_letter(img, substrate, right, font, letter): '''Cut text shaped like letter out of the given layer.''' temp_layer = gpdb.gimp_text_fontname(img, substrate, right, 0, letter, 1, False, FONT_HEIGHT, PIXELS, font) gpdb.gimp_selection_layer_alpha(temp_layer) angle = random.uniform(*ANGLE_RANGE) xaxis = right yaxis = 15 # srcX = float(xaxis) # dstX = float(srcX + random.uniform(0, 25)) # srcY = float(yaxis) # dstY = float(srcY + random.uniform(0, 25)) # scaleX = scaleY = float(100) # We need to save the selection as a channel so we can mess with # the letter form. shape = gpdb.gimp_selection_save(img) gpdb.gimp_selection_none(img) gpdb.gimp_floating_sel_remove(temp_layer) # Distort the form of the individual letter: shape = gpdb.gimp_item_transform_rotate(shape, angle, 0, xaxis, yaxis) # We aren't doing any letter warping now, but if we were, this is the # point where it should be done. We want to warp the shape of textLayer, # which later serves as a cutout for the dark noise layer. If we warp the # dark noise layer directly we will end up with warped dots. # # gpdb.gimp_context_set_transform_resize(TRANSFORM_RESIZE_CROP) # shape = gpdb.gimp_item_transform_2d(shape, srcX, srcY, angle, # scaleX, scaleY, dstX, dstY) gpdb.gimp_selection_load(shape) img.remove_channel(shape) # Note the bounding box of the letter form so we can figure out # where the next one should go. bounds = gpdb.gimp_selection_bounds(img) new_right = bounds[3] + LETTER_SPACING # Actually cut the letter form out of the substate. gpdb.gimp_selection_invert(img) gpdb.gimp_edit_clear(substrate) gpdb.gimp_selection_none(img) return new_right
def create_base_alphabet(font, font_size, directory_base): suffix = '.xbm' for c in string.printable: # Only need the first guard to prevent \x0b and \x0c, but meh if not ' ' <= c <= '\x7f': continue prefix = 'ascii0x%02x' % ord(c) filename = '%s%s' % (prefix, suffix) image = gimp.Image(1, 1, INDEXED) image.disable_undo() # necessary ? pdb.gimp_context_push() gimp.set_foreground((0.0, 0.0, 0.0)) x = y = border = 0 layer = pdb.gimp_text_fontname(image, None, x, y, c, border, True, font_size, PIXELS, font) if layer is None: print 'Failed to handle %r' % c else: image.resize(layer.width, layer.height, 0, 0) filepath = join(directory_base, filename) pdb.gimp_file_save(image, layer, filepath, '?') #pdb.file_xbm_save(RUN_NONINTERACTIVE, image, None, filename, filepath, '', 0, 0, 0) # find out how to properly call file_xbm_save so we can avoid this section with open(filepath, 'r+b') as file_h: lines = file_h.readlines() file_h.seek(0) for line in lines: if '_' in line: if '_hot' not in line: file_h.write(line.replace('_', prefix + '_')) else: file_h.write(line) file_h.truncate() pdb.gimp_image_delete(image) # necessary ? pdb.gimp_context_pop()
def create_base_alphabet(font, font_size, directory_base): suffix = '.xbm' for c in string.printable: # Only need the first guard to prevent \x0b and \x0c, but meh if not ' ' <= c <= '\x7f': continue prefix = 'ascii0x%02x' % ord(c) filename = '%s%s' % (prefix, suffix) image = gimp.Image(1, 1, INDEXED) image.disable_undo() # necessary ? pdb.gimp_context_push() gimp.set_foreground( (0.0, 0.0, 0.0) ) x = y = border = 0 layer = pdb.gimp_text_fontname(image, None, x, y, c, border, True, font_size, PIXELS, font) if layer is None: print 'Failed to handle %r' % c else: image.resize(layer.width, layer.height, 0, 0) filepath = join(directory_base, filename) pdb.gimp_file_save(image, layer, filepath, '?') #pdb.file_xbm_save(RUN_NONINTERACTIVE, image, None, filename, filepath, '', 0, 0, 0) # find out how to properly call file_xbm_save so we can avoid this section with open(filepath, 'r+b') as file_h: lines = file_h.readlines() file_h.seek(0) for line in lines: if '_' in line: if '_hot' not in line: file_h.write(line.replace('_', prefix+'_')) else: file_h.write(line) file_h.truncate() pdb.gimp_image_delete(image) # necessary ? pdb.gimp_context_pop()
def create_base_alphabet(font, font_size, directory_base): suffix = '.xbm' for c_gen, c_prefix in ( (map(chr, xrange(ord('A'), ord('Z')+1)), 'upper'), (map(chr, xrange(ord('a'), ord('z')+1)), 'lower'), (map(chr, xrange(ord('0'), ord('9')+1)), 'number'), ): for c in c_gen: prefix = '%s%c' % (c_prefix, c) filename = '%s%s' % (prefix, suffix) image = gimp.Image(1, 1, INDEXED) image.disable_undo() # necessary ? pdb.gimp_context_push() gimp.set_foreground( (0.0, 0.0, 0.0) ) x = y = border = 0 layer = pdb.gimp_text_fontname(image, None, x, y, c, border, True, font_size, PIXELS, font) image.resize(layer.width, layer.height, 0, 0) filepath = join(directory_base, filename) pdb.gimp_file_save(image, layer, filepath, '?') #pdb.file_xbm_save(RUN_NONINTERACTIVE, image, None, filename, filepath, '', 0, 0, 0) # find out how to properly call file_xbm_save so we can avoid this crap with open(filepath, 'r+b') as file_h: lines = file_h.readlines() file_h.seek(0) for line in lines: if '_' in line: if '_hot' not in line: file_h.write(line.replace('_', prefix+'_')) else: file_h.write(line) file_h.truncate() pdb.gimp_image_delete(image) # necessary ? pdb.gimp_context_pop()