def file_load_lepton(filename, raw_filename):
    ''' Save the current layer into a PNG file, a JPEG file and a BMP file.

    Parameters:
    image : image The current image.
    layer : layer The layer of the image that is selected.
    file : string The file to open in a new layer.
    '''
    # Indicates that the process has started.
    gimp.progress_init("Opening '" + filename + "'...")

    try:
        tmpdirobj = mkdtemp()
        tmp_dirname = tmpdirobj
        jpeg_fn = os.path.join(tmp_dirname, "from_lep.jpeg")
        subprocess.check_call(["lepton", filename, jpeg_fn])
        fileImage = pdb.file_jpeg_load(jpeg_fn, filename)
        if (fileImage is None):
            gimp.message("The image could not be opened since" +
                         "it is not an image file.")
        shutil.rmtree(tmp_dirname)
        return fileImage
    except Exception as err:
        gimp.message("Unexpected error: " + str(err))
        raise err
Ejemplo n.º 2
0
def convert_image(target_dir, output_dir, image_name):
    '''
    Обрабатывает картинку.
    @param target_dir: string
    @param output_dir: string
    @param image_name: string
    '''
    output_path = os.path.join(output_dir, image_name)
    if os.path.exists(output_path):
        print '%s already exists, skipping'%image_name
        return
    image = pdb.file_jpeg_load(os.path.join(target_dir, image_name), image_name)
    layer = image.layers[0]
    # Выравниваем уровни:
    # pdb.gimp_levels_stretch(layer)
    # Добавляем нерезкую маску:
    # pdb.plug_in_unsharp_mask(image, layer, 5, 0.5, 0)
    # Изменяем размер картинки:
    width, height = get_image_new_dimensions(image)
    pdb.gimp_image_scale(image, width, height)
    # Автоматически увеличиваем контраст:
    pdb.plug_in_c_astretch(image, layer)
    # Повышаем резкость:
    pdb.plug_in_sharpen(image, layer, 50)
    pdb.gimp_file_save(image, layer, output_path, image_name)
    pdb.gimp_image_delete(image)