Example #1
0
    def create_selection_image(self):
        vreturn = self.existImage()
        if not vreturn['isOk']:
            self.conn.send(json.dumps(vreturn))
            return
        image = vreturn['image']
        vreturn = self.isTifImage()
        if not vreturn['isOk']:
            self.conn.send(json.dumps(vreturn))
            return
        is_empty = pdb.gimp_selection_is_empty(image)
        if is_empty == 1:
            self.conn.send(
                json.dumps({
                    'isOk': False,
                    'msg': "No selection in '%s'" % self.filename
                }))
            return

        non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)
        selimage = image.selection.image.duplicate()
        selimage.crop(x2 - x1, y2 - y1, x1, y1)
        pdb.gimp_selection_sharpen(selimage)
        channel = pdb.gimp_selection_save(selimage)
        filename = "%s_select.tif" % path.splitext(self.filename)[0]
        pdb.file_tiff_save(selimage, channel, filename, "", 0)
        pdb.gimp_image_delete(selimage)
        #
        vreturn = {'isOk': True, 'tiePoint': (x1, y1), 'filename': filename}
        self.conn.send(json.dumps(vreturn))
  def create_selection_image(self):
    vreturn = self.existImage()
    if not vreturn['isOk']:
      self.conn.send( json.dumps( vreturn ) )
      return
    image = vreturn['image']
    vreturn = self.isTifImage()
    if not vreturn['isOk']:
      self.conn.send( json.dumps( vreturn ) )
      return
    is_empty = pdb.gimp_selection_is_empty( image )
    if is_empty == 1:
      self.conn.send( json.dumps( { 'isOk': False, 'message': "No selection in '%s'" % self.pathfileImage } ) )
      return

    non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds( image )
    selimage = image.selection.image.duplicate()
    selimage.crop( x2 - x1, y2 - y1, x1, y1 )
    pdb.gimp_selection_sharpen( selimage )
    channel = pdb.gimp_selection_save( selimage )
    pdb.file_tiff_save( selimage, channel, self.pathfileImageSelect, "", 0)
    pdb.gimp_image_delete( selimage )
    #
    data = {
      'isOk': True,
      'ulPixelSelect': { 'X': x1, 'Y': y1 }
    }
    data.update( self.paramImage )
    self.conn.send( json.dumps( data ) )
