Repository navigation
fix: preserve alpha on export (#16) and render flattened composite (#17) #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
chenweichiang
wants to merge
1
commit into
gimp-mcp:main
from
chenweichiang:fix/alpha-export-and-composite-bitmap
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8000
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 characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -521,7 +521,14 @@ def _get_current_image_bitmap(self, params=None): | |
|
|
||
| # Use the first image (most recently active) | ||
| original_image = images[0] | ||
|
|
||
|
|
||
| # issue #17 fix: operate on a flattened composite duplicate so the | ||
| # bitmap reflects ALL visible layers (previously only the top layer | ||
| # was copied/exported). merge_visible keeps alpha, unlike flatten(). | ||
| original_image = original_image.duplicate() | ||
| original_image.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE) | ||
| composite_to_delete = original_image | ||
|
|
||
| # Get original image dimensions | ||
| orig_img_width = original_image.get_width() | ||
| orig_img_height = original_image.get_height() | ||
|
|
@@ -791,6 +798,11 @@ def _get_current_image_bitmap(self, params=None): | |
| working_image.delete() | ||
| except (AttributeError, RuntimeError) as e: | ||
| print(f"Warning: Failed to delete working temporary image: {e}") | ||
| # issue #17 fix: always drop the composite duplicate | ||
| try: | ||
| composite_to_delete.delete() | ||
| except (AttributeError, RuntimeError, NameError) as e: | ||
| print(f"Warning: Failed to delete composite duplicate: {e}") | ||
|
|
||
| # Clean up the temporary file | ||
| if os.path.exists(temp_path): | ||
|
|
@@ -1550,7 +1562,12 @@ def _export_to_path(self, image, file_path, fmt, quality, flatten): | |
| from gi.repository import Gio | ||
| if flatten: | ||
| image = image.duplicate() | ||
| image.flatten() | ||
| # issue #16 fix: flatten() drops the alpha channel — only acceptable | ||
| # for JPEG. Alpha-capable formats use merge_visible_layers instead. | ||
| if str(fmt).lower() in ("jpeg", "jpg"): | ||
| image.flatten() | ||
| else: | ||
| image.merge_visible_layers(Gimp.MergeType.CLIP_TO_IMAGE) | ||
| should_delete = True | ||
| else: | ||
| should_delete = False | ||
|
3F6B
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Move composite cleanup to the method-level
finallyblock.get_image_bitmaprequests reach_get_current_image_bitmap, where a partial region such as{"origin_x": 0}returns before the exportfinallyblock. Amerge_visible_layers()exception also occurs beforecomposite_to_deletereceives the duplicate. Both paths can retain the duplicate image. Initializecomposite_to_deletebefore duplication, assign the duplicate before merging, and delete it from an outerfinallythat covers the full method. Keep the existing innerfinallyfor temporary export images and files.🤖 Prompt for AI Agents