def prepare_drivethrucards(img, drawable, output_folder): """ Prepare an image for DriveThruCards printing. """ gimp.progress_init('Prepare an image for DriveThruCards printing...') pdb.gimp_undo_push_group_start(img) try: file_name, back_side = _get_filename_backside(img, 'jpg') except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return rotation = _get_rotation(drawable) clip_size = _get_dtc_clip_size(drawable) if rotation: _rotate(drawable, back_side) if clip_size: _clip(img, drawable, clip_size, rotation and back_side) pdb.file_jpeg_save(img, drawable, os.path.join(output_folder, file_name), file_name, 1, 0, 1, 0, '', 2, 1, 0, 0) pdb.gimp_undo_push_group_end(img)
def prepare_makeplayingcards(img, drawable, output_folder): """ Prepare an image for MakePlayingCards printing. """ gimp.progress_init('Prepare an image for MakePlayingCards printing...') pdb.gimp_undo_push_group_start(img) try: file_name, back_side = _get_filename_backside(img) except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return rotation = _get_rotation(drawable) clip_size = _get_mpc_clip_size(drawable) if rotation: _rotate(drawable, back_side) if clip_size: _clip(img, drawable, clip_size, rotation and back_side) pdb.file_png_save(img, drawable, os.path.join(output_folder, file_name), file_name, 0, 9, 1, 0, 0, 1, 1) pdb.gimp_undo_push_group_end(img)
def prepare_db_output(img, drawable, output_folder): """ Prepare an image for DB output. """ gimp.progress_init('Prepare an image for DB output...') pdb.gimp_undo_push_group_start(img) try: file_name, _ = _get_filename_backside(img) except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return pdb.script_fu_round_corners(img, drawable, 40, 0, 0, 0, 0, 0, 0) pdb.file_png_save(img, drawable, os.path.join(output_folder, file_name), file_name, 0, 9, 1, 0, 0, 1, 1) pdb.gimp_undo_push_group_end(img)
def prepare_generic_png(img, drawable, output_folder): """ Prepare a generic PNG image. """ gimp.progress_init('Prepare a generic PNG image...') pdb.gimp_undo_push_group_start(img) try: file_name, back_side = _get_filename_backside(img, 'png') except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return rotation = _get_rotation(drawable) if rotation: _rotate(drawable, back_side) pdb.file_png_save(img, drawable, os.path.join(output_folder, file_name), file_name, 0, 9, 1, 0, 0, 1, 1) pdb.gimp_undo_push_group_end(img)
def prepare_mbprint_jpg(img, drawable, output_folder): """ Prepare a JPG image for MBPrint printing. """ gimp.progress_init('Prepare a JPG image for MBPrint printing...') pdb.gimp_undo_push_group_start(img) try: file_name, back_side = _get_filename_backside(img, 'jpg') except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return rotation = _get_rotation(drawable) if rotation: _rotate(drawable, back_side) pdb.file_jpeg_save(img, drawable, os.path.join(output_folder, file_name), file_name, 1, 0, 1, 0, '', 2, 1, 0, 0) pdb.gimp_undo_push_group_end(img)
def cut_bleed_margins(img, drawable, output_folder): """ Cut bleed margins from an image. """ gimp.progress_init('Cut bleed margins from an image...') pdb.gimp_undo_push_group_start(img) try: file_name, _ = _get_filename_backside(img) except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return clip_size = _get_bleed_margin_size(drawable) if clip_size: _clip(img, drawable, clip_size, False) pdb.file_png_save(img, drawable, os.path.join(output_folder, file_name), file_name, 0, 9, 1, 0, 0, 1, 1) pdb.gimp_undo_push_group_end(img)
def prepare_pdf_front(img, drawable, output_folder): """ Prepare a front image for PDF document. """ gimp.progress_init('Prepare a front image for PDF document...') pdb.gimp_undo_push_group_start(img) try: file_name, back_side = _get_filename_backside(img) except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return if back_side: pdb.gimp_undo_push_group_end(img) return rotation = _get_rotation(drawable) margin_size = _get_pdf_margin_size(drawable) if rotation: _rotate(drawable, back_side) _add_margin(img, drawable, margin_size) pdb.file_png_save(img, drawable, os.path.join(output_folder, file_name), file_name, 0, 9, 1, 0, 0, 1, 1) pdb.gimp_undo_push_group_end(img)
def \ scale_and_set_size_interactive( image, drawable, horizontalResolution, verticalResolution, scalingFactorPreference, horizontalOffset, verticalOffset, interpolationMode, filename ) : nameFunction = "scale_and_set_size_noninteractive" print("%s : Enter" % (nameFunction)) gimp.progress_init("Scaling and setting the size of image : " + image.filename) # Start a GIMP Undo group, as this will allow the actions of this Plugin to be undone in one step. pdb.gimp_undo_push_group_start(image) scaleAndSetSizeObject = ScaleAndSetSizeObject( image, drawable, horizontalResolution, verticalResolution, scalingFactorPreference, horizontalOffset, verticalOffset, interpolationMode, filename) scaleAndSetSizeObject.run() # End the GIMP Undo group. pdb.gimp_undo_push_group_end(image) print("%s : Exit" % (nameFunction))
def prepare_tts(img, _, output_folder): # pylint: disable=R0914 """ Prepare a TTS sheet image. """ gimp.progress_init('Prepare a TTS sheet image...') pdb.gimp_undo_push_group_start(img) try: file_name, _ = _get_filename_backside(img, 'jpg') except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return parts = file_name.split('_') num = int(parts[-3]) rows = int(parts[-4]) columns = int(parts[-5]) new_width = columns * 750 new_height = rows * 1050 pdb.gimp_image_scale(img, new_width, new_height) json_path = re.sub(r'\.jpg$', '.json', pdb.gimp_image_get_filename(img)) try: with open(json_path, 'r') as fobj: cards = json.load(fobj) except Exception: # pylint: disable=W0703 pdb.gimp_undo_push_group_end(img) return cards = [c['path'] for c in cards] if len(cards) != num: pdb.gimp_undo_push_group_end(img) return card_rows = [ cards[i * columns:(i + 1) * columns] for i in range((len(cards) + columns - 1) // columns) ] if len(card_rows) != rows: pdb.gimp_undo_push_group_end(img) return for i, card_row in enumerate(card_rows): for j, card_path in enumerate(card_row): if not os.path.exists(card_path): pdb.gimp_undo_push_group_end(img) return card_layer = pdb.gimp_file_load_layer(img, card_path) pdb.gimp_image_insert_layer(img, card_layer, None, -1) rotation = _get_rotation(card_layer) if rotation: _rotate(card_layer, True) pdb.gimp_layer_set_offsets(card_layer, j * 750, i * 1050) pdb.gimp_image_merge_down(img, card_layer, 1) pdb.file_jpeg_save(img, img.layers[0], os.path.join(output_folder, file_name), file_name, 1, 0, 1, 0, '', 2, 1, 0, 0) pdb.gimp_undo_push_group_end(img)
def \ superimpose_image_over_another_noninteractive( # image, # drawable, list_filenames, list_filenames_superimpose # horizontalLocation, # verticalLocation ) : nameFunction = "superimpose_image_over_another_interactive" print("----------------------------------------") print("%s : Enter" % (nameFunction)) IFS = ";" # listFiles = fileContents.split(IFS) listFiles = list_filenames.split(IFS) listFiles_superimpose = list_filenames_superimpose.split(IFS) print("%s : Number of elements in list = %d" % (nameFunction, len(listFiles))) print("%s : File list = %s" % (nameFunction, listFiles)) print("%s : Number of elements in list = %d" % (nameFunction, len(listFiles_superimpose))) print("%s : File list = %s" % (nameFunction, listFiles_superimpose)) if (len(listFiles) == 0): print("%s : Number of background image files = 0 : a") % (nameFunction) # errdialog = gtk.MessageDialog( # None, # 0, # gtk.MESSAGE_ERROR, # gtk.BUTTONS_OK, # "A) You must specify at least one background image file." # ) # errdialog.show_all() # errdialog.run() # raise Exception("You must specify at least one background image file.") elif (len(listFiles_superimpose) == 0): gimp.message( "B) You must specify at least one superimpose image file.") print("%s : Number of superimpose image files = 0 : a") % ( nameFunction) # raise Exception("You must specify at least one superimpose image file.") # elif (len(listFiles) == 1) : and elif (listFiles[0] == ''): gimp.message("C) You must specify at least one background image file.") print("%s : Number of background image files = 0 : b") % (nameFunction) # raise Exception("You must specify at least one background image file.") # elif (len(listFiles_superimpose) == 1) and elif (listFiles_superimpose[0] == ''): gimp.message( "D) You must specify at least one superimpose image file.") print("%s : Number of superimpose image files = 0 : b") % ( nameFunction) # raise Exception("You must specify at least one superimpose image file.") elif len(listFiles) != len(listFiles_superimpose): gimp.message( "E) The number of files specified must be the same for both background and superimpose images." ) print( "%s : The number of files specified must be the same for both background and superimpose images!" ) % (nameFunction) # raise Exception("The number of files specified must be the same for both background and superimpose images!") indexList = 0 for filename in listFiles: indexList = indexList + 1 print("%s : ========================================" % (nameFunction)) print("%s : Filename = %s" % (nameFunction, filename)) print("%s : ========================================" % (nameFunction)) if (not path.isfile(filename)): print("%s : > is NOT a file" % (nameFunction)) continue filename_superimpose = listFiles_superimpose[indexList - 1] print("%s : ========================================" % (nameFunction)) print("%s : Filename of image to superimpose = %s" % (nameFunction, filename_superimpose)) print("%s : ========================================" % (nameFunction)) if (not path.isfile(filename_superimpose)): print("%s : > is NOT a file" % (nameFunction)) gimp.progress_init("Superimposing one image over the other") image = pdb.gimp_file_load(filename, filename) drawable = pdb.gimp_image_get_active_layer(image) # Start a GIMP Undo group, as this will allow the actions of this Plugin to be undone in one step. pdb.gimp_undo_push_group_start(image) widthImage = image.width heightImage = image.height widthDrawable = drawable.width heightDrawable = drawable.height print("Width image = %s" % widthImage) print("Height image = %s" % heightImage) print("Width drawable = %s" % widthDrawable) print("Height drawable = %s" % heightDrawable) # print("Horizontal location = %s" % horizontalLocation) # print("Vertical location = %s" % verticalLocation) print("Image filename = %s" % image.filename) # Open the image file to be superimposed and get its drawable object. image_super = pdb.gimp_file_load(filename_superimpose, filename_superimpose) drawable_super = pdb.gimp_image_get_active_layer(image_super) print("Width super image = %s" % image_super.width) print("Height super image = %s" % image_super.height) print("Width super drawable = %s" % drawable_super.width) print("Height super drawable = %s" % drawable_super.height) # How many layers does the current image now contain? # # Use gimp-edit-copy and gimp-edit-paste? copy_result = pdb.gimp_edit_copy(drawable_super) if (copy_result == True): print("True") else: print("False") print("Selection copy result = %s" % copy_result) # pdb.gimp_drawable_update(drawable, horizontalLocation, verticalLocation, 384, 216) # The following operation should paste the image which is in the buffer, into a new layer of the # original image. pdb.gimp_edit_paste(drawable, True) widthImage = image.width heightImage = image.height widthDrawable = drawable.width heightDrawable = drawable.height print("Width image = %s" % widthImage) print("Height image = %s" % heightImage) print("Width drawable = %s" % widthDrawable) print("Height drawable = %s" % heightDrawable) # print("Horizontal location = %s" % horizontalLocation) # print("Vertical location = %s" % verticalLocation) # Move the # pdb.gimp_drawable_update() drawable_new = pdb.gimp_image_flatten(image) pdb.gimp_file_save(image, drawable_new, filename, filename) # End the GIMP Undo group. pdb.gimp_undo_push_group_end(image) # Close the image now that we have finished with it, otherwise it will use up memory unnecessarily. pdb.gimp_image_delete(image) # End of for loop. print("%s : Exit" % (nameFunction))