Optimize images for mobile with responsive images
A guide to using responsive images with srcset in your Shoporama theme, so mobile users get optimized images.
Mobile users should not have to download a 1200px image when their phone only displays 400px. With responsive images, you let the browser choose the right size, so the page loads faster and the customer gets a better experience. This is especially important on product lists and front pages, where many images are shown at once.

How Shoporama scales your images
Shoporama automatically optimizes your product images when they are shown in your store:
- Scaling. Images are scaled down to exactly the size your theme asks for, so the browser does not have to handle huge files.
- WebP conversion. Modern browsers automatically receive the WebP format, which is considerably smaller than JPG.
- Quality. Images are compressed according to the store's own quality setting. If it needs adjusting, write to support@shoporama.dk.
- Caching. Scaled images are saved, so scaling only happens the first time a size is requested.
How to scale an image in your theme
In your Smarty theme, you use the getSrc() method on an image. It is available on all image objects, such as $product->getImage(), $category->getImages(), and similar. It returns the URL of the scaled image:
<img src="<{$product->getImage()->getSrc(400, 400)}>" alt="<{$product->getName()}>">
Parameters for getSrc()
The method takes five parameters, and the last three are optional:
| Parameter | Description |
|---|---|
| $w | Width in pixels |
| $h | Height in pixels |
| $t | Scaling type: fit (fits inside, keeps the aspect ratio, default), box (fills the whole box and crops), or pad (the whole image on a white background in exactly the dimensions you ask for) |
| $format | Force a format: jpg, png, or webp (leave empty for automatic selection) |
| $quality | Quality 0-100. Shoporama always uses the store's own quality setting, so you can leave it out. See image quality and image format. |
Responsive images with srcset
When you want to serve different sizes to mobile, tablet, and desktop, you combine getSrc() with the HTML attribute srcset. The browser then automatically chooses the size that matches the screen resolution:
<img
src="<{$product->getImage()->getSrc(400, 400)}>"
srcset="<{$product->getImage()->getSrc(400, 400)}> 400w,
<{$product->getImage()->getSrc(800, 800)}> 800w,
<{$product->getImage()->getSrc(1200, 1200)}> 1200w"
sizes="(max-width: 640px) 400px,
(max-width: 1024px) 800px,
1200px"
alt="<{$product->getName()}>"
loading="lazy"
>
Tip: Add loading="lazy" to images further down the page, so they only load when the customer scrolls to them.
Example: Cropped product image with a fixed aspect ratio
If you want all images in the same square format, for example on a product list, use the box scaling type:
<img src="<{$product->getImage()->getSrc(600, 600, 'box')}>" alt="<{$product->getName()}>">
Example: The whole image in a fixed format, for example for Facebook
In some places, the image must have exact dimensions without any of the product being cropped. This applies, for example, to images for Facebook and other services that fetch the image directly from your store, where you cannot control the display with CSS. Use the pad scaling type:
<{if $product->getImage()}>
<meta property="og:image" content="<{$webshop->getUrl()|escape}><{$product->getImage()->getSrc(1080, 1080, 'pad', 'jpg')}>">
<{/if}>
The image is scaled down so the whole product is included, and placed in the center of a white background of exactly 1080x1080. A tall image gets a white border on the sides, and a wide image gets a white border at the top and bottom. The border is white even when you choose png or webp, and transparent areas in the image become white. An image that is smaller than the dimensions is not enlarged, but is placed in the center with a wider border.
getSrc() returns an address without a domain, so put the store's address in front with $webshop->getUrl() when the image is used outside the store, as in the example. This only works where your theme fetches the image itself with getSrc(). Your custom product feeds use their own fixed size and cannot use pad. The Google Shopping and Partner Ads feeds, on the other hand, can send the whole image on a white, square background if you check Submit square images (the entire image on a white background) in the Common to all feeds card under Products → Product feeds. Read more in Set up your Google Shopping feed in Shoporama.
Example: Force WebP
If your store uses a different default format, you can force WebP, for example on thumbnails:
<img src="<{$product->getImage()->getSrc(200, 200, 'box', 'webp')}>" alt="">
Tip: Always upload images in high resolution, at least 1200px on the longest side. Shoporama scales down to the requested size, but cannot make a small image sharper. See also image quality and image format.
Frequently asked questions
Do I need to do anything myself, or does it happen automatically?
If you use one of Shoporama's standard themes, such as Delaware, responsive images are already set up for you. You only need to think about it if you customize the theme yourself or build a new one.
How much difference does it make to the customer experience?
A lot. A full product image at 1200x1200 can take up several hundred kilobytes, while a 400x400 mobile version is typically under 50 KB. On a phone with a poor connection, that can be the difference between a fast page and a customer who leaves the store.
What is the difference between fit, box, and pad?
fit keeps the image's original aspect ratio and fits it inside the given box, so the file keeps the image's own proportions and can be smaller than the box in one direction. box fills the whole box and crops whatever does not fit. pad gives exactly the box's dimensions without cropping, by placing the whole image on a white background. Use box for uniform product lists, fit for the product page, where the whole image should be shown, and pad when you need both the exact dimensions and the whole product, for example for Facebook.
Can I change the size directly in the image URL?
No. Shoporama only creates the sizes your theme has asked for with getSrc(). If you change the dimensions in a URL by hand, you are redirected to another size of the image that already exists. If you need a new size, for example in a feed you build yourself in the theme, call getSrc() with those dimensions in the theme, and use the URL it returns.
Can I choose pad in my theme settings?
No. In the store, pad is only used where the theme's code asks for it. The Image fit setting in the built-in themes only changes how the image is displayed in the browser. If you choose Show entire image in Montana or Contain in Delaware, the whole product is already shown in the store.
Are images scaled every time the page is shown?
No. Shoporama saves the scaled image the first time it is requested, so it is fast on all subsequent visits. You do not need to think about caching yourself.
Will Google PageSpeed penalize me for large images?
Yes, if you deliver images that are too large to mobile. If you use srcset and sizes correctly, you usually get rid of "Properly size images" warnings in PageSpeed Insights.
Does this affect my ranking on Google?
Mobile page speed is part of Google's assessment. Faster image loading can improve Core Web Vitals (especially LCP), which is good for SEO. It is not magic, but it helps.
Can I use the same approach for blog or landing page images?
Yes. All image objects in Shoporama have getSrc(). It works the same way for products, categories, landing pages, blog posts, and brand logos.
Do you need help customizing your theme so images load optimally on mobile? Write to support@shoporama.dk.
Related articles
Images on landing pages
How to upload images to a landing page in Shoporama and show them correctly in your theme with getImages() and getSrc().
Delaware theme: settings and customization
A complete guide to Delaware and DelawareDK in your Shoporama store: theme settings, footer menus, mega menu, colors, payment icons, Trustpilot,...
Shoporama themes: an overview of all free store themes
A complete overview of all free themes in Shoporama: Delaware, DelawareDK, California, Alaska 2, Washington, Montana, and the classic Smarty 2...
How to upgrade your theme to Smarty 4
Upgrade your Shoporama store from Smarty 2 to Smarty 4. Smarty 4 is faster, more secure, and runs on PHP 8.
Related features
CLS (Cumulative Layout Shift)
CLS measures how much content unexpectedly moves while a page loads. Learn the causes, thresholds, and fixes that improve your Core Web Vitals score.
Core Web Vitals
Core Web Vitals (LCP, INP, CLS) are Google's metrics for page speed and user experience. Learn the thresholds, how to optimize, and what they mean...
WebP
WebP is an image format with smaller file sizes than JPEG and PNG. Learn about WebP, image optimization, and faster page speed for online stores.
Image Archive
Collect all your images in one place. Upload once, organize them in folders, and use them on products, categories, and pages or directly in your text.
Responsive website
A responsive website adapts automatically to mobile, tablet, and desktop. Learn why it matters for SEO, conversion, and user experience in your store.