Last active
October 27, 2020 17:12
-
-
Save ammancilla/cf9dd21d0193c374a442dd0392e29d98 to your computer and use it in GitHub Desktop.
Revisions
-
ammancilla revised this gist
Oct 27, 2020 . 1 changed file with 1 addition and 49 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -104,52 +104,4 @@ def apply(): print("ERROR: " + str(e)) finally: pdb.gimp_quit(1) -
ammancilla revised this gist
Oct 27, 2020 . 1 changed file with 94 additions and 80 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,94 +3,108 @@ # # # apt-get install -y gimp gimp-python # # gimp -i -d -f --batch-interpreter python-fu-eval -b 'import sys; sys.path=["."]+sys.path;import gimp_fadeout; gimp_fadeout.apply()' # import sys, os from gimpfu import * def apply(): try: # --- # Configuration # --- fadeout_from = 0.98 fadeout_until = 0.1 image_path = os.environ['FADEOUT_IMAGE'] if not os.path.exists(image_path): raise NameError('image does not exists') if 'FADEOUT_FROM' in os.environ and os.environ['FADEOUT_FROM']: fadeout_from = float(os.environ['FADEOUT_FROM']) if 'FADEOUT_UNTIL' in os.environ and os.environ['FADEOUT_UNTIL']: fadeout_until = float(os.environ['FADEOUT_UNTIL']) image_filename = os.path.basename(image_path) black_image_path = 'black_image_' + image_filename fadeout_path = 'fadeout_' + image_filename # --- # Gimp context configuration # --- print('Configuring Gimp context...') pdb.gimp_context_set_default_colors() pdb.gimp_context_set_gradient_fg_bg_rgb() # --- # Create base black image # --- print('Creating base black image...') image = pdb.gimp_file_load(image_path, RUN_NONINTERACTIVE) width = image.width height = image.height layer = gimp.Layer(image, 'Black Layer', width, height, RGB_IMAGE, 100, NORMAL_MODE) image.add_layer(layer) pdb.gimp_image_merge_visible_layers(image, CLIP_TO_IMAGE) pdb.file_jpeg_save(image, image.active_layer, black_image_path, black_image_path, 1,0,1,0,0,0,0,0,0) pdb.gimp_image_delete(image) # --- # Create Fadeout # --- print('Adding fadeout to original image...') # Open black image black_image = pdb.gimp_file_load(black_image_path, RUN_NONINTERACTIVE) # Load main image as layer image = pdb.gimp_file_load_layer(black_image, image_path) black_image.add_layer(image) # Create layer mask mask = pdb.gimp_layer_create_mask(image, ADD_MASK_WHITE) # Add layer mas to main image pdb.gimp_layer_add_mask(image, mask) # Apply gradient x1 = width / 2 y1 = height * fadeout_from y2 = y1 - (y1 * fadeout_until) pdb.gimp_drawable_edit_gradient_fill(mask, GRADIENT_LINEAR, 0, 0, 0, 0, 0, x1, y1, x1, y2) # Merge layers into black image pdb.gimp_image_merge_visible_layers(black_image, CLIP_TO_IMAGE) # --- # Save Image with Fadeout # --- print('Saving image with fadeout...') pdb.file_jpeg_save(black_image, black_image.active_layer, fadeout_path, fadeout_path, 1,0,1,0,0,0,0,0,0) # --- # Clean Up # --- print('Done!!!') # Delete temporarily files os.remove(black_image_path) # Delete images from gimp context pdb.gimp_image_delete(black_image) except Exception as e: print("ERROR: " + str(e)) finally: pdb.gimp_quit(1) # ----- -
ammancilla revised this gist
Oct 27, 2020 . 1 changed file with 72 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,32 +2,37 @@ # Simple python module to add a black fadeout effect to a given image # # # apt-get install -y gimp-python # # gimp -i -d -f --batch-interpreter python-fu-eval -b 'import sys; sys.path=["."]+sys.path;import gimp_fadeout; gimp_fadeout.apply()' # import os from gimpfu import * def apply(): image_path = os.environ['GIMP_FADEOUT_IMAGE'] if not os.path.exists(image_path): raise NameError('image does not exists') image_filename = os.path.basename(image_path) black_image_path = 'black_image_' + image_filename fadeout_path = 'fadeout_' + image_filename # --- # Context Configuration # --- print('Configuring Gimp context...') pdb.gimp_context_set_default_colors() pdb.gimp_context_set_gradient_fg_bg_rgb() # --- # Create base black image # --- print('Creating base black image...') image = pdb.gimp_file_load(image_path, RUN_NONINTERACTIVE) width = image.width height = image.height @@ -42,6 +47,8 @@ def gimp_fadeout(): # --- # Create Fadeout # --- print('Adding fadeout to original image...') # Open black image black_image = pdb.gimp_file_load(black_image_path, RUN_NONINTERACTIVE) @@ -65,14 +72,70 @@ def gimp_fadeout(): # Merge layers into black image pdb.gimp_image_merge_visible_layers(black_image, CLIP_TO_IMAGE) # --- # Save Image with Fadeout # --- print('Saving image with fadeout...') pdb.file_jpeg_save(black_image, black_image.active_layer, fadeout_path, fadeout_path, 1,0,1,0,0,0,0,0,0) # --- # Clean Up # --- print('Done!!!') # Delete temporarily files os.remove(black_image_path) # Delete images from gimp context pdb.gimp_image_delete(black_image) # Close gimp pdb.gimp_quit(1) # ----- # FADEOUT TECNIQUE 2 # ---- # def fadeout(infile, percentile = 0.9): # # 5. Get the image - Load the image # infile = "/home/oferfacil/bron.jpg" # outfile = "/home/oferfacil/fadeout.jpg" # image = pdb.gimp_file_load(infile, RUN_NONINTERACTIVE) # width = image.width # height = image.height # # 2. Create a layer # layer = gimp.Layer(image, 'Overlay', width, height, RGB_IMAGE, 100, NORMAL_MODE) # # 3. Add layer to image # image.add_layer(layer) # # 4. Create mask # mask = pdb.gimp_layer_create_mask(layer, ADD_MASK_WHITE) # # 5. Add mask to layer # pdb.gimp_layer_add_mask(layer, mask) # # 6. Apply Gradient - fadeout # cx = width / 2 # cy = height * percentile # pdb.gimp_context_set_default_colors() # pdb.gimp_context_set_gradient_fg_bg_hsv_ccw() # pdb.gimp_drawable_edit_gradient_fill(mask, GRADIENT_BILINEAR, 0, 0, 0, 0, 0, cx, 0, cx, cy) # # 7. Merge layers # pdb.gimp_image_merge_visible_layers(image, CLIP_TO_IMAGE) # # 7. Save image with fadeout # drawable = image.active_layer # pdb.file_jpeg_save(image, drawable, outfile, outfile, 1,0,1,0,0,0,0,0,0) # # pdb.file_png_save(image, drawable, outfile, outfile, 0,9,0,0,0,0,0) # # 9. Delete original from gimp context # pdb.gimp_image_delete(image) # # 10. Quit gimp # pdb.gimp_quit(1) -
ammancilla created this gist
Oct 27, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ # # Simple python module to add a black fadeout effect to a given image # import os from gimpfu import * def gimp_fadeout(): image_path = os.environ['IMAGE'] # image_path = '/Users/drilococo/Desktop/bron.jpg' if not os.path.exists(image_path): raise NameError('image does not exists') image_filename = os.path.basename(image_path) black_image_filename = 'black_image_' + image_filename black_image_path = '/tmp/' + black_image_filename fadeout_filename = 'fadeout_' + image_filename fadeout_path = '/tmp/' + fadeout_filename # --- # Context Configuration # --- pdb.gimp_context_set_default_colors() pdb.gimp_context_set_gradient_fg_bg_rgb() # --- # Create base black image # --- image = pdb.gimp_file_load(image_path, RUN_NONINTERACTIVE) width = image.width height = image.height layer = gimp.Layer(image, 'Black Layer', width, height, RGB_IMAGE, 100, NORMAL_MODE) image.add_layer(layer) pdb.gimp_image_merge_visible_layers(image, CLIP_TO_IMAGE) pdb.file_jpeg_save(image, image.active_layer, black_image_path, black_image_path, 1,0,1,0,0,0,0,0,0) pdb.gimp_image_delete(image) # --- # Create Fadeout # --- # Open black image black_image = pdb.gimp_file_load(black_image_path, RUN_NONINTERACTIVE) # Load main image as layer image = pdb.gimp_file_load_layer(black_image, image_path) black_image.add_layer(image) # Create layer mask mask = pdb.gimp_layer_create_mask(image, ADD_MASK_WHITE) # Add layer mas to main image pdb.gimp_layer_add_mask(image, mask) # Apply gradient x1 = width / 2 y1 = height * 0.98 y2 = y1 - (height * 0.1) pdb.gimp_drawable_edit_gradient_fill(mask, GRADIENT_LINEAR, 0, 0, 0, 0, 0, x1, y1, x1, y2) # Merge layers into black image pdb.gimp_image_merge_visible_layers(black_image, CLIP_TO_IMAGE) # Save image with fadeout as jpg pdb.file_jpeg_save(black_image, black_image.active_layer, fadeout_path, fadeout_path, 1,0,1,0,0,0,0,0,0) # Delete temporarily files os.remove(black_image_path) # Delete images from gimp context pdb.gimp_image_delete(black_image) # Close gimp pdb.gimp_quit(1)