(03-28-2024, 12:06 PM)Ofnuts Wrote:(03-28-2024, 11:55 AM)kaiserart Wrote: Is there any function/plugin like this?
If no is it possible to create a fu-python plugin myself to achieve this?
Basically the mockup does not change. The empty space will always have the same position and size. I just have to fit the image to it.You can also do this with ImageMagick compose but you have to find an external way to remember the size/position of the empty space.
- None I know of
- Yes
- You probably want to keep the mockup as an XCF mark the empty space with a layer at the right size/position
Thanks for your reply. I managed to create a plugin for myself which iterates through every image in a folder and then through every mockup in a folder.
Then scales and positions the image according to the mockup and create a blurred shadow around it to make it more seamless.
Still i have one more question.
When the script finishes actually successfully it says in a GIMP Message:
"Unable to run GimpPdbProgress callback. The corresponding plug-in may have crashed."
Here is my Script (it is rather rudimental, also with absolute paths):
Code:
from gimpfu import *
import os
def set_stroke_params():
# Set opacity to 100%
pdb.gimp_context_set_opacity(100)
# Set paint mode to NORMAL
pdb.gimp_context_set_paint_mode(0) # NORMAL mode
# Set paint method to GRAYA (this is the default)
pdb.gimp_context_set_paint_method("gimp-paintbrush") # GRAYA method
# Set stroke method to PAINT
pdb.gimp_context_set_stroke_method("0") # PAINT method
# Set foreground color to black
pdb.gimp_context_set_foreground((0, 0, 0)) # Black color
# Set active brush (assuming you've already defined the brush)
brush_name = "Circle (01)"
pdb.gimp_context_set_brush(brush_name)
# Set line width to 10
pdb.gimp_context_set_line_width(6)
# Enable antialiasing
pdb.gimp_context_set_antialias(True)
def create_outline_layer(mockup_image, scaled_image):
# Create a new layer filled with transparent color
outline_layer = pdb.gimp_layer_new(mockup_image, scaled_image.width, scaled_image.height, RGBA_IMAGE, "Outline", 100, NORMAL_MODE)
pdb.gimp_image_insert_layer(mockup_image, outline_layer, None, 0)
return outline_layer
def mockup_scaleandmove_horizontal(image, drawable):
mockups = ["WoodFrame_1.jpg", "BlackBorder_1.jpg", "Gaming_1.jpg", "Gaming_2.jpg", "LivingRoom_1.jpg"]
pos_x = [295, 113, 212, 303, 163]
pos_y = [611, 236, 112, 171, 115]
scale_x = [1461, 801, 492, 436, 699]
scale_y = [850, 540, 290, 270, 435]
mockup_folder_path = "C:/Users/Daniel Kunz/Desktop/MidJourney/Mockups/Horizontal/Frontal"
original_folder_path = "C:/Users/Daniel Kunz/Desktop/MidJourney/NewArt"
mockup_image_path = ""
original_image_path = ""
# Iterate through each new file
for filename_original in os.listdir(original_folder_path):
# Check if it's a file
if os.path.isfile(os.path.join(original_folder_path, filename_original)):
original_image_path = original_folder_path + "/" + filename_original
# Iterate through each mockup
for index, mockup in enumerate(mockups):
# Iterate through each file in the folder
for filename_mockup in os.listdir(mockup_folder_path):
# Check if it's a file
if os.path.isfile(os.path.join(mockup_folder_path, filename_mockup)):
if filename_mockup == mockup:
# Set Mockup Image Path
mockup_image_path = mockup_folder_path + "/" + filename_mockup
# Load the Mockup Image
mockup_image = pdb.gimp_file_load(mockup_image_path, mockup_image_path)
# Load the Original Image
original_image = pdb.gimp_file_load(original_image_path, original_image_path)
# Resize the original image to fit the mockup
pdb.gimp_image_scale(original_image, scale_x[index], scale_y[index])
# Create a new layer in the mockup image
layer = pdb.gimp_layer_new_from_drawable(original_image.active_drawable, mockup_image)
# Add the layer to the mockup image
pdb.gimp_image_insert_layer(mockup_image, layer, None, 0)
# Move the layer to the fixed position
pdb.gimp_layer_translate(layer, pos_x[index], pos_y[index])
# Create a new layer with only the outline of the selection
outline_layer = create_outline_layer(mockup_image, original_image)
# Move the layer to the fixed position
pdb.gimp_layer_translate(outline_layer, pos_x[index], pos_y[index])
# Select the outline
pdb.gimp_selection_all(outline_layer.image)
# Stroke the selection to draw a line around it
set_stroke_params()
pdb.gimp_drawable_edit_stroke_selection(outline_layer)
# Apply Gaussian blur to the outline layer
pdb.plug_in_gauss(mockup_image, outline_layer, 10, 10, 1)
# Merge the blurred stroke layer with the original layer
# Merge visible layers
merged_layer = pdb.gimp_image_merge_visible_layers(mockup_image, CLIP_TO_IMAGE)
#pdb.gimp_image_merge_down(mockup_image, outline_layer, EXPAND_AS_NECESSARY)
# Save the merged image
output_filename = filename_original[:-4] + filename_mockup + ".jpg"
output_foldername = "{}".format(filename_original[:-4])
output_folder = "C:/Users/Daniel Kunz/Desktop/MidJourney/Images/NewMockups/" + output_foldername
# Check if the directory already exists
if not os.path.exists(output_folder):
# If it doesn't exist, create the directory
os.makedirs(output_folder)
filename = os.path.join(output_folder, output_filename[:-4])
pdb.gimp_file_save(mockup_image, merged_layer, filename, filename)
# Close the images to conserve memory
pdb.gimp_image_delete(mockup_image)
pdb.gimp_image_delete(original_image)
# Notify user
gimp.message("Images rescaled, stroke painted, and saved successfully!")
register(
"python_fu_mockup_scaleandmove_horizontal",
"Rescale, paint stroke, and save images",
"Rescale the input image into 5 different sizes, paint a stroke around the scaled and moved original image, and save them with DPI set to 300.",
"Daniel Kunz",
"Daniel Kunz",
"2024",
"<Image>/Filters/Mockup ScaleAndMove Horizontal",
"",
[],
[],
mockup_scaleandmove_horizontal)
main()