Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Pad an image so its aspect ratio approximates a specified value
ResourceFunction["AspectRatioImagePad"][image,ratio] pads image with black pixels so its aspect ratio approximates ratio. | |
ResourceFunction["AspectRatioImagePad"][image] uses an aspect ratio of 1. | |
ResourceFunction["AspectRatioImagePad"][image,ratio,padding] pads image so its aspect ratio approximates ratio with the value or method specified by padding. |
Pad an image to make it square:
In[1]:= | ![]() |
Out[1]= | ![]() |
Measure the aspect ratio of the new image:
In[2]:= | ![]() |
Out[2]= | ![]() |
Pad an image to a specific aspect ratio:
In[3]:= | ![]() |
Out[3]= | ![]() |
Pad using the "TextureSynthesis" padding scheme:
In[4]:= | ![]() |
Out[4]= | ![]() |
For very small images, where adding rows or columns of pixels accounts for relatively large changes in the aspect ratio of the resulting image, the function may fail to apply appropriate padding:
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
Use AspectRatioImagePad for art by nestedly applying a function to a starting image that pads it to a goal ratio, then inverts the image, and pads it with one column or row of white pixels on each side:
In[7]:= | ![]() |
Out[7]= | ![]() |
Wolfram Language 14.0 (January 2024) or above
This work is licensed under a Creative Commons Attribution 4.0 International License