Exemplo n.º 1
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)
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()
Exemplo n.º 4
0
from gimpfu import pdb

filename = "hall_of_fame_large.xcf"
image = pdb.gimp_file_load(filename, filename)
pdb.gimp_image_scale(image, 1280, 800)
outfilename = "hall_of_fame.png"
layer = pdb.gimp_image_merge_visible_layers(image, 1)
pdb.gimp_file_save(image, layer, outfilename, outfilename)
Exemplo n.º 5
0
def despeckle(fin, fout):
    image = pdb.gimp_file_load(fin, fin)
    drawable = pdb.gimp_image_get_active_layer(image)
    pdb.plug_in_despeckle(image, drawable, 3, 1, 7, 248)
    pdb.gimp_file_save(image, drawable, fout, fout)
    pdb.gimp_image_delete(image)
Exemplo n.º 6
0
    def __flattenAndSaveImage(self):
        """
		Flatten the current image and then save it to file.

		Instruct GIMP to flatten the current image by collapsing all of the image's layers down into one layer and then saving the resulting image to file.


		Parameters:

		NA


		Returns:

		NA


		Invoked by :

		__run


		Invokes :

		__pauseAndProgressDisplay

		"""

        nameProcedure = "OverlayImageAgent::flattenAndSaveImage"

        print("%s : Enter" % (nameProcedure))

        if (type(self.image_background) is not gimp.Image):

            exception_message = "\n\nAn Exception has been raised by the method;\n\n  " + \
                                nameProcedure + \
                                "\n\n" + \
                                "This method is attempting to flatten an Object which is not an Image." + \
                                "\n\n" + \
                                "Object is of type : " + type(self.image_background) + \
                                "As a result, this Plugin is about to terminate!"

            raise Exception(exception_message)

        # Flatten the modified background image down into one layer.

        drawable_background = pdb.gimp_image_flatten(self.image_background)

        message = "<span foreground=\"black\" style=\"italic\"> Have flattened the image : " + self.image_background.filename + "</span>"

        self.__displayDiagnosticData(message)

        gimp.progress_init("Have flattened the background image")

        self.__pauseAndProgressDisplay(self.sleep_timer)

        # Save the background image into the specified file.

        pdb.gimp_file_save(self.image_background, drawable_background,
                           self.filename_result, self.filename_result)

        gimp.progress_init("Have saved the background image")

        self.__pauseAndProgressDisplay(self.sleep_timer)

        print("%s : Enter" % (nameProcedure))
Exemplo n.º 7
0
def flip(file):
    image = pdb.gimp_file_load(file, file)
    drawable = pdb.gimp_image_get_active_layer(image)
    pdb.gimp_image_flip(image, ORIENTATION_HORIZONTAL)
    pdb.gimp_file_save(image, drawable, file, file)
    pdb.gimp_image_delete(image)