Example #3
0
def change_num(image, inNumero):
    layer = pdb.gimp_image_get_active_layer(image)

    pdb.gimp_context_set_sample_transparent(True)
    pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE,layer, 1, 1)
    pdb.gimp_selection_invert(image)
    _, x, y, x2, y2  = pdb.gimp_selection_bounds(image)
    xthird=x  + ((x2 - x) // 4  * 3)

    y = _find_black_not_transparent(image, layer, xthird, y)

    pdb.gimp_context_set_sample_transparent(False)
    pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE, layer, xthird, y)
    pdb.gimp_edit_clear(layer)
                    
    if inNumero > 1:        
        _, x, y, x2, y2  = pdb.gimp_selection_bounds(image)
        ymiddle = y + ( (y2 - y) // 2)

        keep = True
        while keep:
            if not _is_transparent(image, layer, x, ymiddle):
                keep = False
                pdb.gimp_context_set_sample_transparent(False)
                pdb.gimp_context_set_sample_threshold(1)
                pdb.gimp_image_select_contiguous_color(image, CHANNEL_OP_REPLACE, layer, x+1, ymiddle)
                pdb.gimp_context_set_sample_threshold(0.1)
 
            x += 1
        pdb.gimp_edit_clear(layer)

        _, x1, y1, x2, y2  = pdb.gimp_selection_bounds(image)
        
        pdb.gimp_image_select_rectangle(image, CHANNEL_OP_REPLACE, x1, y1, x2-x1, y2-y1)
        
        filename = GRAPH_PATH + str(inNumero) + ".png"

        imagechiffre = pdb.gimp_file_load(filename, filename)
        layerchiffre = pdb.gimp_image_get_active_layer(imagechiffre)
        
        pdb.gimp_selection_all(imagechiffre)
        pdb.gimp_edit_copy(layerchiffre)
        pdb.gimp_image_delete(imagechiffre)
        
        floating_sel = pdb.gimp_edit_paste(layer,False)
        pdb.gimp_floating_sel_anchor(floating_sel)
def load_caches(args):
    inColorFondR, inColorFondG, inColorFondB, outDir = args.split(" ")
    inDir, inNameLayerFleche = GRAPH_PATH + "layers/", "layer_fleche-1.png"
    inColorFondR, inColorFondG, inColorFondB = int(inColorFondR), int(
        inColorFondG), int(inColorFondB)

    nb, listimg = pdb.file_glob(inDir + "*.png", 1)
    baseimage = pdb.gimp_image_new(10, 10, RGB)
    fondcolor = (inColorFondR, inColorFondG, inColorFondB)

    for filename in listimg:
        layer = pdb.gimp_file_load_layer(baseimage, filename)
        pdb.gimp_image_insert_layer(baseimage, layer, None, 0)

    pdb.gimp_image_resize_to_layers(baseimage)
    pdb.gimp_message("Layers chargés")
    pdb.gimp_selection_all(baseimage)

    layerfond = pdb.gimp_image_get_layers(baseimage)[1][0]
    layerfond = gimp.Item.from_id(layerfond)
    fond = pdb.gimp_layer_copy(layerfond, 1)
    _, _, _, xmax, ymax = pdb.gimp_selection_bounds(baseimage)

    pdb.gimp_item_set_name(fond, "layer_fond.png")
    pdb.gimp_image_insert_layer(baseimage, fond, None, 0)

    pdb.gimp_edit_clear(fond)
    pdb.gimp_image_select_round_rectangle(baseimage, CHANNEL_OP_REPLACE, 0, 0,
                                          xmax, ymax, 35, 35)
    pdb.gimp_selection_shrink(baseimage, 3)
    pdb.gimp_selection_feather(baseimage, 20)
    pdb.gimp_context_set_foreground(fondcolor)
    pdb.gimp_edit_fill(fond, FILL_FOREGROUND)
    pdb.gimp_image_lower_item_to_bottom(baseimage, fond)
    pdb.plug_in_hsv_noise(baseimage, fond, 5, 38, 63, 74)
    pdb.gimp_selection_none(baseimage)
    pdb.gimp_message("Fond créé")
    caches(baseimage, inNameLayerFleche, "layer_fond.png")
    pdb.gimp_message("Cache créé")

    layercache = pdb.gimp_image_get_layer_by_name(baseimage, "cache.png")
    layerfond = pdb.gimp_image_get_layer_by_name(baseimage, "layer_fond.png")
    layerfleche = pdb.gimp_image_get_layer_by_name(baseimage,
                                                   inNameLayerFleche)

    pdb.gimp_item_set_visible(layerfond, True)
    pdb.gimp_image_merge_down(baseimage, layercache, CLIP_TO_IMAGE)
    pdb.gimp_item_set_visible(layerfleche, True)
    pdb.gimp_image_merge_down(baseimage, layerfleche, CLIP_TO_IMAGE)

    pdb.gimp_image_scale(baseimage, 900, 550)
    # drawable = pdb.gimp_image_get_active_drawable(baseimage)
    pdb.script_fu_multiple_layer_actions(baseimage, None, 0, 0, (0, 0, 0), 4,
                                         0, 0, 0, 0, 0)
    pdb.gimp_message("Taille de l'image ajustée")

    pdb.script_fu_export_layers(baseimage, None, outDir, "~l")
    pdb.gimp_message("Layers enregistrés")
Example #5
0
def effet_texte(inColor, inImg):
    layer = pdb.gimp_image_get_active_layer(inImg)
    
    pdb.gimp_context_set_sample_transparent(True)
    pdb.gimp_image_select_contiguous_color(inImg, CHANNEL_OP_REPLACE, layer, 1, 1)
    pdb.gimp_selection_invert(inImg)

    _, x, _, x2, y2  = pdb.gimp_selection_bounds(inImg)
    xmiddle = x + (x2 - x) // 2
    y = y2 - 1
        
    keep = True
    while keep:
        if y < 0:
            print("Error in effet_texte for img {} : y < 0 !".format(inImg))
            return
        if (not _is_transparent(inImg, layer, xmiddle, y)) and  _is_black(inImg, layer, xmiddle, y):
            keep = False
            pdb.gimp_context_set_sample_transparent(False)
            pdb.gimp_image_select_contiguous_color(inImg, CHANNEL_OP_REPLACE, layer, xmiddle, y)
            pdb.gimp_edit_clear(layer)
                
        y -= 1

    _, x1, y1, x2, y2  = pdb.gimp_selection_bounds(inImg)
    newlayer = pdb.gimp_layer_copy(layer, True)

    pdb.gimp_image_select_rectangle(inImg, CHANNEL_OP_REPLACE, x1, y1, x2-x1, y2-y1)
    pdb.gimp_context_set_sample_transparent(True)
    pdb.gimp_image_select_contiguous_color(inImg, CHANNEL_OP_SUBTRACT, layer, x1, y1)
    pdb.gimp_edit_clear(layer)
    
    pdb.gimp_selection_invert(inImg)
    pdb.gimp_image_insert_layer(inImg, newlayer, None, 0)
    pdb.gimp_edit_clear(newlayer)
    
    pdb.script_fu_layerfx_outer_glow(inImg, newlayer, inColor, 75, 0, 0, 0, 0, 5, 0, 1)
    pdb.gimp_image_merge_visible_layers(inImg, CLIP_TO_IMAGE)
    
    pdb.gimp_selection_none(inImg)
    pdb.gimp_displays_flush()
Example #6
0
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
Example #7
0
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 cutter_single_image(
        image, drawable,
        limit, sl_thresh, sz_thresh,
        bg_manual, bg_color, bg_corner, bg_x, bg_y,
        padding, deskew, sq_crop, autoclose,
        save_same, save_dir, save_ftype, save_dpi, jpg_qual, save_suffix
    ):
    img_width = pdb.gimp_image_width(image)
    img_height = pdb.gimp_image_height(image)
    img_fullpath = pdb.gimp_image_get_filename(image)
    img_filename = os.path.basename(img_fullpath)
    img_name = '.'.join(img_filename.split('.')[:-1])
    img_ext = save_ftype or img_filename.split('.')[-1].lower()
    new_filename_tpl = ''.join([
        img_name, '-', save_suffix, '-',
        '%0', str(len(str(int(limit + 1)))), 'd',
        '.', img_ext
    ])
    new_fullpath_tpl = os.path.join(
        os.path.dirname(img_fullpath) if save_same else save_dir,
        new_filename_tpl
    )

    # gimp.message(new_fullpath_tpl)

    # function code goes here...
    gimp.context_push()
    pdb.gimp_image_undo_disable(image)

    # If the background wasn't manually defined, pick the colour from one of the four corners
    # (using radius 5 average)
    if not bg_manual:
        if bg_corner in (1, 3):
            bg_x = img_width - bg_x
        if bg_corner in (2, 3):
            bg_y = img_height - bg_y

        bg_color = pdb.gimp_image_pick_color(image, drawable, bg_x, bg_y, True, True, 5)

    pdb.gimp_context_set_defaults()
    pdb.gimp_context_set_antialias(True)
    pdb.gimp_context_set_sample_transparent(True)
    pdb.gimp_context_set_sample_threshold_int(sl_thresh)
    pdb.gimp_context_set_feather(True)
    fr = min(img_width, img_height) / 100.0     # NOTE why???
    pdb.gimp_context_set_feather_radius(fr, fr)
    pdb.gimp_context_set_background(bg_color)

    pdb.gimp_image_select_color(image, gimpfu.CHANNEL_OP_REPLACE, drawable, bg_color)

    # convert inverted copy of the background selection to a path
    pdb.gimp_selection_sharpen(image)
    pdb.gimp_selection_invert(image)

    # _, before = pdb.gimp_image_get_vectors(image)
    pdb.plug_in_sel2path(image, drawable)
    # _, after = pdb.gimp_image_get_vectors(image)
    # newpath_id = list(set(after) - set(before))[0]
    # newpath = gimp.Vectors.from_id(newpath_id)

    # looks like newly created vector is always active, so this should be sufficent
    newpath = pdb.gimp_image_get_active_vectors(image)

    pdb.gimp_context_set_feather(False)

    _, strokes = pdb.gimp_vectors_get_strokes(newpath)
    extracted = 0
    for stroke_id in strokes:
        stroke_points = pdb.gimp_vectors_stroke_get_points(newpath, stroke_id)
        # skip not closed paths
        if not stroke_points[3]:
            continue

        temp_vector = pdb.gimp_vectors_new(image, '-temp-')
        pdb.gimp_image_insert_vectors(image, temp_vector, None, -1)

        pdb.gimp_vectors_stroke_new_from_points(temp_vector, *stroke_points)
        pdb.gimp_image_select_item(image, gimpfu.CHANNEL_OP_REPLACE, temp_vector)
        pdb.gimp_image_remove_vectors(image, temp_vector)

        # check for minimum size
        bounds = pdb.gimp_selection_bounds(image)
        sizex = bounds[3] - bounds[1]
        sizey = bounds[4] - bounds[2]

        if (min(sizex, sizey) < sz_thresh or
                sizex >= img_width or
                sizey >= img_height):
            continue

        buffname = "dsibuff"
        if deskew and pdb.gimp_procedural_db_proc_exists('gimp_deskew_plugin'):
            pdb.gimp_progress_set_text('Running deskew plugin...')
            pdb.gimp_image_select_rectangle(
                image, gimpfu.CHANNEL_OP_REPLACE,
                bounds[1], bounds[2], sizex, sizey
            )
            buffname = pdb.gimp_edit_named_copy(drawable, buffname)
            temp_image = pdb.gimp_edit_named_paste_as_new(buffname)
            temp_layer = pdb.gimp_image_get_active_layer(temp_image)
            pdb.gimp_image_undo_disable(temp_image)

            pdb.gimp_layer_flatten(temp_layer)

            # RUN_NONINTERACTIVE causes 'calling error' exception
            pdb.gimp_deskew_plugin(temp_image, temp_layer, 0, 0, 0, 0, True,
                                   run_mode=gimpfu.RUN_INTERACTIVE)

            pdb.gimp_image_resize_to_layers(temp_image)
            pdb.gimp_layer_flatten(temp_layer)

            pdb.gimp_image_select_contiguous_color(
                temp_image, gimpfu.CHANNEL_OP_REPLACE, temp_layer, 0, 0
            )
            pdb.gimp_selection_invert(temp_image)
            bounds = pdb.gimp_selection_bounds(temp_image)
            sizex = bounds[3] - bounds[1]
            sizey = bounds[4] - bounds[2]
            pdb.gimp_selection_none(temp_image)
            pdb.gimp_image_crop(temp_image, sizex, sizey, bounds[1], bounds[2])

            if (sq_crop and sizex != sizey
                    and pdb.gimp_procedural_db_proc_exists('script_fu_addborder')):
                if sizex > sizey:
                    dx = 0
                    dy = (sizex - sizey) * 0.5
                else:
                    dx = (sizey - sizex) * 0.5
                    dy = 0

                pdb.script_fu_addborder(temp_image, temp_layer, dx, dy, bg_color, 0)
                pdb.gimp_image_raise_item_to_top(temp_image, temp_layer)
                pdb.gimp_image_merge_visible_layers(temp_image, gimpfu.EXPAND_AS_NECESSARY)
                temp_layer = pdb.gimp_image_get_active_layer(temp_image)
        else:
            temp_image = image
            pdb.gimp_image_undo_disable(temp_image)
            temp_layer = pdb.gimp_image_get_active_layer(temp_image)

            if sq_crop:
                c_x = 0.5 * (bounds[1] + bounds[3])
                c_y = 0.5 * (bounds[2] + bounds[4])
                hl = padding + max(sizex, sizey) * 0.5
                sel_x = c_x - hl
                sel_y = c_y - hl
                sel_w = sel_h = 2 * hl
            else:
                sel_x = bounds[1]
                sel_y = bounds[2]
                sel_w = sizex
                sel_h = sizey

            pdb.gimp_image_select_rectangle(
                temp_image, gimpfu.CHANNEL_OP_REPLACE,
                sel_x, sel_y, sel_w, sel_h
            )
            buffname = pdb.gimp_edit_named_copy(drawable, buffname)
            temp_image = pdb.gimp_edit_named_paste_as_new(buffname)
            temp_layer = pdb.gimp_image_get_active_layer(temp_image)

        if padding and pdb.gimp_procedural_db_proc_exists('script_fu_addborder'):
            pdb.script_fu_addborder(temp_image, temp_layer, padding, padding, bg_color, 0)
            pdb.gimp_image_merge_visible_layers(temp_image, gimpfu.EXPAND_AS_NECESSARY)
            temp_layer = pdb.gimp_image_get_active_layer(temp_image)

        pdb.gimp_image_undo_enable(temp_image)
        temp_display = pdb.gimp_display_new(temp_image)

        extracted += 1

        filename = new_fullpath_tpl % (extracted, )
        pdb.gimp_image_set_resolution(temp_image, save_dpi, save_dpi)
        if img_ext == 'jpg':
            pdb.file_jpeg_save(
                temp_image, temp_layer, filename, filename,
                jpg_qual, 0.1, 1, 1, '', 2, 0, 0, 1
            )
        else:
            pdb.gimp_file_save(temp_image, temp_layer, filename, filename)

        if autoclose:
            pdb.gimp_display_delete(temp_display)

        if extracted >= limit:
            break

    pdb.gimp_progress_set_text('Extracted %d images' % (extracted, ))

    pdb.gimp_image_remove_vectors(image, newpath)
    pdb.gimp_selection_none(image)

    pdb.gimp_image_undo_enable(image)
    pdb.gimp_progress_end()
    pdb.gimp_displays_flush()
    gimp.context_pop()

    return extracted
Example #9
0
    def create_selection_image(self, socket):
        def existImage():
            if self.pathfileImage in self.addedImages:
                image = self.addedImages[self.pathfileImage]['image']
                if pdb.gimp_image_is_valid(image):
                    return {'isOk': True, 'image': image}
            images = gimp.image_list()
            if len(images) == 0:
                return {'isOk': False, 'message': "Not exist images"}
            images_by_filename = [
                item for item in images if item.filename == self.pathfileImage
            ]
            del images
            if len(images_by_filename) == 0:
                return {
                    'isOk': False,
                    'message':
                    "Not exist image '{}'".format(self.pathfileImage)
                }
            image = images_by_filename[0]
            del images_by_filename
            if not pdb.gimp_image_is_valid(image):
                return {
                    'isOk': False,
                    'message':
                    "Image '{}' is not valid".format(self.pathfileImage)
                }
            return {'isOk': True, 'image': image}

        r = existImage()
        if not r['isOk']:
            socket.send(json.dumps(r))
            return
        image = r['image']
        r = self._isTifImage()
        if not r['isOk']:
            socket.send(json.dumps(r))
            return
        is_empty = pdb.gimp_selection_is_empty(image)
        if is_empty == 1:
            data = {
                'isOk': False,
                'message': "No selection in '{}'".format(self.pathfileImage)
            }
            socket.send(json.dumps(data))
            return

        _non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)
        # Verify Version
        sel_image = image.duplicate(
        ) if self.isVersion2_10 else image.selection.image.duplicate()
        #
        sel_image.crop(x2 - x1, y2 - y1, x1, y1)
        pdb.gimp_selection_sharpen(sel_image)
        channel = pdb.gimp_selection_save(sel_image)
        # Verify Version
        if self.isVersion2_10:
            sel_layer = pdb.gimp_selection_float(
                channel, 0, 0)  # Add selection how top layer
            pdb.gimp_image_remove_layer(
                sel_image, sel_image.layers[-1])  # Remove original layer
            pdb.file_tiff_save(sel_image, sel_layer, self.pathfileImageSelect,
                               '', 0)
        else:
            pdb.file_tiff_save(sel_image, channel, self.pathfileImageSelect,
                               "", 0)
        #
        pdb.gimp_image_delete(sel_image)
        data = {'isOk': True, 'ulPixelSelect': {'X': x1, 'Y': y1}}
        data.update(self.paramImage)
        socket.send(json.dumps(data))
