---
title: "prepareThumbnail(of:completionHandler:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiimage/preparethumbnail(of:completionhandler:)"
---

# prepareThumbnail(of:completionHandler:)

Creates a thumbnail image at the specified size asynchronously on a background thread.

## Declaration

```swift
func prepareThumbnail(of size: CGSize, completionHandler: @escaping @Sendable (UIImage?) -> Void)
```

```swift
func byPreparingThumbnail(ofSize size: CGSize) async -> UIImage?
```

## Parameters

- `size`: The desired size of the thumbnail.
- `completionHandler`: The completion handler to call when the thumbnail is ready. The handler executes on a background thread. The completion handler takes the following parameters:

## Discussion

Discussion When displaying an image in a UIImageView, you can use the view’s contentMode property to clip or scale the image automatically. But when the native image size is much larger than the bounds of the view, decoding the full size image creates unnecessary memory overhead. By creating a thumbnail image at a specified size with this method, you avoid the overhead of decoding the image at its full size. This method asynchronously creates the thumbnail image on a background thread and calls the completion handler on that thread. If your app updates the UI in the completion handler, schedule the UI update on the main thread.

## See Also

### Loading images for display

- [preparingForDisplay()](uikit/uiimage/preparingfordisplay().md)
- [prepareForDisplay(completionHandler:)](uikit/uiimage/preparefordisplay(completionhandler:).md)
- [preparingThumbnail(of:)](uikit/uiimage/preparingthumbnail(of:).md)
