0

Migrated images from Zen Cart to Wordpress and now the correct images are there, but WP thinks that each one has dimensions of 100 x 100.

If I use the WP image editor and make a trivial change in the image, dimensions will be updated to the correct dimensions.

This helpful MySQL query:

 SELECT * FROM  `wp_postmeta` WHERE meta_key IN ('_wp_attached_file', '_wp_attachment_backup_sizes',  '_wp_attachment_metadata',  '_thumbnail_id');

Shows that the image "dimensions" are stored in _wp_attachment_metadata. For example, (unserialized):

array (
  'width' => 100,
  'height' => 100,
  'hwstring_small' => 'height=100 width=100',
  'file' => '2017/09/p-72-Digital-Boardwalk2.jpg',
  'sizes' => 
  array (
    'thumbnail' => 
    array (
      'file' => 'p-72-Digital-Boardwalk2.jpg',
      'width' => 150,
      'height' => 150,
    ),
    'medium' => 
    array (
      'file' => 'p-72-Digital-Boardwalk2.jpg',
      'width' => 300,
      'height' => 214,
    ),
    'shop_thumbnail' => 
    array (
      'file' => 'p-72-Digital-Boardwalk2.jpg',
      'width' => 90,
      'height' => 67,
    ),
    'shop_catalog' => 
    array (
      'file' => 'p-72-Digital-Boardwalk2.jpg',
      'width' => 150,
      'height' => 111,
    ),
    'shop_single' => 
    array (
      'file' => 'p-72-Digital-Boardwalk2.jpg',
      'width' => 300,
      'height' => 250,
    ),
  ),
  'image_meta' => 
  array (
    'aperture' => 0,
    'credit' => '',
    'camera' => '',
    'caption' => '',
    'created_timestamp' => 0,
    'copyright' => '',
    'focal_length' => 0,
    'iso' => 0,
    'shutter_speed' => 0,
    'title' => '',
  ),
)

Found this handy command line tool from ImageMagic that confirms the actual image dimensions:

$ identify p-72-Digital-Boardwalk2.jpg
p-72-Digital-Boardwalk2.jpg JPEG 960x960 960x960+0+0 8-bit DirectClass 69KB 0.000u 0:00.009

I could compose a script to go through all of the media library files and, potentially using php's getimagesize, update all of the relevant _wp_attachment_metadata columns.

What would be a good approach to update the metadata to the actual image dimensions?

2

You can easily use Regenerate Thumbnails and bulk regenerate for all the images. Regenerate Thumbnail plugin updates all the details about the full size image, as well as it recreates thumbnail. It'll update the dimension for each image, but all the other image sizes should be registered as well, else they won't be stored in updated image meta.

If you want to just update the dimensions for the full size image, you can probably run a custom script.

Read the link you shared, and checked the code of Regenerate Thumbnail as well, the latest version don't seem to rely on dimensions stored in image meta by WordPress, but for thumbnails, it definitely needs the image meta, all the image sizes should be registered

  • Regenerate Thumbnails do not regenerate sizes into wp_postmeta. Do not clean up unused sizes from attachment post meta. – Betagoo Oct 4 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.