🖼️✂️AGSoft Image Crop
Crop with presets, percentages, and a mask that comes along
- image
- mask
- cropped_image
- cropped_mask
- cropped_width
- cropped_height
Every workflow eventually needs a crop that isn't "center, fixed size." Maybe you want the top-left 512px, maybe you want to shave 5% off the edges, maybe you want to crop around a subject that isn't in the middle. ✂️ AGSoft Image Crop is the pack's general-purpose crop node, and it covers all of those without forcing you to build the math yourself. The trick that makes it worth your time: it crops images and masks together, so your inpainting or compositing setup stays aligned.
What it does
At its simplest it's a center crop: width and height in, cropped_image out. But there are three layers on top of that.
Positions. position has 9 presets - center, all four corners, and the four edges. No manual coordinate math for the common cases.
Percentages. Flip use_percentage on and width/height become percentages of the source. Crop 50% from the center, 25% from the top - the kind of thing that's a pain to express as raw pixels.
Inverse crop. inverse_crop_percent does the opposite: it removes a band from the edges. Set it to 5 and the node trims 5% off each side - handy for chopping scan borders or watermark strips without doing offset arithmetic.
There's also maintain_aspect_ratio (keeps the source proportions when you change one side), custom start_x/start_y when presets don't fit, a fill_color for the crop's leftovers, interpolation, and a device selector with CPU/GPU/Auto. use_cache (on by default) keeps repeated crops fast, which matters in batch-heavy loops.
The mask connection
Plug a mask in and you get cropped_mask out, cut with the exact same geometry. That's the feature that makes this node more than a toy: crop around a face or an object, and the mask that goes with it comes along for the ride, ready to feed an inpaint or composite step. For that classic "crop tight, generate big, stitch back" workflow, keeping image and mask in lockstep is half the battle.
Outputs: cropped_image, cropped_mask, plus cropped_width/cropped_height ints you can wire into downstream sizing.
Installing it
Standard pack install: ComfyUI Manager → search comfyui-AGSoft → install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/Art-xmaster/comfyui-AGSoft.git
No models, no extra dependencies - pure PIL/torch, so a bare clone runs it.
Common issues
The usual trap is use_percentage left on from a previous workflow: suddenly your 512 width means "half of a 1024-wide image" and crops come out unexpected. Check that toggle before debugging anything else. Also, if you crop and then upscale the crop a lot, the result gets soft fast - this is a plain crop, not a super-resolution stage, so pair it with an upscaler or an inpaint pass when you need detail back. And as with any crop that feeds a dedicated inpainting model, the mask should match the crop exactly - which is precisely the case where this node earns its keep.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Входное изображение в формате [BATCH, HEIGHT, WIDTH, CHANNELS] Input image tensor in format [BATCH, HEIGHT, WIDTH, CHANNELS] | |
| width | INT | 5121–8192 | Ширина обрезки в пикселях или процентах (зависит от use_percentage) Crop width in pixels or percentage (depends on use_percentage) |
| height | INT | 5121–8192 | Высота обрезки в пикселях или процентах (зависит от use_percentage) Crop height in pixels or percentage (depends on use_percentage) |
| position | COMBO | center | Позиция области обрезки: - top-left: верхний левый угол - top-center: верхний центр - top-right: верхний правый угол - center-left: центр по вертикали, левый край - center: центр изображения - center-right: центр по вертикали, правый край - bottom-left: нижний левый угол - bottom-center: нижний центр - bottom-right: нижний правый угол - custom: пользовательские координаты (start_x, start_y) Crop area position: - top-left: top-left corner - top-center: top center - top-right: top-right corner - center-left: center vertically, left edge - center: image center - center-right: center vertically, right edge - bottom-left: bottom-left corner - bottom-center: bottom center - bottom-right: bottom-right corner - custom: custom coordinates (start_x, start_y) |
| maskopt | MASK | Опциональная маска для обрезки (должна совпадать по размеру с изображением) Optional mask for cropping (must match image dimensions) | |
| use_percentageopt | BOOLEAN | false | Если включено, width и height интерпретируются как проценты от размера изображения If enabled, width and height are interpreted as percentage of image size |
| maintain_aspect_ratioopt | BOOLEAN | false | Сохранять соотношение сторон исходного изображения Maintain original image aspect ratio |
| inverse_crop_percentopt | INT | 00–49 | Процент обрезки от каждого края изображения (0-49%): Например, 10% обрежет по 10% с каждой стороны Полезно для удаления артефактов по краям Percentage to crop from each edge (0-49%): Example: 10% crops 10% from each side Useful for removing edge artifacts |
| start_xopt | INT | 00–8192 | Начальная координата X для обрезки (только при position='custom') Должна быть меньше (ширина изображения - ширина обрезки) Start X coordinate for cropping (only when position='custom') Must be less than (image width - crop width) |
| start_yopt | INT | 00–8192 | Начальная координата Y для обрезки (только при position='custom') Должна быть меньше (высота изображения - высота обрезки) Start Y coordinate for cropping (only when position='custom') Must be less than (image height - crop height) |
| deviceopt | COMBO | auto | Устройство для выполнения операций: - auto: автоматический выбор (GPU если доступен, иначе CPU) - cpu: принудительное использование CPU - gpu: принудительное использование GPU (если доступен) Device for operations: - auto: automatic selection (GPU if available, else CPU) - cpu: force CPU usage - gpu: force GPU usage (if available) |
| use_cacheopt | BOOLEAN | true | Использовать кэширование для ускорения повторных операций с теми же параметрами Use caching to speed up repeated operations with same parameters |
| fill_coloropt | STRING | black | Цвет для заполнения при выходе за границы (black, white, или RGB значения через запятую, например: 255,0,0) Fill color when cropping out of bounds (black, white, or comma-separated RGB, e.g.: 255,0,0) |
| interpolationopt | COMBO | bilinear | Метод интерполяции для изменения размера (если требуется) Interpolation method for resizing (if needed) |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| cropped_image | IMAGE | — |
| cropped_mask | MASK | — |
| cropped_width | INT | — |
| cropped_height | INT | — |