](?!(height|width)=[\'\"](?:\S+)[\'\"]))*+)>#is', $html, $images, PREG_SET_ORDER); if(!empty($images)) { //remove any duplicate images $images = array_unique($images, SORT_REGULAR); //exclude specific images $image_exclusions = array( ';base64' ); $image_exclusions = apply_filters('perfmatters_image_dimensions_exclusions', $image_exclusions); //loop through images foreach($images as $image) { //get image attributes array $image_atts = Utilities::get_atts_array($image[1]); if(!empty($image_atts['src'])) { foreach($image_exclusions as $exclude) { if(strpos($image[1], $exclude) !== false) { continue 2; } } //get image dimensions $dimensions = self::get_dimensions_from_url($image_atts['src']); if(!empty($dimensions)) { //remove any existing dimension attributes $new_image = preg_replace('/(height|width)=[\'"](?:\S+)*[\'"]/i', '', $image[0]); //add dimension attributes to img tag $new_image = preg_replace('/<\s*img/i', ' $matches[1], 'height' => $matches[2]); } //get image path $parsed_url = parse_url($url); if(empty($parsed_url['path'])) { return false; } $image_path = str_replace('/wp-content', '', WP_CONTENT_DIR) . '/' . $parsed_url['path']; if(file_exists($image_path)) { //get dimensions from file $sizes = getimagesize($image_path); if(!empty($sizes)) { return array('width' => $sizes[0], 'height' => $sizes[1]); } } return false; } }