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_image | id_product | position | cover |
| 963 | 455 | 1 | 0 |
| 964 | 455 | 2 | 1 |
In the ps_image_lang table, it creates the following records:
| id_image | id_lang | legend |
| 963 | 1 | Product Name |
| 964 | 1 | Product 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_image | id_shop | cover |
| 963 | 1 | 1 |
| 964 | 1 | 0 |
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.