Skip to content

Conversation

@Eutalix
Copy link

@Eutalix Eutalix commented Nov 28, 2025

Description

This PR adds support for the Cutout Sticker creation feature (converting photos to stickers in Direct Messages).

It implements the logic found in the latest Instagram versions, allowing users to create native stickers that are saved to the user's sticker tray.

Features

  • AI Bypass Mode (Default): Creates a sticker from the full image using a manual bounding box. This is ideal for pre-processed images (e.g., transparent PNGs or WhatsApp sticker imports) where server-side cropping is not desired.
  • AI Detection Mode: Supports the native server-side subject detection (SAM) by sending the appropriate flags.

Changes

  • instagrapi/mixins/media.py: Added media_configure_to_cutout_sticker. This handles the private API endpoint media/configure_to_cutout_sticker/.
  • instagrapi/mixins/photo.py: Added photo_upload_to_cutout_sticker. A high-level helper that uploads a photo and configures it as a sticker in one step.

Reverse Engineering Notes

I reverse-engineered this flow by patching the Instagram Android APK to inject logging into the networking classes (LX/UtP and LX/WLA).

The key discovery was that the media/upload_edit/ endpoint (used for AI segmentation) can be completely bypassed by providing a manual_mask with a full bounding box ([0.0, 0.0, 1.0, 1.0]) directly to the configuration endpoint. This results in a custom_sticker product type with status: ok.

Note: This feature was reverse-engineered and tested entirely on an Android device via Termux/ADB.

Usage Example

# 1. Create a sticker from a transparent PNG (Bypass AI cropping)
# This selects the full image area.
cl.photo_upload_to_cutout_sticker("path/to/sticker.png", bypass_ai=True)

# 2. Create a sticker from a photo (Let Instagram AI crop the subject)
cl.photo_upload_to_cutout_sticker("path/to/photo.jpg", bypass_ai=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant