توسيع محتوى صورة باستخدام ميزة "الرسم الخارجي" في Imagen
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توضّح هذه الصفحة كيفية استخدام ميزة التوسيع التلقائي باستخدام Imagen من أجل
توسيع محتوى الصورة إلى ما بعد حدودها الأصلية
باستخدام حِزم تطوير البرامج (SDK) الخاصة بـ Firebase AI Logic.
التوسيع الخارجي هو نوع من التعديل المستند إلى القناع. القناع هو طبقة رقمية
تحدّد المنطقة المحدّدة التي تريد تعديلها.
طريقة العمل: يمكنك تقديم صورة أصلية وصورة مقنّعة مطابقة، سواء تم إنشاؤها تلقائيًا أو قدّمتها أنت، وتحدّد هذه الصورة قناعًا للمنطقة الجديدة الموسّعة. يمكنك أيضًا تقديم طلب نصي اختياري يصف ما تريده في المنطقة الموسَّعة، أو يمكن للنموذج أن يقرّر بذكاء ما سيستمر بشكل منطقي في المشهد الحالي. ينشئ النموذج المحتوى الجديد ويملأ المنطقة المخفية.
على سبيل المثال، يمكنك تغيير نسبة العرض إلى الارتفاع في صورة أو إضافة المزيد من سياق الخلفية.
لا تتوفّر هذه الميزة إلا عند استخدام Vertex AI Gemini API كموفّر لواجهة برمجة التطبيقات.
إذا لم يسبق لك إجراء ذلك، أكمل دليل بدء الاستخدام الذي يوضّح كيفية إعداد مشروعك على Firebase وربط تطبيقك بـ Firebase وإضافة حزمة تطوير البرامج (SDK) وتهيئة خدمة الخلفية لمزوّد واجهة برمجة التطبيقات الذي اخترته وإنشاء مثيل ImagenModel.
الطُرز التي تتيح هذه الإمكانية
توفّر Imagen إمكانية تعديل الصور من خلال نموذج capability:
imagen-3.0-capability-001
يُرجى العِلم أنّه بالنسبة إلى طُرز Imagen، لا يتوفّر الموقع الجغرافي global.
توسيع محتوى صورة
قبل تجربة هذا النموذج، أكمل قسم
قبل البدء في هذا الدليل
لإعداد مشروعك وتطبيقك.
يوضّح المثال التالي كيفية توسيع صورة إلى ما بعد حدودها الأصلية
— باستخدام قناع محدّد في صورة تقدّمها.
يجب تقديم الصورة الأصلية وطلب نصي والصورة التي تم إخفاء أجزاء منها. يُرجى ملاحظة ما يلي بشأن الصورة الأصلية والصورة المخفية:
يجب أن تكون أبعاد الصورة المقنّعة بالبكسل هي أبعاد الحجم المستهدف للصورة النهائية التي تم توسيعها.
يجب أن تتضمّن الصورة الأصلية مساحة متروكة إضافية لتتطابق مع أبعاد البكسل الخاصة بالصورة المخفية.
إنّ تقديم طلب نصي هو أمر اختياري إذا أردت أن يقرّر النموذج بشكل ذكي ما سيتم إضافته بشكل منطقي إلى المشهد الحالي. إذا كنت تريد محتوًى معيّنًا في المنطقة الموسَّعة، عليك تحديد ذلك في طلب نصي.
Swift
لا تتوافق لغة Swift مع تعديل الصور باستخدام نماذج Imagen. يُرجى التحقّق مجددًا في وقت لاحق من هذا العام.
Kotlin
لتوسيع صورة، استخدِم
editImage()
واضبط إعدادات التعديل على ImagenEditMode.OUTPAINT.
يُرجى العِلم أنّه يمكنك اختياريًا استخدام
outpaintImage()
بدلاً من editImage()، ولست بحاجة إلى تحديد وضع التعديل.
لتوسيع صورة، استخدِم
editImage()
واضبط إعدادات التعديل على ImagenEditMode.OUTPAINT.
يُرجى العِلم أنّه يمكنك اختياريًا استخدام
outpaintImage()
بدلاً من editImage()، ولست بحاجة إلى تحديد وضع التعديل.
لا تتوافق نماذج Imagen مع Unity عند تعديل الصور. يُرجى التحقّق مجددًا في وقت لاحق من هذا العام.
أفضل الممارسات والقيود
ننصحك بتوسيع القناع عند تعديل صورة. يمكن أن يساعد ذلك في تنعيم حواف التعديل وجعلها تبدو أكثر إقناعًا. بشكل عام، ننصح بقيمة تمدّد تبلغ% 1 أو% 2 (0.01 أو 0.02).
تاريخ التعديل الأخير: 2025-09-10 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-09-10 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["\u003cbr /\u003e\n\n\n| **Preview** : Using the Firebase AI Logic SDKs to access Imagen models is a feature that's in Preview, which means that it isn't subject to any SLA or deprecation policy and could change in backwards-incompatible ways.\n|\n| Editing with Imagen is only supported if you're using the\n| Vertex AI Gemini API. It's also currently only supported for\n| Android and Flutter apps. Support for other platforms is coming later in the\n| year.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis page describes how to use *outpainting* using Imagen to\n**expand the content of an image beyond its original borders**\nusing the Firebase AI Logic SDKs.\n\nOutpainting is a type of *mask-based editing* . A *mask* is a digital overlay\ndefining the specific area you want to edit.\n\n\n**How it works**: You provide an original image and a\ncorresponding masked image --- either auto-generated or provided by you --- that\ndefines a mask of the new, expanded area. You can also optionally provide a\ntext prompt describing what you want in the expanded area, or the model can\nintelligently decide what will logically continue the existing scene. The\nmodel generates the new content and fills in the masked area.\n\n\nFor example, you can change an image's aspect ratio or add more background\ncontext.\n\n\u003cbr /\u003e\n\n[arrow_downward Jump to code](#expand-image)\n\nBefore you begin\n\n\n|----------------------------------------------------------------------------|\n| *Only available when using the Vertex AI Gemini API as your API provider.* |\n\n\nIf you haven't already, complete the\n[getting started guide](/docs/ai-logic/get-started), which\ndescribes how to set up your Firebase project, connect your app to Firebase,\nadd the SDK, initialize the backend service for your chosen API provider, and\ncreate an `ImagenModel` instance.\n| **This guide assumes you're using the latest\n| Firebase AI Logic SDKs.** If you're still using the \"Vertex AI in Firebase\" SDKs, see the [migration guide](/docs/ai-logic/migrate-to-latest-sdk).\n\nModels that support this capability\n\n\nImagen offers image editing through its `capability`\nmodel:\n\n- `imagen-3.0-capability-001`\n\n\nNote that for Imagen models, the `global` location is\n***not*** supported.\n\n\u003cbr /\u003e\n\nExpand content of an image\n\n\n|---------------------------------------------------------------------------------------------------------------------------------------|\n| *Before trying this sample, complete the [Before you begin](#before-you-begin) section of this guide to set up your project and app.* |\n\n\u003cbr /\u003e\n\nThe following sample shows how to expand an image beyond its original borders\n--- using a mask defined in an image that you provide.\nYou provide the original image, a text prompt, and the masked image. Note the\nfollowing about the original and masked image:\n\n- The masked image must have the pixel dimensions of the targeted size of the\n final outpainted image.\n\n- The original image must include additional padding to match the pixel\n dimensions of the masked image.\n\nProviding a text prompt is optional if you want the model to intelligently\ndecide what will logically continue the existing scene. If you want specific\ncontent within the expanded area, you need to specify that in a text prompt. \n\nSwift\n\nImage editing with Imagen models isn't supported for Swift. Check back later this year!\n\nKotlin\n\nTo expand an image, use\n[`editImage()`](/docs/reference/kotlin/com/google/firebase/ai/ImagenModel#editImage(kotlin.collections.List,kotlin.String,com.google.firebase.ai.type.ImagenEditingConfig))\nand set the editing config to use `ImagenEditMode.OUTPAINT`.\n\nNote that you can optionally use\n[`outpaintImage()`](/docs/reference/kotlin/com/google/firebase/ai/ImagenModel#outpaintImage(com.google.firebase.ai.type.ImagenInlineImage,com.google.firebase.ai.type.Dimensions,com.google.firebase.ai.type.ImagenImagePlacement,kotlin.String,com.google.firebase.ai.type.ImagenEditingConfig))\ninstead of `editImage()`, and you don't need to specify the editing mode.\n| **Note:** The SDK provides a helper function [`generateMaskAndPadForOutpainting()`](https://firebase.google.com/docs/reference/kotlin/com/google/firebase/ai/type/ImagenMaskReference) to generate a masked image with your specified dimensions and the original image centered within the expanded area.\n\nCheck out the\n[quickstart for sample code for outpainting](https://github.com/firebase/quickstart-android/blob/master/firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenViewModel.kt).\n\n\u003cbr /\u003e\n\nJava\n\nTo expand an image, use\n[`editImage()`](/docs/reference/android/com/google/firebase/ai/ImagenModel#editImage(kotlin.collections.List,kotlin.String,com.google.firebase.ai.type.ImagenEditingConfig))\nand set the editing config to use `ImagenEditMode.OUTPAINT`.\n\nNote that you can optionally use\n[`outpaintImage()`](/docs/reference/android/com/google/firebase/ai/ImagenModel#outpaintImage(com.google.firebase.ai.type.ImagenInlineImage,com.google.firebase.ai.type.Dimensions,com.google.firebase.ai.type.ImagenImagePlacement,kotlin.String,com.google.firebase.ai.type.ImagenEditingConfig))\ninstead of `editImage()`, and you don't need to specify the editing mode.\n| **Note:** The SDK provides a helper function [`generateMaskAndPadForOutpainting()`](https://firebase.google.com/docs/reference/android/com/google/firebase/ai/type/ImagenMaskReference) to generate a masked image with your specified dimensions and the original image centered within the expanded area.\n\nCheck out the\n[quickstart for sample code for outpainting](https://github.com/firebase/quickstart-android/blob/master/firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/media/imagen/ImagenViewModel.kt).\n\n\u003cbr /\u003e\n\nWeb\n\nImage editing with Imagen models isn't supported for Web apps. Check back later this year!\n\nDart\n\nTo expand an image, use\n[`editImage()`](https://pub.dev/documentation/firebase_ai/latest/firebase_ai/ImagenModel/editImage.html)\nand set the editing config to use `ImagenEditMode.OUTPAINT`.\n\nCheck out the\n[quickstart for sample code for outpainting](https://github.com/firebase/flutterfire/blob/main/packages/firebase_ai/firebase_ai/example/lib/utils/image_utils.dart).\n\n\u003cbr /\u003e\n\nUnity\n\nImage editing with Imagen models isn't supported for Unity. Check back later this year!\n\nBest practices and limitations\n\n\nWe recommend dilating the mask when editing an image. This can help smooth\nthe borders of an edit and make it seem more convincing. Generally, a dilation\nvalue of 1% or 2% is recommended (`0.01` or `0.02`).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n[Give feedback\nabout your experience with Firebase AI Logic](/docs/ai-logic/feedback)\n\n\u003cbr /\u003e"]]