(img, layer, res_folder, folder_prefix, image_basename, target_width, x_ldpi, x_mdpi, x_hdpi, x_xhdpi, x_xxhdpi, x_xxxhdpi, allow_upscale, image_extension)
Resize and write images for all android density folders 
    
    @param img: gimp image
    @param layer: gimp layer (or drawable)
    @param res_folder: output directory : basically res folder of your android project 
    @param folder_prefix: android mipmap or drawable folder
    @param image_basename: basename of your image, ex: icon
    @param target_width: new width for your image
    @param target_dpi: reference density for your target width
    @param allow_upscale: whether to create upscaled images
    @param image_extension: output format
Resize and write images for all android density folders
Resize and write images for all android density folders
def write_xdpi(img, layer, res_folder, folder_prefix, image_basename, target_width, x_ldpi, x_mdpi, x_hdpi, x_xhdpi, x_xxhdpi, x_xxxhdpi, allow_upscale, image_extension):
    '''
    Resize and write images for all android density folders 
    
    @param img: gimp image
    @param layer: gimp layer (or drawable)
    @param res_folder: output directory : basically res folder of your android project 
    @param folder_prefix: android mipmap or drawable folder
    @param image_basename: basename of your image, ex: icon
    @param target_width: new width for your image
    @param target_dpi: reference density for your target width
    @param allow_upscale: whether to create upscaled images
    @param image_extension: output format
    '''
    
    warnings = list()
    
    gimpfu.pdb.gimp_edit_copy_visible(img); #@UndefinedVariable
    
    dpi_ratios = (('ldpi',    0.75 ,x_ldpi),
                  ('mdpi',    1    ,x_mdpi),
                  ('tvdpi',   1.33 ,False),
                  ('hdpi',    1.5  ,x_hdpi),
                  ('xhdpi',   2    ,x_xhdpi),
                  ('xxhdpi',  3    ,x_xxhdpi),
                  ('xxxhdpi', 4    ,x_xxxhdpi))

    for folder, ratio, export in dpi_ratios:
        if not export: 
            continue

        new_img = gimpfu.pdb.gimp_edit_paste_as_new(); #@UndefinedVariable
        
        resize_ratio = float(target_width) / new_img.width
        target_dp_width = target_width
        target_dp_height = round(new_img.height * resize_ratio)
        
        # Compute new dimensions for the image
        new_width = target_dp_width * ratio
        new_height = target_dp_height * ratio
        
        print('%s : %dx%d' % (folder, new_width, new_height))
        
        if (new_width>new_img.width):
            if not allow_upscale:
                warnings.append('Not creating resource for %s upscaled by %0.2f' %
                            (folder, new_width/new_img.width))
                continue
            else:
                warnings.append('Resource for %s has been upscaled by %0.2f' %
                            (folder, new_width/new_img.width))

        target_res_folder = os.path.join(res_folder, folder_prefix + '-' + folder)
        if (os.path.exists(res_folder) and not os.path.exists(target_res_folder)):
            os.makedirs(target_res_folder)

        target_res_filename = os.path.join(target_res_folder, image_basename + '.' + image_extension)
        
        # Save the new Image
        gimpfu.pdb.gimp_image_scale_full( #@UndefinedVariable
            new_img, new_width, new_height, gimpfu.INTERPOLATION_CUBIC)
        
        gimpfu.pdb.gimp_file_save( #@UndefinedVariable
            new_img, new_img.layers[0], target_res_filename, target_res_filename)
        
        gimpfu.pdb.gimp_image_delete(new_img) #@UndefinedVariable
        
    # Show warning message
    if warnings: 
        warnings.append(UPSCALE_WARN_MESSAGE)
        gimp.message('\n'.join(warnings))
def write_xdpi ( img , layer , res_folder , folder_prefix , image_basename , target_width , x_ldpi , x_mdpi , x_hdpi , x_xhdpi , x_xxhdpi , x_xxxhdpi , allow_upscale , image_extension ) : warnings = list ( ) gimpfu . pdb . gimp_edit_copy_visible ( img ) #@UndefinedVariable dpi_ratios = ( ( 'ldpi' , 0.75 , x_ldpi ) , ( 'mdpi' , 1 , x_mdpi ) , ( 'tvdpi' , 1.33 , False ) , ( 'hdpi' , 1.5 , x_hdpi ) , ( 'xhdpi' , 2 , x_xhdpi ) , ( 'xxhdpi' , 3 , x_xxhdpi ) , ( 'xxxhdpi' , 4 , x_xxxhdpi ) ) for folder , ratio , export in dpi_ratios : if not export : continue new_img = gimpfu . pdb . gimp_edit_paste_as_new ( ) #@UndefinedVariable resize_ratio = float ( target_width ) / new_img . width target_dp_width = target_width target_dp_height = round ( new_img . height * resize_ratio ) # Compute new dimensions for the image new_width = target_dp_width * ratio new_height = target_dp_height * ratio print ( '%s : %dx%d' % ( folder , new_width , new_height ) ) if ( new_width > new_img . width ) : if not allow_upscale : warnings . append ( 'Not creating resource for %s upscaled by %0.2f' % ( folder , new_width / new_img . width ) ) continue else : warnings . append ( 'Resource for %s has been upscaled by %0.2f' % ( folder , new_width / new_img . width ) ) target_res_folder = os . path . join ( res_folder , folder_prefix + '-' + folder ) if ( os . path . exists ( res_folder ) and not os . path . exists ( target_res_folder ) ) : os . makedirs ( target_res_folder ) target_res_filename = os . path . join ( target_res_folder , image_basename + '.' + image_extension ) # Save the new Image gimpfu . pdb . gimp_image_scale_full ( #@UndefinedVariable new_img , new_width , new_height , gimpfu . INTERPOLATION_CUBIC ) gimpfu . pdb . gimp_file_save ( #@UndefinedVariable new_img , new_img . layers [ 0 ] , target_res_filename , target_res_filename ) gimpfu . pdb . gimp_image_delete ( new_img ) #@UndefinedVariable # Show warning message if warnings : warnings . append ( UPSCALE_WARN_MESSAGE ) gimp . message ( '\n' . join ( warnings ) )