<!--
{
  "availability" : [
    "macOS: 10.11.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextAttachmentContainer/image(forBounds:textContainer:characterIndex:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextAttachmentContainer(im)imageForBounds:textContainer:characterIndex:"
  },
  "title" : "image(forBounds:textContainer:characterIndex:)"
}
-->

# image(forBounds:textContainer:characterIndex:)

Returns the image object that the layout manager renders in the specified image bounds rectangle inside the text container.

```
func image(forBounds imageBounds: CGRect, textContainer: NSTextContainer?, characterIndex charIndex: Int) -> NSImage?
```

## Parameters

`imageBounds`

The rectangle in which the image is laid out.

`textContainer`

The text container in which the image is laid out.

`charIndex`

The character location inside the text storage for the attachment character.

## Return Value

The image rendered in the bounds rectangle.

## Discussion

The method should return an image appropriate for the target rendering context derived by arguments passed into this method. The `NSTextAttachment` implementation returns the text attachment’s [`image`](/documentation/AppKit/NSTextAttachment/image) when non-`nil`. If the image is `nil`, it returns an image based on the text attachment’s [`contents`](/documentation/AppKit/NSTextAttachment/contents) and [`fileType`](/documentation/AppKit/NSTextAttachment/fileType) properties.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)