Skip to content

Resize Image Canvas

By , Customer Success DirectorUpdated

Open this page in a new chat

Short answer

Add canvas.width and canvas.height to the image URL to put space around the image, in pixels or percent. Set the background with canvas.color, which is white by default, and place the image with canvas.position. Use canvas.aspectratio, such as 1:1, to give a mixed set of images the same shape.

After reading this you will know

  • How to add space around an image from its URL
  • How to set the canvas color, position, opacity and border
  • How to give many images the same aspect ratio

Add space around an image by making its canvas bigger with canvas options in the URL. Try it in the demo below.

Try it
Original image
Original
Image with the options applied
With options
F8DD6C
Border options3
D3D3D3
https://demo.sirv.com/skys.jpg?canvas.width=500&canvas.height=350&canvas.color=F8DD6C&canvas.position=center

canvas.width - sets the width of the canvas, in pixels or percentage (%). If you choose a value smaller than the width of the original image, the image will be cropped.

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.width=112%

Example image with wide canvas

canvas.height - sets the height of the canvas, in pixels or percentage (%). If you choose a value smaller than the height of the original image, the image will be cropped.

The image below has a 112% canvas width, so white is added to the left and right:

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.width=112%&canvas.height=260

Example image with wide canvas and fixed height canvas

canvas.color - sets the color of the background canvas. The values are set with hex RGB/RGBA or a color name. The default value is ‘white’. Here’s an example with dark orange (C16303):

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.width=112%&canvas.height=260&canvas.color=C16303

Example image with colored canvas

canvas.position - sets the position of the canvas behind the image. Other than the default ‘center’, the values are points on a compass, with ‘north’ at the top middle.

The allowed values are: north, northeast, northwest, center, south, southeast, southwest, east, and west.

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.width=112%&canvas.height=260&canvas.color=C16303&canvas.position=west

Example image with canvas aligned left

canvas.opacity - is set on a scale from 0 (transparent) to 100 (opaque). The default value is ‘100’. JPEG doesn’t support transparency, so the example below is served as PNG:

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.width=112%&canvas.height=260&canvas.color=C16303&canvas.opacity=50&format=png

Example image with semi-transparent canvas as PNG

The canvas border is great for setting a consistently sized border around an image. It can be used with or without the other canvas options.

canvas.border.width and canvas.border.height are set in px or %:

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.border.width=40

Example image with 40px border

To specify different widths and heights, use both options:

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.border.width=10&canvas.border.height=40

Example image with different border dimensions

canvas.border.color sets a color as a hex ref:

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.border.width=40&canvas.border.color=317bba

Example image with colored border

canvas.border.opacity adjusts the transparency - only applied to supporting images (not JPEG):

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.border.width=40&canvas.border.color=317bba&canvas.border.opacity=30

Example image with colored border

canvas.aspectratio sets an aspect ratio to the canvas, which is useful for making a varied set of images have uniform dimensions. Common aspect ratios are 4:3, 16:9, 1:1, 3:2, 5:4.

Each number can have any value from 1-99, as long as the difference is greater than 0.04 and smaller than 25.

https://sirv.sirv.com/Examples/test-sky.jpg?canvas.aspectratio=16:9&canvas.color=317bba

Example image with fixed canvas aspect ratio

Use the same aspect ratio on every image in a gallery to make all the images line up neatly.

Back to top