$content is empty while using DOMDocument

If the pages that are giving errors have no content, you can deal with it by adding a check at the start of the function:

function image_manipulation( $content ) {
  if(empty($content)) return $content;
  //rest of the code
}