Example #10
0
def halftone_gimp(img, layer, slide_density, slide_circle_size, work_size_flag,
                  work_size_width, revert_size_flag, black_strength,
                  slide_angle):
    # Obtain layer dimensions.
    width = layer.width
    height = layer.height
    print("original size:", width, height)

    print("density", slide_density)
    D = int(slide_density)

    print("circle size", "slide_circle_size")
    C = int(slide_circle_size)

    print("black strength", black_strength)
    B = int(black_strength)

    ANGLES = POSSIBLE_ANGLES[int(slide_angle) - 1]
    print("angles", ANGLES)

    # New image dimensions
    if work_size_flag is True:
        new_width = int(work_size_width)
        new_height = int(height * (new_width / float(width)))
        print("new_size:", new_width, new_height)
        scale_image(img, new_width, new_height)
    else:
        new_width = width
        new_height = height

    add_cmyk_layers(img, layer)

    halftone_layers = [None] * 4
    for k in range(0, 4):
        current_layer = find_layer(img, COMPONENT_STRING[k])
        rotate_layer(current_layer, ANGLES[k])
        halftone_layers[k] = pdb.gimp_layer_new(
            img, current_layer.width, current_layer.height, RGBA_IMAGE,
            COMPONENT_STRING[k] + " halftone", 100, MULTIPLY_MODE)

        pdb.gimp_image_insert_layer(img, halftone_layers[k], None, 0)
        pdb.gimp_drawable_fill(halftone_layers[k], FILL_WHITE)

        start = timer()
        halftone_layer(img, current_layer, halftone_layers[k], D, COLORS[k], C,
                       B)
        end = timer()
        print("halftone in ", end - start)
        rotate_layer(halftone_layers[k], -ANGLES[k])
        x0, y0 = pdb.gimp_drawable_offsets(halftone_layers[k])
        non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(img)
        print(x0, y0)
        print(x1, y1, x2, y2)
        xx = new_width / 2 - current_layer.width / 2
        yy = new_height / 2 - current_layer.height / 2

        # print xx, yy
        pdb.gimp_layer_set_offsets(halftone_layers[k], x0 + xx, y0 + yy)

    for i_layer in COMPONENT_STRING:
        del_layer = find_layer(img, i_layer)
        img.remove_layer(del_layer)

    for i_layer in img.layers:
        if i_layer.name.endswith("halftone"):
            i_layer.visible = False
            # if revert_size_flag is True:
            #    scale_image(img, width, height)
        else:
            i_layer.visible = False

    for i_layer in img.layers:
        if i_layer.name.endswith("halftone"):
            current_layer = pdb.gimp_layer_new(img, new_width, new_height,
                                               RGBA_IMAGE,
                                               "_" + i_layer.name + "_", 100,
                                               MULTIPLY_MODE)
            pdb.gimp_image_insert_layer(img, current_layer, None, 0)
            pdb.gimp_rect_select(img, 0, 0, new_width, new_height, 2, 0, 0)
            pdb.gimp_edit_copy(i_layer)
            new_layer = pdb.gimp_edit_paste(current_layer, True)
            pdb.gimp_floating_sel_anchor(new_layer)

    for i_layer in img.layers:
        if i_layer.name.endswith("halftone"):
            print(i_layer.name)
            img.remove_layer(i_layer)

    if revert_size_flag is True:
        scale_image(img, width, height)