Here’s some information that may help someone. I did some research on table structure (v. 126.96.36.199) relating to the image tables
1.) Table `catalog_product_entity_media_gallery`
Fields: `value_id` (auto_increment primary key), `attribute_id`, `entity_id`, `value`
`attribute_id` is a foreign key from the table `eav_attribute` that matches the `attribute_id` in that table for `attribute_code` “media_gallery”.
`entity_id` is a foreign key from the table `catalog_product_entity` that matches the `entity_id` (product id) in that table (where you can also see the product sku).
This table should contain all the product images for every item. So if you have a main image and 3 gallery images for an item, you would have 4 entries in this table for that product. It stores the image location and filename, and it links to the corresponding `product_id` in product tables. I have managed to import images for items and not get the main image into this table and yet it still appears in the front end, but that was using an importing extension that made errors. By default it seems that Magento stores ALL images in this table (as well as perhaps elsewhere?).
Each entry corresponding to the images for a single product should have the same `entity_id` - the `entity_id` being the database product id. If you’re wondering, you would most easily find in `catalog_product_flat_1`, since it’s a flat table and you can see both the id field and the sku field on one line. Or you could just select a product in the admin and the id should appear somewhere in the url.
It seems like the `attribute_id` is the same for all images in your database, but not necessarily the same for different magento installations. I have one installation where they are all “73” and another where they are all “77”. I imported some images with the wrong `attribute_id` and those images didn’t show up. I manually changed one value in the database to the correct value and the image instantly appeared on the front end. Of course, manually changing the database is usually a bad idea, so I didn’t do this experiment on the production site.
Each entry has a unique `value`, which is the image location and filename (e.g. /4/3/4327abc.jpg).
Each entry has a unique `value_id` that corresponds to an entry in `catalog_product_entity_media_gallery_value`.
2.) Table `catalog_product_entity_media_gallery_value`
Fields: `value_id`, `store_id`, `label`, `position`, `disabled`
`value_id` is the foreign key from the previous table, `catalog_product_entity_media_gallery`.
`store_id` is the foreign key linking to the `core_store` table.
For single store installations, this table has a 1-to-1 correspondence with the 1st table. It’s linked to the last table on `value_id`.
It also contains the field `store_id`, which for my single-store installations always contains “0”.
For multi-store installations, the `value_id` values in this table could be duplicated, since the primary key for this table is a composite of `value_id` and `store_id`. This means that, based on the previous table (`catalog_product_entity_media_gallery` ) you could have a single set of images for a product, but give them different labels, put them in a different order, and have different images disabled (not showing) depending on which website store it is assigned to.
Changing `label` or `position` manually should instantly change the mouse-over label (title) for the images, and the order in which they’re presented, on the front-end. If two images have the same position value then I think they’re arranged in alphabetical order, though it could be in order of `value_id`.