ayushn21 / AvatarImageView

DEPRECATED!!! --- Use https://github.com/neone/NDAvatarApp
MIT License
255 stars 37 forks source link

Choose smaller of the two dimensions or make a perfect circle #17

Open dannysood opened 7 years ago

dannysood commented 7 years ago

When width of image is bigger than height and it is taken as the radius the image drawn in circle is not perfect circle but a rectangle with two sides circular. Is ther ea way to force smaller of the two edges to be taken as reference. or maybe just fit the image the best way without losing orientation or aspect ratio in between a circle.

ayushn21 commented 7 years ago

Hi @dannysood,

I considered this case when I originally wrote the library. I decided not to support it at the time because I couldn't think of a reason why a user would not lock the height equal to the width in AutoLayout if they wanted a circular profile picture.

I am still not keen on having this functionality in as I don't think it is required and would be unnecessary bloat in my opinion. Code would be required to compute the square in which to draw the circle and then centre it within the rectangular bounds. Fairly trivial logic, but no point in adding unnecessary code in!

Could you please explain what your use case is for which you would need this functionality?

Thanks, Ayush

dannysood commented 7 years ago

The reason I faced this issue is because I am trying to fetch images from social networks which may or may not be perfect squares. A lot of platforms allow you to upload pictures in any dimension and then select a part of it to show as thumbnail. As a result when such images are pulled and without the metadata of where the square thumbnail is its difficult to exactly how to draw the square thumbnail that can be converted to perfect circle. Doing aspect fit instead of aspect fill inside the circle when its drawn takes care of such scenarios in easy way. A lot of apps dont really want to complicate user flow and forcing user to select a dp in a cropping tool as a first step is a extra avoidable step when onboarding new customers which already is an expensive process.

dannysood commented 7 years ago

I think I can figure out a way around it but this is something that other users may also feel and might expect this to be available as I expected. :)

ayushn21 commented 7 years ago

Ah I see what you mean, you're referring to the dimensions of the image, not the ImageView.

I agree that a cropping tool is an extra avoidable step. Setting the image resizing to Aspect Fill would expand the image to fill the bounds of the ImageView, after which the circle shape would appear correctly.

This is something I would like to leave in control of the user though; in my opinion it is not within the scope of the library to handle those settings.

What are you thoughts on this? Is there a code change in the library code that you have in mind to work around this issue?

dannysood commented 7 years ago

Setting the image resizing to Aspect Fill would expand the image to fill the bounds of the ImageView, after which the circle shape would appear correctly. This for some reason hasnt worked properly for me and I thought that this property was being bypassed somehow. THe image is always in aspectfit. The only special case here is that the uiimage is inside a stackview maybe that is to blame?

ayushn21 commented 7 years ago

Ah, that's strange. I don't see why the Stack View should be a problem. I'm not setting the scaling mode anywhere inside the library. Could you please extract the bit of code you're facing a problem with into a sample project and upload it? It would help me investigate and diagnose the problem. Thanks!

dannysood commented 7 years ago

Ill need some time for that. I am on a pretty tight deadline. You can go ahead and close this for now but I will get back to this with an update and we can reopen and debug it then.

ayushn21 commented 7 years ago

No worries, I'll try investigating myself when I get some time. I'll leave it open in case someone else encounters the same issue :)