Nodes/comfyui-AGSoft/🖼️✂️AGSoft Image Crop
ComfyUI Node

🖼️✂️AGSoft Image Crop

Crop with presets, percentages, and a mask that comes along

By Art-xmaster·Created 12 months ago·Updated a day ago· 23
🖼️✂️AGSoft Image Crop
  • image
  • mask
  • cropped_image
  • cropped_mask
  • cropped_width
  • cropped_height
width512
height512
positioncenter
use_percentagefalse
maintain_aspect_ratiofalse
inverse_crop_percent0
start_x0
start_y0
deviceauto
use_cachetrue
fill_colorblack
interpolationbilinear

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.

CategoryAGSoft/Image

Inputs (14)

NameTypeDefaultDescription
imageIMAGEВходное изображение в формате [BATCH, HEIGHT, WIDTH, CHANNELS] Input image tensor in format [BATCH, HEIGHT, WIDTH, CHANNELS]
widthINT5121–8192Ширина обрезки в пикселях или процентах (зависит от use_percentage) Crop width in pixels or percentage (depends on use_percentage)
heightINT5121–8192Высота обрезки в пикселях или процентах (зависит от use_percentage) Crop height in pixels or percentage (depends on use_percentage)
positionCOMBOcenterПозиция области обрезки: - 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)
maskoptMASKОпциональная маска для обрезки (должна совпадать по размеру с изображением) Optional mask for cropping (must match image dimensions)
use_percentageoptBOOLEANfalseЕсли включено, width и height интерпретируются как проценты от размера изображения If enabled, width and height are interpreted as percentage of image size
maintain_aspect_ratiooptBOOLEANfalseСохранять соотношение сторон исходного изображения Maintain original image aspect ratio
inverse_crop_percentoptINT00–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_xoptINT00–8192Начальная координата X для обрезки (только при position='custom') Должна быть меньше (ширина изображения - ширина обрезки) Start X coordinate for cropping (only when position='custom') Must be less than (image width - crop width)
start_yoptINT00–8192Начальная координата Y для обрезки (только при position='custom') Должна быть меньше (высота изображения - высота обрезки) Start Y coordinate for cropping (only when position='custom') Must be less than (image height - crop height)
deviceoptCOMBOautoУстройство для выполнения операций: - 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_cacheoptBOOLEANtrueИспользовать кэширование для ускорения повторных операций с теми же параметрами Use caching to speed up repeated operations with same parameters
fill_coloroptSTRINGblackЦвет для заполнения при выходе за границы (black, white, или RGB значения через запятую, например: 255,0,0) Fill color when cropping out of bounds (black, white, or comma-separated RGB, e.g.: 255,0,0)
interpolationoptCOMBObilinearМетод интерполяции для изменения размера (если требуется) Interpolation method for resizing (if needed)

Outputs (4)

NameTypeDescription
cropped_imageIMAGE
cropped_maskMASK
cropped_widthINT
cropped_heightINT