How to change image atributes right before an image to be saved?

If the import function you’re using uses wp_insert_post() (used also by wp_insert_attachment()) to add the new images (attachment posts) to your site, then you could perhaps use the wp_insert_attachment_data( array $data, array $postarr ) filter, which is defined inside wp_insert_post().

According to the docs it,

Filters attachment post data before it is updated in or added to the
database.

Parameters,

array $data    An array of sanitized attachment post data.
array $postarr An array of unsanitized attachment post data.

If you look at the wp_insert_post() docs, you can see what keys are present for the wp_insert_attachment_data parameters $data and $postarr, https://developer.wordpress.org/reference/functions/wp_insert_post/

For attachments, if I remember correctly,

  • title = post_title
  • alt=”_wp_attachment_image_alt” post_meta
  • caption = post_excerpt
  • description = post_content