Where does WordPress store image resolution in the MySQL database?

A full year later and I’ve discovered that the image resolution IS stored in a very poor manner, as custom fields on the attachment. I’m still not clear on exactly how that works and I think I can write a plugin that will convert that crummy method to a custom taxonomy that would allow searching and easy display on sites.

Previously in 2017:


TL;DR: WordPress does not store image resolution in the database.  Nor does it store any information on the difference sizes of the image that it automatically creates.  Looks like the only interaction WP has with images and their resized versions is on initial load, after that it has no record of what’s available for use in posts.

Spent about an hour this morning searching for an answer for this, but there’s no indication that the image size is stored anywhere in the database.  Any time the image is referenced in full from WP, getimagesize is used to get the resolution. The rest of the the image attachment’s meta data is stored haphazardly in either wp_postmeta or wp_posts.  Oddly enough when using getimagesize outside of wp_get_attachment_image_src I seem to get different results (0x0 vs 9393×12500), which may have something to do with image size limits or memory limits in WP.

Here’s where you can find the data that’s stored for each image attachment:

wp_posts:
post_content = description
post_title = image title
post_excerpt = image caption

wp_postmeta:
_wp_attachment_image_alt

If you’ve created a custom taxonomy for your attachments, they’ll be found in the expected taxonomy tables (wp_termmeta, wp_terms, wp_term_relationships, wp_term_taxonomy)

Ref:

php.net/manual/en/function.getimagesize.php

developer.wordpress.org/reference/functions/wp_get_attachment_image_src/

Leave a Reply