Magic Resize (Automate)
Automates the magic resize process for an image, allowing for resizing to target dimensions with content-aware fill or cropping if necessary.
Method Signature
client.automate.magicResize(payload: MagicResizeAutomateRequest): Promise<MagicResizeAutomateResponse>;
Parameters
-
payload(MagicResizeAutomateRequest): An object containing the parameters for the magic resize operation. Key fields include:image_url(string): URL of the source image.target_width(number): Desired width of the output image.target_height(number): Desired height of the output image.prompt(optional string): A text prompt to guide the content generation if filling is needed.mode(optional string): Resizing mode (e.g., 'fill', 'fit'). Defaults to 'fill'.output_format(optional string): Desired output format (e.g., 'png', 'jpeg'). Defaults to 'png'.webhook_url(optional string): URL to send a webhook notification upon completion.
(Refer to
MagicResizeAutomateRequestintypes.tsfor the full list of options.)
Returns
(Promise<MagicResizeAutomateResponse>): A promise that resolves to an object containing details of the initiated magic resize job, typically including a job_id.
Usage Example
import { ImagineoAIClient } from "@imagineoai/javascript/browser"; // Or /server for Node.js
const imagine = new ImagineoAIClient({ apiKey: "YOUR_API_KEY" });
async function main() {
try {
const result = await imagine.automate.magicResize({
image_url: "https://example.com/your-image.jpg",
target_width: 1024,
target_height: 768,
prompt: "A beautiful landscape with a sunset",
mode: "fill",
});
console.log("Magic resize initiated:", result.job_id);
} catch (error) {
console.error("Error during magic resize:", error);
}
}
main();