Unlike other ecommerce software such as VirtueMart, PestaShop slightly complicates the purpose of making our ecommerce site faster and more responsive in the presence of large catalogs. To do this, it does not use a single folder for images, but creates a folder for each digit of the id_image value, placing the product images in the last folder that corresponds to the last digit of our ID number.

HOW DOES PRESTASHOP HANDLE IMAGES?

When we go to insert an image into a product PrestaShop 1.5.X/1.6.X and 1.7, it populates the ps_image table with the following fields: id_image, id_product, position, cover where:

  • the id_image field is AUTO_INCREMENT
  • the id_product field is the id of the product we are inserting/modifying
  • the position field is the order in case of multiple images
  • the cover field identifies the cover image by setting the value to 1 while the others have the value 0

Once the DB is populated, it uploads the image renaming it as id_image.jpg and creates the various thumbnails set in the ps_image_type table (Back office > Preferences > Images).
The naming rule for thumbnails is very simple; the images will be id_image-formatname.jpg

For example, if we upload an image of a product, PrestaShop assigns this image ID 936, renames our image as 936.jpg and will also create all the thumbnails by reading the ps_image_type table. Let's assume in this example that we only have home_default which is 124x124px, PrestaShop will create the file 936-home_default.jpg with the dimensions set in Back office > Preferences > Images.
PrestaShop will save these images in: img/p/9/3/6/ where /img/p is the default folder for product images (/img/c/ is for categories)

Let's see in detail what happens when setting the product ID to 455 and uploading a second image that takes ID 964:

In the ps_image table, it creates the following records:

id_imageid_productpositioncover
96345510
96445521


In the ps_image_lang table, it creates the following records:

id_imageid_langlegend
9631Product Name
9641Product Name


This table varies depending on the languages we manage in the e-commerce (it is possible to upload a different image for each language) and the value set in the "Legend" field when we upload the image.

In the ps_image_shop table, it creates the following records:

id_imageid_shopcover
96311
96410

PrestaShop multistore: this table also varies depending on whether the Multistore management is activated in our e-commerce and the number of shops we have configured.

We will find our images at:
/img/p/9/6/3/963.jpg
/img/p/9/6/3/963-home_default.jpg
/img/p/9/6/4/964.jpg
/img/p/9/6/4/964-home_default.jpg

PrestaShop then displays the images through the getImageLink function called in the files of our Template.
If we have activated the understandable URL option in Back office > Preferences > URL and SEO, the product images will be renamed with the product name significantly enhancing the SEO optimization of our site.

Optimizing images for an e-commerce in PrestaShop: let’s remember the importance of optimizing the images of our e-commerce in PrestaShop. We can use the TinyPNG APIs (https://tinypng.com/) also through the excellent module for PrestaShop available on Addons: https://addons.prestashop.com/it/website-performance/22488-compressore-di-immagini-con-tinypng.html. It is also possible to optimize images locally with Windows software such as FileOptimizer or perform optimization via SSH access to your server. Optimizing images will allow us to have faster loading times and better scores from Google.

Author: Loris Modena

SENIOR DEVELOPER

Per Ind Loris Modena, owner of Arte e Informatica, started working in the IT sector in 1989 as a system administrator responsible for the maintenance and installation of computer systems. He began programming for the web in 1997, focusing on CGI programming in PERL and later transitioning to programming in PHP and JavaScript. During this time, he became familiar with the Open Source world and the management of Linux servers.

Product added to wishlist