Repository navigation
fix(modifiers): skip an inserted element that lands wholly off the canvas - #135
Merged
olivervogel merged 1 commit intoOct 12, 2026
Merged
Conversation
…nvas InsertModifier embeds an element with an alpha band into a frame-sized canvas before compositing. When the position leaves no part of the element on the frame, libvips refuses the embed with "embed: bad dimensions", so insert() threw where GD and Imagick clip the element away and return the image unchanged. The decoders add an alpha band to sRGB and greyscale sources, so a JPEG element takes that path too. Return the image as it is when the element does not overlap it. The check runs before the element is materialised, so the pixels of an element that would not be drawn are never read.
This was referenced Oct 11, 2026
Member
|
Thanks, I made a small adjustment. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
InsertModifierthrowsJcupitt\Vips\Exception(embed: bad dimensions) when the inserted image does not overlap the canvas at all, for example when the offset pushes it past an edge. GD and Imagick clip it away and return the image unchanged.Base 40x30, inserted image 10x5:
Same with
transparencybelow 1. As soon as one row or column of the inserted image is on the canvas, it works.placeElement()embeds the element in a canvas of the frame size beforecomposite2(), and libvips refuses anembed()with no overlap. Decoded sRGB and greyscale images get an alpha band, so they all go through this path. Theinsert()path without alpha already handles this case.The modifier now returns the image as is when nothing overlaps. The check runs before
Core::ensureInMemory(), so the element is not loaded into memory for nothing. Tests cover the four edges, alignment with offsets, an animated image (frame height, not the whole strip) and the single row/column cases.