Esempio n. 1
0
def batch_xcf_to_png(file_pattern):
	#log_msg('pattern='+file_pattern)
	file_list=glob.glob(file_pattern)
	file_list.sort()
	for filename in file_list:
		#log_msg('filename='+filename)
		img = pdb.gimp_file_load(filename, filename)
                ind = find_graph_ind(img)
                #log_msg('ind='+str(ind))
                if ind:
                    img.layers[ind].visible = False
                    pne, ext = os.path.splitext(filename)
                    png_path = pne+'.png'
                    flat_layer = pdb.gimp_image_flatten(img)
                    log_msg('%s --> %s' % (filename, png_path))
                    pdb.gimp_file_save(img, flat_layer, png_path, png_path)  
##                     pdb.file_png_save(img, flat_layer, png_path, png_path, \
##                                       0, 9, 0, 0, 0, \
##                                       0, 0)                
		    #pdb.gimp_file_save(image, drawable, filename, filename)
		    pdb.gimp_image_delete(img)
Esempio n. 2
0
def my_save2(img, drawable):
    #log_msg('in my_save2')
    ind = find_graph_ind(img)

    if ind:
        img.layers[ind].visible = False
    else:
        log_msg('did not find a graph ind')
        
    folder = get_path_from_pkl()
    log_msg('folder='+str(folder))
    myint = get_notes_layer_slide_num(img)
    log_msg('myint='+str(myint))
    title_in = img.filename
    log_msg('title_in = %s' % title_in)
    new_name = None
    if title_in:
        folder_in, name_in = os.path.split(title_in)
        fno, ext = os.path.splitext(name_in)
        name_in = fno + '.png'
        #log_msg('name_in = %s' % name_in)
        #log_msg('folder_in = %s' % folder_in)
        cn = get_course_number()
        my_ind = name_in.find('ME'+cn)
        #log_msg('my_ind = %s' % my_ind)
        if my_ind == 0:
            #log_msg('in the good case')
            folder = folder_in
            new_name = name_in
    #log_msg('new_name = %s' % new_name)
    if new_name is None:
        new_name, slide_num = get_slide_num_filename(myint=myint)
    filename = save_as(initialdir=folder, initialfile=new_name)
    log_msg('filename = ' + filename)
    if filename:
        pne, ext = os.path.splitext(filename)
        xcf_path = pne+'.xcf'
        pdb.gimp_selection_all(img)
        pdb.gimp_edit_copy_visible(img)
        img2 = pdb.gimp_edit_paste_as_new()
        pdb.gimp_xcf_save(1, img, drawable, xcf_path, xcf_path)
        folder, xcf_name = os.path.split(xcf_path)
        xcf_path = xcf_path.encode()
        xcf_name = xcf_name.encode()
        #log_msg('xcf_name='+xcf_name)
        #log_msg('type(img.filename)=%s' % type(img.filename))
        #log_msg('type(xcf_name)=%s' % type(xcf_name))
        img.filename = xcf_path
        #pdb.gimp_file_save(img, drawable, xcf_path, xcf_path)
        flat_layer = pdb.gimp_image_flatten(img2)
        #gimp.Display(img2)
        pdb.gimp_file_save(img2, flat_layer, filename, filename)
        pdb.gimp_image_delete(img2)
        if ind:
            img.layers[ind].visible = True
        pdb.gimp_image_clean_all(img)
        gimp.displays_flush()
        log_msg('after clean all')