Image Storage Path

I am trying to learn how CS-Cart accesses images from the filesystem. Looking at the database in the cscart_images table I see the image filename (like image_path=10026.jpg) but it's just storing the filename, not the full path.

When I look at the filesystem, I see a structure like

images ->
detailed ->
0 ->
filename1.jpg
filename2.jpg
filename3.jpg
1 ->
filename1.jpg
filename2.jpg
filename3.jpg
2 ->
filename1.jpg
filename2.jpg
filename3.jpg
...
and even a more complex structure under images->thumbnails. There can be images of the same name (but relating to different items) in those numbered subdirectories.
How does CS-Cart determine what path to use when serving an image? It seems like there should be a "map" stored somewhere in the database but I can't find it. Or perhaps a formula base on filename?
Any help appreciated.

0, 1, 2 folders depends on the MAX_FILES_IN_DIR setting in the config.local.php. You can specify the maximum number of files, stored in directory.

As for thumbnails, the structure is the following:

images/thumbnails/WIDTH/HEIGHT/detailed/0/FILE_NAME.jpg

OK, but how does CS-Cart know which numbered subdirectory to fetch the image from when an image is served?

For example, I noticed (at least in variant_images) that there can be a may.jpg in /0 and a may.jpg in /5 and they are different images associated with different SKUs.

I'm thinking there either has to be a map somewhere or some logic that CS-Cart is using to determine the full path to the image.

OK, but how does CS-Cart know which numbered subdirectory to fetch the image from when an image is served?

For example, I noticed (at least in variant_images) that there can be a may.jpg in /0 and a may.jpg in /5 and they are different images associated with different SKUs.

I'm thinking there either has to be a map somewhere or some logic that CS-Cart is using to determine the full path to the image.

It depends on the image ID - unique ID of the image which is stored in the database

So if you know image ID and MAX_FILES_IN_DIR value, you can get the folder name

Got it. Thank you.

Just for posterity's sake, the first number of the image_id determines which numbered folder it goes in.

If that's wrong, let me know.

Got it. Thank you.

Just for posterity's sake, the first number of the image_id determines which numbered folder it goes in.

If that's wrong, let me know.

The formula is:

floor($image_id / MAX_FILES_IN_DIR)