Integration Module 2.0 for Medusa is outRead the announcement
C

Converter studio

Medusa v2 plugin: converts product images to WebP, AVIF or JPG (HEIC, PNG, JPG, TIFF, BMP) with Converter Studio's API, automatically on upload or from the admin. Originals are kept and can be restored.

npm install medusa-plugin-converter-studio
Category
Version
1.1.0
Last updated
1 day ago
Monthly downloads
Loading downloads

Converter Studio for Medusa

Smaller, faster product images for your Medusa v2 store. This plugin converts product images to WebP, AVIF or JPG with the Converter Studio API. It runs on its own when you add images to a product, and you can also start it from the admin.

  • Automatic. When a product is created or updated, its JPG, PNG, HEIC, TIFF and BMP images are converted in the background. The converted file takes the original's place in the product's gallery, thumbnail and variant thumbnails.
  • HEIC from phones just works. Browsers other than Safari cannot show HEIC photos. The plugin turns them into WebP or JPG.
  • Large photos are made smaller. Photos whose longer side is over 2560 pixels (phone and camera photos, often 5–10 MB) are scaled down to 2560 px, which still fills a sharp product page and its zoom. Change it with , or turn it off.
  • Originals are kept. The original file stays in your storage, and its URL is saved in the image's metadata (). You can put the originals back with one click.
  • Safe for credits. Each image goes ahead only up to (default 1). If a converted JPG or PNG comes out larger than the original, the original stays. Before converting the whole catalog, the admin shows how many images would be converted and what that can cost, and lets you try 10 images first. When the account runs out of credits, the plugin stops, keeps the originals and tells you in the admin.
  • Admin. A product page widget shows each image's state and has Convert images and Restore originals buttons. A settings page (Settings → Converter Studio) shows your plan and remaining credits, can convert a sample or the whole catalog, and lists the latest conversions.
  • Works with any file provider. Local, S3, MinIO, R2 and others: the plugin saves converted files through Medusa's File Module, so your storage setup stays the same.
  • Privacy. EXIF details (camera, date, GPS location) are removed by default.

Requirements

  • Medusa v2.11.2 or later (tested with 2.22.7 and 2.23.0)
  • Node.js 20 or later
  • A Converter Studio account and an API key. Create a key on your account page. A free account is enough to start.

Install

Add the plugin to :

Put the key in your environment (for example ), not in the code:

Then create the plugin's table, and restart Medusa:

npx medusa db:migrate

New product images are now converted automatically. To convert the images you already have, open Settings → Converter Studio: it shows how many images would be converted. Click Try 10 images to see the savings first, then Convert all. Or use Convert images on a product's page.

Options

All options are optional.

OptionDefaultWhat it does
Your Converter Studio API key. Without one, the plugin does nothing and logs a warning.
What images become: , or .
depends on Formats to convert. WebP: , , , , . AVIF: the same plus . JPG: , , (only formats browsers cannot show). can be added, but animation is not kept.
, or .
Shrinks images whose longer side is larger: , , or pixels. Images are never made larger. (or ) keeps every image at its size.
Keeps EXIF details (camera, date). The GPS location is still removed.
The most credits one image may cost. A more expensive conversion is skipped and the original kept.
Converts images when products are created or updated. Set to to convert only from the admin.
Keeps a JPG or PNG original when the converted file would be larger. HEIC, TIFF and BMP are always converted.
Images converted at the same time (1–5).
The longest one conversion may take.
Further Converter Studio options, passed on unchanged (for example or ). A size set here (, , , , ) replaces the default .
The API's address. Change it only for testing.

Credits and pricing

Conversions use your Converter Studio account's credits, the same credits as on the website. Most images cost 1 credit. Free accounts get 25 credits a day, and paid plans include more credits each month. See converter.studio/pricing.

When the credits run out:

  • the image that could not be converted, and the ones after it, keep their originals;
  • the admin widget and the settings page say so, with a link to get more credits;
  • automatic conversions pause for 30 minutes, then try again on the next product change. Click Convert images (or Convert all) once you have credits again.

A failed conversion costs nothing. Images already in the target format are never sent, so they cost nothing either. Converting an image whose result turns out larger (and is therefore not used) still costs its credit: the plugin cannot know beforehand whether a JPG or PNG will come out smaller. That happens mostly with small JPGs that are already well compressed; photos larger than nearly always come out much smaller, because they are also scaled down.

Before converting the whole catalog, Settings → Converter Studio shows:

  • how many images Convert all would send, in how many products, and the most it can cost (one credit an image);
  • how many images it leaves alone for free (already in the target format, a format you did not choose, or an original kept after an earlier try);
  • whether the account has fewer credits than that.

Try 10 images converts the first 10 of those images and reports how many were converted, how many kept their original, the credits spent (and how many of them on kept originals) and the space saved. Convert all then goes on with the rest: images converted or kept before are not sent again.

How it works

  1. A product is created or updated. A subscriber (, ) starts the workflow in the background. The product itself is saved right away, with the originals. The plugin's own updates (a converted or restored image put in place) do not start it again, so converting one image or a sample converts only those.
  2. The workflow locks the product, so only one run works on it at a time. It then picks the images that need converting.
  3. Each image is downloaded from its URL and sent to Converter Studio (, ). When the result is ready, it is downloaded and saved with your File Module provider.
  4. The workflow reads the product again and swaps the URLs of images that have not changed in the meantime, using Medusa's . Image ids stay the same, so variant images are kept.
  5. Every attempt is recorded in the table, which the admin reads.

A few seconds pass between saving a product and its converted images appearing. Storefronts showing the product in that time get the original.

The workflows are exported for your own code:

Admin API routes

All routes require an admin login.

RoutePurpose
Options in effect (without the key), plan and credits
Each image's state
Convert the product's images (), in the background
Put the originals back ()
Latest conversions (, , )
/Convert every product's images (; : try only that many images, 1–1000)
What converting every product's images would send and can cost, before anything is spent

Good to know

  • Product feeds. Some marketplaces and ad catalogs accept only JPG or PNG. If you send product feeds, use , or read the original from the image's metadata.
  • Demo data. With the plugin active, seeding demo products converts their images too, which uses credits. Set while seeding if you don't want that.
  • Changing later (for example from WebP to AVIF) converts the images again from their originals, not from the earlier result.
  • Restored images are left alone by automatic conversions. Convert images converts them again.
  • Several servers. Converting is safe across servers and workers (a lock per product). The progress of Convert all is kept by the server that runs it.
  • Storage. Converted files are stored next to the originals. Restoring deletes the converted file.

Privacy

Product images are sent to Converter Studio to be converted, and that is their only use. Uploads are deleted after conversion, and results after 6 hours. See the privacy policy and terms. Mention Converter Studio in your store's privacy policy as a service that processes product images.

Support

Write to support@converter.studio, or report a problem at github.com/tariksucu/medusa-plugin-converter-studio/issues. API documentation: converter.studio/developers.

Development and releases

runs the conversion code against a Converter Studio API: set (for example ) and (a file holding an API key). It spends a few credits.

Releases are published to npm by this repository's GitHub Actions workflow () when a version tag is pushed, with an npm provenance statement: the package page on npm shows the commit and the workflow each version was built from.

License

MIT