Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Swift - How to build a useful camera app that crops the photos to square?

Hi, Firstly, I'm sad there is no Swift camera content on the site. Hopefully, the community will have answers. I'm trying to build a camera app that is actually useful (not just a working camera app; I've built three of those from resources on the net). Some problems are: the size of the images the camera takes (iPhone 5/6) are way to big. I just need these photos to be "Instagram size" on the screen. Also, the size of the forward camera is different from the size of the rear camera, which screws up my ability to save and retrieve them. (I know I can have an imageView with .AspectFit, but that's not what I need). Here are some of my questions:

I need to crop the image (whether it is taken from the front or rear camera) to the same size, that being 170x170. So whether the camera is front, back, or Library, I need to squeeze the image down (with aspect) to a 170x170 square, and if the original is not square, I need to present the sort of view (like Instagram) to allow the user to make it square. Now, I'm not making an Instagram clone, but actually, that would answer a lot of my questions. If someone can explain to me how to do the thing Instagram does (regarding the size of the images, regardless of source), that would be great.

This will not only be helpful for me, but I guarantee it will be helpful to all Treehouse learners, as this topic is NOT covered well on the internet. There are some poor Stack Overflow examples, and poorer Apple Documentation, and only a couple Youtube videos that use Swift for a camera app, and they are poor too.

I would much appreciate the help. :)

Hi Tony,

I probably cant help much technically, as I am still learning, but I was originally doing an iOS course over on Udemy and one of the sessions on that was building an Instagram clone, Wondering if this would be any good to you.

It was something like the complete iOS 9 developer course by Rob Percival. It was a good course but it felt more like painting by numbers, which Is why I moved across to Treehouse.

Cheers, Marc

Hey Marc, Thanks for the reply and recommendation. I actually have taken that course and it's quite lacking. It doesn't discuss programing the camera or image, just saving and retrieving the images from a list of friends.

1 Answer

Ah fair enough Tony. I left that course just before that section so I never did it. Sorry I couldn't help more. Keep me posted as I'd be interested in doing something similar.