Creating Image Thumbnails Programmatically In iOS

Get a recipe that generates image thumbnails easily.

Gabriel Theodoropoulos
9 min readFeb 17, 2023
Photo by Anna Nekrashevich: https://www.pexels.com/photo/close-up-shot-of-a-white-card-8533651/

Working with images in iOS projects is not rare. There are various operations one could perform to an image, and sometimes such an operation is to create a thumbnail, meaning a smaller version, of the original image.

At first sight it might look like a complicated process involving a series of transformations that the image has to go through. That’s not true, though; the Core Graphics framework is here to support us, providing us with all the -really few- APIs we need to carry out such a task.

With that said, let’s get straight into the point and let’s find out what it takes in order to create image thumbnails easily. Once that’s out of the way, we’ll put it in motion in a pretty simple demo application.

Creating an image thumbnail

All we’re going to do is to implement a method that will be performing the thumbnail creation. You can define that method anywhere that’s convenient to you, but I strongly believe that the best place to keep it is in a UIImage extension. That way, it will be always available to all images.

So, let’s get started with that:

extension UIImage {
func createThumbnail(…

--

--

Gabriel Theodoropoulos

An iOS & macOS app maker writing code in Swift. Author of countless programming tutorials. Content creator. https://serialcoder.dev