OpenCart product images
When adding a product in Opencart you can assign to it two types of images:
- main image
- additional images
The main product image is recorded in the product table and the plugin can work with it - delete, replace. The additional product images are added to another database table without the plugin being able to work with any of them specifically.
It is impossible to find, replace or delete a specific photo among additional ones with this plugin.
Image files are stored in the image/catalog folder and sub-folders, and linked to the product through database records:
In our example, you can see that the product with ID 2768 main image is in folder image/catalog/palto and the file name is photo-main12.png
If you change the image file name in the image/catalog/palto folder, then you need to change it in the database, otherwise, the main product image will disappear on the site.
Distributing images into folders
The folder photo contains an image of not one product 2768, but the whole category "SLR" because when creating products, the plugin followed your instructions on the tab "Category and margin":
and uploaded product images from the category, which is indicated as "Cameras" in the price list, to the folder image/catalog/photo
In a nutshell
When processing the price list the plugin uploads the product images in a folder defined in the "Category and margin" tab according to the product category.
Impact on site speed
According to experts, if the photo folder contains more than 1000 files, the site starts to slow down, so the plugin has three ways to avoid folder overflow.
1. More different folders for different categories. Don't put all product images into one folder:
2. Divide each folder into 10 sub-folders:
When the "Add the images in subfolders..." button is enabled, the plugin will evenly distribute images into sub-folders: , , ,...
Distributing images in sub-folders follows this rule: The image is uploaded into the sub-folder number same as the last product ID number. In our example, this will be the sub-folder 8 because the product ID is 2768.
3. If needed, you can use the "Tools" to divide each sub-folder into 10 more sub-sub-folders:
Delete unused images
Image files are using the most disk space and the image folder is the largest folder on the site, but not all images stored in it are used in product pages.
Unnecessary, junk photos remain in the image folder after deleting images in products.
OpenCart removes only the image link in the database and does not remove the file itself in the folder, because this image could theoretically be used in another product.
The plugin has a tool called "Delete unused images from image folder":
Make a copy of the database before using this tool.
The plugin checks all the products on the site and copies only the images associated with at least one product to a new empty folder. Thus, only the necessary images appear in the new image1 folder.
All preparation should be done on your PC.
- Download the image folder on your PC and do not delete it until the end of the process
- Create a folder image1 and copy the contents of the image folder into it.
- Empty the image1/catalog folder from files using the console command: del /s /q image1/catalog (restore deleted files that are not related to products: icons, languages, categories ...). Our goal is to keep the image folder structure and only the images that are used for the site design, icons, banners…
- Upload the image1 folder to the site root (next to the image folder).
- Run the tool "Delete unused images from image folder".
- When the action is finished, rename the image folder to image2 and the image1 folder to image
- Clean the cached images in image/cache/catalog.
- Go to the site to make sure that the product images are not missing.
- Delete the folder image2.