Responsive design necessitates displaying pictures in many sizes, usually much smaller than the original. Rather than delivering large, full-sized images and relying on the browser to resize them, you can programmatically scale them immediately without needing to use editing tools.
Going further, you can automate art direction with advanced scaling features such as smart resize, smart crop, and object zoom.
Typical use cases:
-/preview/ when you need to put an image inside a known tile without
changing its proportions, and ok with empty space. E.g. you have a layout of
300x400, and neither horizontal nor vertical photos shouldn’t escape these borders.-/scale_crop/.-/smart_resize/
that will generate missing parts of the picture.-/scale_crop/smart/ to crop a background, but keep important objects.-/crop/face/, -/border_radius/, and
-/setfill/ operations.These operations, like other URL API functions, are non-destructive, handled on the server side, and sent to the browser in the requested size.
Note: The order of operations is essential. For instance, when you resize an image first, the ensuing crop operation will use the coordinates of the resized image.
-/preview/
-/preview/:dimensions/
Downscales an image proportionally to fit the given width and height in pixels. Use it as a default resizing method when you need to save image proportions without calculating precise width or height.
:dimensions — width and height in pixels separated by x.
Example: 320x240.
If the dimensions are not specified, it’ll be 2048x2048.
/:uuid/-/preview/
/:uuid/-/preview/300x500/
-/resize/:one_or_two_dimensions/
Resizes an image to one or two dimensions. When you set both width and height explicitly, it may result in a distorted image. If you specify either side, this operation will preserve the original aspect ratio and resize the image accordingly.
:one_or_two_dimensions — width and height in pixels separated by x,
one of the values can be omitted.
Examples: 320x240, 320x, x240.
/:uuid/-/resize/320x240/
/:uuid/-/resize/320x/
/:uuid/-/resize/x240/
-/stretch/:mode/
Sets the resize and scale_crop behavior when a source image is smaller than
the requested dimensions. The order is important: a stretch operation applies
to its following resize or scale_crop. You can use multiple resizing
operations with individual stretch behavior for each one.
:mode — one of the following values:
on — an image can be scaled up (default).off — an image won’t be scaled up.fill — no image scaling up. The
background color fills the remaining parts.-/smart_resize/:dimensions/
Content-aware resize helps retaining original proportions of faces and other visually sensible objects while resizing the rest of the image using intelligent algorithms.
:dimensions — width and height in pixels separated by x. 320x240.Smart resize works best for solid, gradient, and homogeneous backgrounds that’ll be expanded. If background stretching can’t be done without artifacts, a solid fill with a matching color will be applied instead.
Note that we are working on improving Smart resize and behavior may change. Contact us if you found out regression.
-/crop/:dimensions/
-/crop/:dimensions/:alignment/
Crops an image by using specified dimensions and alignment.
:dimensions — width and height in pixels or percents separated by
x.% or p
char.320x240, 50px240, 30%x25%.:alignment — horizontal and vertical offsets in pixels or percents
separated by ,.% or p char.100,-50, 50p,240, 30%,25%.center,
top, right, bottom, left.0,0 value is used.In URLs, % is an escape character and should be encoded with %25 escape
sequence, e.g. -/crop/200x200/80%25,80%25/. For convenience, you can use
the p shortcut for percent which doesn’t require encoding.
If given dimensions are greater than the ones of the original image,
the image is rendered inside a color-filled box. The color of that box
can be changed via the setfill operation.
-/crop/:ratio/
-/crop/:ratio/:alignment/
Crops the image to the specified aspect ratio, cutting off the rest of the image.
:ratio — two numbers greater than zero separated by :.:alignment — horizontal and vertical offsets in pixels or percents
separated by ,.% or p char.100,-50, 50p,240, 30%,25%.center,
top, right, bottom, left.center value is used.In URLs, % is an escape character and should be encoded with %25 escape
sequence, e.g. -/crop/4:3/80%25,80%25/. For convenience, you can use
the p shortcut for percent which doesn’t require encoding.
-/crop/:tag/
-/crop/:tag/:ratio/
-/crop/:tag/:ratio/:alignment/
-/crop/:tag/:dimensions/
-/crop/:tag/:dimensions/:alignment/
Crops the image to the object specified by the :tag parameter.
:tag — one of the following values:
face — the largest detected face in the image is used as
a crop basis.image — the whole image is used as a crop basis.:ratio — two numbers greater than zero separated by :.
Ratio is the quotient from the division of these numbers.
The found object fits into the given aspect ratio.:dimensions — width and height in percents separated by x.%
or p char.150%x150%, 200%x100%.:alignment — horizontal and vertical offsets in percentage
values separated by comma (,).% or p char.30%,25%, 30p,25pcenter,
top, right, bottom, left.center value is used.In URLs, % is an escape character and should be encoded with %25 escape
sequence, e.g. -/crop/face/4:3/80%25,80%25/. For convenience, you can use
the p shortcut for percent which doesn’t require encoding.
-/scale_crop/:dimensions/
-/scale_crop/:dimensions/:alignment/
Scales an image until it fully covers the specified dimensions; the rest gets cropped. Mostly used to place images with various dimensions into placeholders (e.g., square shaped).
:dimensions — width and height in pixels separated by x.320x240, 440x440.:alignment — horizontal and vertical offsets in percentage
values separated by comma (,).% or p char.30%,25%, 30p,25pcenter,
top, right, bottom, left.0,0 value is used.In URLs, % is an escape character and should be encoded with %25 escape
sequence, e.g. -/scale_crop/440x440/80%25,80%25/. For convenience, you can use
the p shortcut for percent which doesn’t require encoding.
-/scale_crop/:dimensions/:type/
-/scale_crop/:dimensions/:type/:alignment/
Switching the crop type to one of the smart modes enables the content-aware
mechanics. Uploadcare applies AI-based algorithms to detect faces and other
visually sensible objects to crop the background and not the main object.
:dimensions — width and height in pixels separated by x.320x240, 440x440.:type — one of the following values:
smart (alias for smart_faces_objects_points)smart_faces_objectssmart_faces_pointssmart_objects_faces_pointssmart_objects_facessmart_objects_pointssmart_pointssmart_objectssmart_faces:alignment — horizontal and vertical offsets in percentage
values separated by comma (,).% or p char.30%,25%, 30p,25pcenter,
top, right, bottom, left.0,0 value is used.
Alignment doesn’t affect smart crop behavior and works as a fallback when no smart crop can’t detect any objects.In URLs, % is an escape character and should be encoded with %25 escape
sequence, e.g. -/scale_crop/440x440/smart/80%25,80%25/. For convenience,
you can use the p shortcut for percent which doesn’t require encoding.
Content-aware mechanics of the smart crop are based on the following methods of image analysis:
:type is set to smart_faces. Face detection identifies and
locates human faces in digital images.:type is set to smart_objects. Object detection
identifies and locates most visually important regions in the image.:type is set to smart_points. This method
analyses image pixels to find the high contrast corners in the image, useful
for abstract, landscape, and art images. The corner points have much less
semantic information than other methods and designed to be used as a fallback.The methods you include separating by underscore are applied sequentially. The
algorithm switches to the next method only if no regions were found by the
previous one. For example smart_faces_objects_points applies face detection
initially as the first step. Only when no faces are found on an image, the
object detection will be used. Finally, when no objects are found, the corner
points will be detected.
Smart crop always tries to save the maximum amount of pixels from the original image. It first applies scale operation and then cuts horizontal or vertical excesses.
-/trim/
-/trim/:tolerance/:padding/
Removes insignificant edges of the image, such as solid backgrounds or fully transparent areas.
By default, this operation only removes colors very close to the background.
It can be adjusted with a color distribution :tolerance parameter, ranging from 0 to 99.
Since objects cropped to the edges can look unnatural, you can optionally add :padding,
specified as a percentage of the resulting image, ranging from 0% to 100%.
-/border_radius/:radii/
-/border_radius/:radii/:vertical_radii/
Applies transparency mask with round or elliptical corners to the image.
The syntax and effect is pretty much similar to the border-radius property in CSS.
E.g. border-radius: 10px 100px / 50%; would become -/border_radius/10,100/50%/.
The differences are:
px for absolute values should be omitted.If :vertical_radii is omitted, :radii used for both horizontal and
vertical radii. Both :radii and :vertical_radii should contain
1 to 4 numbers separated by comma. Each number could be an absolute radius
in pixels or a percentage value ended with % or p char.
In URLs, % is an escape character and should be encoded with %25 escape
sequence, e.g. -/border_radius/10%25/50%25/. For convenience, you can use
the p shortcut for percent which doesn’t require encoding.
-/setfill/:color/
Sets the fill color used with crop,
stretch or when converting an alpha channel enabled
image to JPEG.
:color — color in hexadecimal notation with optional transparency.99ff99, 9f9, 99ff9920.-/zoom_objects/:zoom/
Zoom objects operation is best suited for images with solid or uniform backgrounds.
:zoom — sets the object’s size in the image from 1 to 100.As a result of the operation, the object’s size in the image will change.
The resolution of the image after the operation will remain the same.
For example, an object in an image with applied operation -/zoom_objects/100/
is the object that occupies the maximum area of this image.
-/autorotate/yes/
-/autorotate/no/
The default behavior goes with parsing EXIF tags of original images and rotating
them according to the “Orientation” tag. This is what we call autorotation.
-/autorotate/no/ allows turning off the default behavior.
-/rotate/:angle/
Right-angle image rotation, counterclockwise. The value of :angle must be a
multiple of 90.
-/flip/
Flips images.
-/mirror/
Mirrors images.