Blog

  • Converting PrestaShop Images to WebP

    Following on from my image cleanup tool, I’ve been looking at ways to speed up PrestaShop sites without touching the theme or installing heavy modules. The obvious target? Images.

    Product images are usually the biggest chunk of any e-commerce page. On a typical category page with 20 products, you’re easily loading several megabytes of JPEGs. Multiply that across thousands of visitors and it adds up quickly — both for page speed and bandwidth costs.

    Why WebP?

    WebP has been around for years now, and browser support is essentially universal at this point. The format typically delivers 25-35% smaller file sizes compared to JPEG at the same visual quality. For a store with 10,000 product images, that’s a significant reduction in what visitors have to download.

    The catch is that PrestaShop doesn’t support WebP natively. You can’t just upload WebP images through the back office. The regeneration tools only output JPEG and PNG.

    What I Built

    Rather than mess about with core files or install modules that hook into the image generation process, I went for a simpler approach.

    The tool converts your existing product images to WebP format, placing the new files alongside the originals. Then it adds some rewrite rules to your .htaccess that automatically serve the WebP version to browsers that support it. Browsers that don’t? They get the original JPEG or PNG.

    Your image URLs don’t change. The product pages don’t change. The swap happens at the server level, completely transparent to both PrestaShop and your visitors.

    How It Works

    1. Upload the PHP file to your PrestaShop root
    2. Change the default password
    3. Run a scan to see what you’ve got
    4. Preview with a dry-run
    5. Convert your images
    6. Add the .htaccess rules (creates a file in /img/p/)
    7. Delete the tool when you’re done

    The conversion runs in batches so it doesn’t time out on larger catalogues. You get a live progress log showing what’s being converted and how much space you’re saving.

    If you change your mind later, there’s a full revert option. It’ll delete all the WebP files and remove the .htaccess rules, putting everything back to how it was.

    The .htaccess Bit

    This took a bit of figuring out. PrestaShop’s main .htaccess does URL rewriting for friendly image URLs — and those rules have [L] flags that stop processing before any WebP rules at the bottom would be reached.

    The solution is to place the WebP rules in a separate .htaccess file inside /img/p/. This gets processed when Apache actually goes to serve the file, after PrestaShop’s URL rewriting has already done its job.

    The rules check the browser’s Accept header for image/webp. If the browser supports it and a WebP version of the requested file exists, it serves that instead. If either condition fails, the original file gets sent.

    It also adds a Vary header so caching proxies know to store both versions. Your main .htaccess stays completely untouched.

    It’s Free

    I’ve put it on GitHub alongside the cleanup tool. Same MIT licence, same deal — use it however you like.

    GitHub: PrestaShop WebP Converter

    As always, back up before you start. The tool preserves your original images, so the risk is minimal, but it’s still modifying your .htaccess file. Better to have a backup and not need it.

    Results

    On a test site with around 8,000 product images totalling 2.3GB, the WebP conversion brought that down to about 1.6GB — roughly a 30% reduction. Page weight on category pages dropped noticeably, and the Lighthouse performance score went up a few points without any other changes.

    If you’re looking for a quick win on site speed without diving into theme optimisation, this might be worth a look.

    Questions? Drop me an email at hello@simontodd.dev

  • Cleaning Up Orphaned Images in PrestaShop

    I’ve been working with PrestaShop for a while now, and one thing that’s always bugged me is how stores accumulate unused images over time. Delete a product? The images often stay behind. Update a CMS page? Old images linger. Swap out a slider? Those banners aren’t going anywhere.

    On one of my client sites, I discovered over 50,000 image files taking up around 8GB of space. The actual product catalogue only needed a fraction of that. The rest was just… clutter.

    The Problem

    PrestaShop doesn’t have a built-in way to clean this up. There are a few modules out there, but I wanted something simple that I could run on any site without installing anything permanently. Just upload, scan, clean, delete the tool.

    So I built one.

    What I Made

    It’s a single PHP file. You upload it to your PrestaShop root, access it in your browser, and it scans everything to find orphaned images.

    The tricky bit was making sure it doesn’t flag images that are actually in use. PrestaShop stores image references in all sorts of places — product descriptions, CMS pages, theme files, module templates, slider configurations, page builder content. Miss any of these and you’d end up deleting images that are still needed.

    The tool dynamically discovers your installed modules and scans their database tables automatically. No hardcoded list that goes out of date. It just looks at what’s actually installed on your site.

    How It Works

    1. Upload the PHP file to your site
    2. Change the default password (important!)
    3. Access it via your browser
    4. Run a scan
    5. Review what it finds
    6. Clean up if you’re happy
    7. Delete the tool when you’re done

    It validates product images against your actual database records, checks category/manufacturer/supplier images, scans theme templates, and crawls through all your content fields looking for image references.

    Only files that aren’t referenced anywhere get flagged as orphans.

    It’s Free

    I’ve put it on GitHub if anyone else finds it useful. It’s MIT licensed, so do whatever you like with it.

    GitHub: PrestaShop Image Cleanup Tool

    Fair warning though — always back up before deleting anything. I’ve tested it extensively on my own sites, but every PrestaShop installation is different. Better safe than sorry.

    Results

    On that 8GB site I mentioned, the tool identified around 30,000 orphaned files. After reviewing the results and running the cleanup, I freed up about 5GB of space. The site’s now much easier to back up and migrate.

    If you’re running a PrestaShop store that’s been around for a few years, it might be worth a look. You’d be surprised how much cruft builds up.


    Questions? Drop me an email at hello@simontodd.dev