### Create a Binary Executable Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Install the 'pkg' tool globally and build the project to create a standalone binary executable for the remove-bg-cli. ```bash npm i -g pkg npm run build ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Clone the remove-bg-cli repository from GitHub, navigate into the directory, install Node.js dependencies, and build the project. ```bash git clone git@github.com:remove-bg/remove-bg-cli.git cd remove-bg-cli npm i npm run build ``` -------------------------------- ### Install remove-bg CLI with Homebrew Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Use Homebrew to install the remove-bg CLI tool on macOS and Linux systems. ```bash brew install remove-bg/homebrew-tap/removebg ``` -------------------------------- ### Display CLI Version and Help Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Show CLI version information using --version or -v, and display usage help with --help or -h. ```bash removebg --version ``` ```bash removebg -v ``` ```bash removebg --help ``` ```bash removebg -h ``` -------------------------------- ### Build and Test Locally Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Build the remove-bg-cli project and test its functionality locally by running the help command. ```bash npm run build ./dist/removebg --help ``` -------------------------------- ### Product Photography Workflow Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Automate background removal for product images in batches. Set environment variables for API key and create output directories before processing. ```bash export REMOVE_BG_API_KEY=your_api_key_here # Create output directories mkdir -p processed/transparent processed/white-bg # Process product images with transparent background removebg --type product --size full --output-directory processed/transparent products/*.jpg # Process same images with white background for web removebg --type product --bg-color ffffff --format jpg --output-directory processed/white-bg products/*.jpg ``` -------------------------------- ### Specify Output Image Format Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Choose the output image format using the `--format` option. Options include `png` (default), `jpg`, and `zip`. JPG output requires a background color to be specified. ```bash # Transparent PNG output (default) removebg --format png photo.jpg # JPG output (requires background color) removebg --format jpg --bg-color ffffff photo.jpg # ZIP format for maximum resolution removebg --format zip photo.jpg ``` -------------------------------- ### Build and Test Project Locally Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Build the remove-bg-cli project and run tests to ensure functionality. This is part of the local development workflow. ```bash npm run build npm run test ``` -------------------------------- ### Portrait Processing with Custom Background Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Process portrait images and apply a custom studio background. Ensure the API key is set and specify the output directory. ```bash export REMOVE_BG_API_KEY=your_api_key_here # Process portraits with custom studio background removebg --type person \ --bg-image-file studio_backdrop.jpg \ --extra-api-option add_shadow=true \ --output-directory final_portraits \ raw_portraits/*.jpg ``` -------------------------------- ### Set Extra API Options Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Use --extra-api-option to pass additional parameters to the remove.bg API, such as enabling cropping or adding shadows. ```bash removebg --extra-api-option crop=true --extra-api-option add_shadow=true photo.jpg ``` ```bash removebg --extra-api-option crop=true --extra-api-option crop_margin=10% photo.jpg ``` ```bash removebg --extra-api-option scale=80% photo.jpg ``` ```bash removebg --bg-image-file bg.jpg --extra-api-option position=center photo.jpg ``` -------------------------------- ### Process Images in a Directory (Default Output) Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Remove backgrounds from all PNG and JPG images in a directory and save the processed images in the same directory. This is the default behavior when no output directory is specified. ```bash removebg images/*.{png,jpg} ``` -------------------------------- ### Process Image with Additional API Options Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Process a car image and include additional API options like `--type car`, `--extra-api-option add_shadow=true`, and `--extra-api-option semitransparency=true` for advanced customization. ```bash removebg car.jpg --type car --extra-api-option add_shadow=true --extra-api-option semitransparency=true ``` -------------------------------- ### Replace Background with Custom Image Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Use the `--bg-image-file` option to composite the foreground onto a custom background image. This can be combined with other options like `--output-directory`. ```bash # Add custom background from file removebg --bg-image-file background.jpg photo.jpg # Combine with output directory removebg --bg-image-file beach.jpg --output-directory composited photos/*.jpg ``` -------------------------------- ### Produce JPG with Background Color Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Generate a JPG image with a specified background color by using the `--format jpg` and `--bg-color` options. The output is saved to a specified directory. ```bash removebg subject.jpg --format jpg --bg-color 7a7a7a --output-directory processed ``` -------------------------------- ### Pass Extra API Options Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Utilize the `--extra-api-option` flag to pass additional parameters directly to the remove.bg API for advanced features like adding shadows, enabling semi-transparency, or cropping to the foreground. ```bash # Add shadow to the result removebg --extra-api-option add_shadow=true photo.jpg # Enable semi-transparency support removebg --extra-api-option semitransparency=true photo.jpg # Crop to foreground removebg --extra-api-option crop=true photo.jpg ``` -------------------------------- ### Set API Key and Process Images Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Set your API key as an environment variable for secure access. Process single images, multiple images, or all images in a directory using glob patterns. You can also specify the API key directly via a command-line flag. ```bash # Set API key as environment variable (recommended) export REMOVE_BG_API_KEY=your_api_key_here # Process a single image (outputs image-removebg.png in same directory) removebg photo.jpg # Process multiple images removebg image1.jpg image2.png image3.jpg # Process all images in a directory using glob patterns removebg images/*.{png,jpg} # Specify API key directly removebg --api-key your_api_key_here photo.jpg ``` -------------------------------- ### Control Output Image Size Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Adjust the output image dimensions using the `--size` option. Available values include `auto`, `preview`, `small`, `regular`, `medium`, `hd`, `full`, and `4k`. `auto` is the default setting. ```bash # Auto-detect best size (default) removebg --size auto photo.jpg # Full resolution output (up to 25 megapixels) removebg --size full large_image.jpg # Preview quality for quick tests removebg --size preview test_image.jpg ``` -------------------------------- ### Set API Key via Environment Variable Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Export your remove.bg API key as an environment variable for use with all subsequent commands. This is a convenient way to authenticate without specifying the key for each request. ```bash export REMOVE_BG_API_KEY=xyz ``` -------------------------------- ### Produce Large Transparent PNG Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Generate a large transparent PNG image up to 25 megapixels by specifying `--size full` and `--format png`. ```bash removebg large.jpg --size full --format png ``` -------------------------------- ### Convert ZIP to PNG Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Use the `zip2png` command within the remove.bg CLI to convert a result zip file obtained from remove.bg into a transparent PNG file. ```bash removebg zip2png --file /path/to/file.zip ``` -------------------------------- ### Configure Batch Processing Behavior Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Manage batch processing settings, including confirmation prompts for large batches and reprocessing of existing files. Use `--confirm-batch-over` to set a threshold or `-1` to disable confirmation. ```bash # Confirm before processing batches over 50 images (default) removebg images/*.jpg # Disable batch confirmation removebg --confirm-batch-over -1 images/*.jpg # Set custom confirmation threshold removebg --confirm-batch-over 100 images/*.jpg # Reprocess already processed images (normally skipped) removebg --reprocess-existing images/*.jpg ``` -------------------------------- ### Control Output Color Channels Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Specify the desired color channels for the output using the `--channels` option. Options are `rgba` for full color with transparency (default) or `alpha` for a grayscale transparency mask. ```bash # Full RGBA output (default) removebg --channels rgba photo.jpg # Alpha channel only (grayscale mask) removebg --channels alpha photo.jpg ``` -------------------------------- ### Process Images to a Different Directory Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Remove backgrounds from all PNG and JPG images in a directory and save the processed images to a specified output directory using the `--output-directory` flag. ```bash mkdir processed removebg --output-directory processed originals/*.{png,jpg} ``` -------------------------------- ### Optimize Foreground Type Detection Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Improve background removal accuracy by specifying the foreground type with the `--type` option. Supported values are `auto`, `person`, `product`, and `car`. ```bash # Auto-detect foreground type (default) removebg --type auto photo.jpg # Optimize for person/portrait photos removebg --type person portrait.jpg # Optimize for product photography removebg --type product item.jpg # Optimize for car images removebg --type car vehicle.jpg ``` -------------------------------- ### Specify API Key per Command Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Provide the API key directly as an argument to the removebg command when processing a specific file. ```bash removebg --api-key xyz images/image1.jpg ``` -------------------------------- ### Control PNG Format Optimization Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Control the transfer format optimization for PNG output. The default uses ZIP for maximum resolution, while skipping it uses standard PNG format limited to 10MP. ```bash removebg photo.jpg ``` ```bash removebg --skip-png-format-optimization photo.jpg ``` -------------------------------- ### Skip PNG Format Optimization Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Use the `--skip-png-format-optimization` flag to process images using the 'png' format instead of the default 'zip' format. This limits output resolution to 10 megapixels but can save bandwidth. ```bash removebg --skip-png-format-optimization images/*.png ``` -------------------------------- ### Configure Output Directory Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Use the `--output-directory` flag to specify where processed images should be saved. Output files will retain their original names without the '-removebg' suffix when this option is used. ```bash # Save processed images to a specific directory mkdir processed removebg --output-directory processed originals/*.jpg # Input: originals/dog.jpg, originals/cat.png # Output: processed/dog.png, processed/cat.png ``` -------------------------------- ### Remove.bg API Endpoint and Parameters Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Details on the remove.bg API v1.0 endpoint and supported parameters for background removal operations. This includes image file handling, size, type, format, color, and various processing options. ```text # API endpoint used internally # POST https://api.remove.bg/v1.0/removebg # Required header # X-Api-Key: your_api_key # Supported parameters (as form fields): # - image_file: Input image file # - size: auto|preview|small|regular|medium|hd|full|4k # - type: auto|person|product|car # - type_level: none|1|2|latest # - format: png|jpg|zip # - channels: rgba|alpha # - bg_color: Hex color code (e.g., ffffff) # - bg_image_file: Background image file # - crop: true|false # - crop_margin: Percentage or pixels # - scale: Percentage # - position: Positioning value # - add_shadow: true|false # - semitransparency: true|false # - roi: Region of interest ``` -------------------------------- ### High-Resolution Car Photography Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Process car images at maximum resolution, including shadows and semitransparency. Set the API key and output directory. ```bash export REMOVE_BG_API_KEY=your_api_key_here # Process car images at maximum resolution with shadows removebg --type car \ --size full \ --extra-api-option add_shadow=true \ --extra-api-option semitransparency=true \ --output-directory car_cutouts \ car_photos/*.jpg ``` -------------------------------- ### Reprocess Existing Files Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Force reprocessing of images that have already been processed by using the `--reprocess-existing` flag. This is useful if you need to regenerate output files or apply new settings. ```bash removebg --reprocess-existing images/*.{png,jpg} ``` -------------------------------- ### Add Custom Background Color Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt Replace the removed background with a solid color using the `--bg-color` option, specifying the color as a hex code. This is often used in conjunction with JPG output. ```bash # White background removebg --bg-color ffffff photo.jpg # Gray background with JPG output removebg --format jpg --bg-color 7a7a7a photo.jpg # Red background removebg --bg-color ff0000 photo.jpg ``` -------------------------------- ### POST /v1.0/removebg Source: https://context7.com/remove-bg/remove-bg-cli/llms.txt The primary endpoint for background removal operations, supporting various image processing parameters. ```APIDOC ## POST https://api.remove.bg/v1.0/removebg ### Description Performs background removal on an uploaded image file based on the provided parameters. ### Method POST ### Endpoint https://api.remove.bg/v1.0/removebg ### Parameters #### Request Body (Form Fields) - **image_file** (file) - Required - The input image file. - **size** (string) - Optional - Output size: auto, preview, small, regular, medium, hd, full, 4k. - **type** (string) - Optional - Subject type: auto, person, product, car. - **type_level** (string) - Optional - Subject detection level: none, 1, 2, latest. - **format** (string) - Optional - Output format: png, jpg, zip. - **channels** (string) - Optional - Color channels: rgba, alpha. - **bg_color** (string) - Optional - Background color in hex code (e.g., ffffff). - **bg_image_file** (file) - Optional - Custom background image file. - **crop** (boolean) - Optional - Enable cropping. - **crop_margin** (string) - Optional - Margin for cropping (percentage or pixels). - **scale** (string) - Optional - Scaling percentage. - **position** (string) - Optional - Positioning value for background. - **add_shadow** (boolean) - Optional - Enable shadow addition. - **semitransparency** (boolean) - Optional - Enable semi-transparency. - **roi** (string) - Optional - Region of interest. ### Request Example curl -H "X-Api-Key: your_api_key" -F "image_file=@photo.jpg" -F "size=full" https://api.remove.bg/v1.0/removebg ### Response #### Success Response (200) - **image** (binary) - The processed image file or ZIP archive. ``` -------------------------------- ### Disable Batch Confirmation Prompt Source: https://github.com/remove-bg/remove-bg-cli/blob/main/README.md Disable the confirmation prompt for processing large batches of images by setting `--confirm-batch-over` to -1. Use with caution as this bypasses a safeguard against accidental large operations. ```bash removebg --confirm-batch-over -1 images/*.{png,jpg} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.