image icon indicating copy to clipboard operation
image copied to clipboard

[feature] copyCropSquircle function

Open Cyril212 opened this issue 3 years ago • 12 comments

Hi, first of all, I would like to thank you for this incredible library. It saved me an enormous amount of time!

Since I am working on a project which generates app icons, it would be great if you consider implementing copyCropSquircle feature.

Thanks in advance!

Cyril212 avatar Feb 14 '22 10:02 Cyril212

@Cyril212 @brendan-duncan was this feature been implemented? I am unable to find any reference to copyCropSquircle function in the code. The closest one is copyCropCircle but that isn't the same.

ekuleshov avatar Dec 31 '22 18:12 ekuleshov

I haven't implement rounded rectangles yet.

brendan-duncan avatar Dec 31 '22 23:12 brendan-duncan

@brendan-duncan it would be a handy feature that could be used to generate and update app icons (macos and windows) using Flutter tools like flutter_launcher_icons

ekuleshov avatar Dec 31 '22 23:12 ekuleshov

Yeah, it's on my list to do. Just have to figure out a good way to draw a rounded rectangle, and not call it squircle :-)

brendan-duncan avatar Jan 01 '23 00:01 brendan-duncan

Yeah, it's on my list to do. Just have to figure out a good way to draw a rounded rectangle, and not call it squircle :-)

That is good to hear.

Technically they are not the same. For their icons Apple uses superellipse.

It needs some form of Bezier path support, e.g. this Flutter package depends on the Path from Flutter https://github.com/Monksc/cupertino_rounded_corners/blob/master/lib/cupertino_rounded_corners.dart

Rounded corners should be simpler - kind of 4 times copyCropCircle you have, or an extension of calculateCircumference with the angle range input parameters to produce corner arcs.

BTW, it would be interesting to have an extension of the drawRect method with similar rounded corners support.

ekuleshov avatar Jan 01 '23 01:01 ekuleshov

Thanks for the info. Guess I'll have to live with the word "squicle" being a thing. I was thinking of adding a radius arg to drawRect and copyCrop (and copyResizeCropSquare). I want to avoid having to implement full spline path filling, so I'm looking at other solutions.

brendan-duncan avatar Jan 01 '23 01:01 brendan-duncan

A quick experiment: with a radius defining circles at the corners of rectangles, analytically discard pixels outside the corner circles to round the corners. Here's a test with a radius of 10:

squircle squircle_2

brendan-duncan avatar Jan 01 '23 02:01 brendan-duncan

And here is an outline version using lines and circle arcs: squircle

Much faster than dealing with splines. I'll go ahead and add a radius arg to drawRect, fillRect, and the crop functions and use this approach, unless this isn't quite what you're describing. I'll look up the Material spec to make sure I'm not too far off.

brendan-duncan avatar Jan 01 '23 03:01 brendan-duncan

@brendan-duncan thank you for looking into that. Especially on a New Years Eve. :)

It is a great progress without having support for path/curves. Maybe at some point in the future...

ekuleshov avatar Jan 01 '23 03:01 ekuleshov

Never a lack of things to work on. I'm just doing some quick experiments while the cake is in the oven :-)

brendan-duncan avatar Jan 01 '23 03:01 brendan-duncan

It does seem Material uses more rounded rectangles like I have above, and Apple uses more squircles. Guess I'll have to spend the time on cubic splines and path filling.

brendan-duncan avatar Jan 01 '23 04:01 brendan-duncan

It does seem Material uses more rounded rectangles like I have above, and Apple uses more squircles. Guess I'll have to spend the time on cubic splines and path filling.

That also would be an awesome addition to the image package.

ekuleshov avatar Jan 01 '23 15:01 ekuleshov