Skip to main content

Stretch circles into squares and squish squares into circles

Project description is a Python utility for stretching circles into squares and squishing squares into circles. It requires Python 3.6 or later.


pip install squircle


import numpy as np
from PIL import Image

from squircle import to_circle, to_square

square = np.asarray('some-square-image.jpg'))
circle = to_circle(square)
and_back_to_square = to_square(circle)

there's 3 stretching methods you can choose from

>>> from squircle import methods
>>> list(methods.keys())
['fgs', 'stretch', 'elliptical']
>>> circle = to_circle(square, method='elliptical')

Stretching methods

Fernández-Guasti squircle (fgs)

The Fernández-Guasti squircle is used by default.

Simple Stretching (stretch)

This method "just linearly stretches each point radially so that the rim of the circle matches the rim of the square".

Elliptical grid mapping (elliptical)

"The way I went about this was to think of a line of constant x (as well as a line of constant y) getting mapped to an ellipse in the circle"

Schwarz-Christoffel conformal mapping

raise NotImplementedError. The math is difficult.


After pip install tox you can run squircle's (limited) test set with


On Ubuntu, you also need the following dependencies for numpy and matplotlib

sudo apt install python3-dev libjpeg-dev zlib1g-dev libfreetype6-dev

You can visually inspect the transformations by uncommenting the matplotlib code in and then invoking the tests directly with pytest instead of tox


but you'll need to install the dependencies of the tests manually, which you can do with pip install pytest numpy matplotlib pillow.


If you would like to help with this project, the open issues on GitHub should list some ideas.


This code is converted from the C++ sources on Chamberlain Fong's blog posts, which (I think) are based on his paper Analytical Methods for Squaring the Disc (2014).

The square image in test_images/ is and the circle is taken from Chamberlain Fong's blog posts.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

squircle-0.2.2.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

squircle-0.2.2-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page