AMP_Image_Dimension_Extractor::extract PHP Метод

extract() публичный статический Метод

public static extract ( $urls )
    public static function extract($urls)
    {
        if (!self::$callbacks_registered) {
            self::register_callbacks();
        }
        $valid_urls = array();
        foreach ($urls as $url) {
            $url = self::normalize_url($url);
            if (false !== $url) {
                $valid_urls[] = $url;
            }
        }
        $dimensions = array_fill_keys($valid_urls, false);
        $dimensions = apply_filters('amp_extract_image_dimensions_batch', $dimensions);
        return $dimensions;
    }

Usage Example

Пример #1
0
 public function sanitize($amp_attributes = array())
 {
     $nodes = $this->dom->getElementsByTagName(self::$tag);
     $num_nodes = $nodes->length;
     if (0 === $num_nodes) {
         return;
     }
     for ($i = $num_nodes - 1; $i >= 0; $i--) {
         $node = $nodes->item($i);
         $old_attributes = AMP_DOM_Utils::get_node_attributes_as_assoc_array($node);
         if (!array_key_exists('src', $old_attributes)) {
             $node->parentNode->removeChild($node);
             continue;
         }
         $new_attributes = $this->filter_attributes($old_attributes);
         if (!isset($new_attributes['width']) || !isset($new_attributes['height'])) {
             $dimensions = AMP_Image_Dimension_Extractor::extract($new_attributes['src']);
             if ($dimensions) {
                 $new_attributes['width'] = $dimensions[0];
                 $new_attributes['height'] = $dimensions[1];
             }
         }
         $new_attributes = $this->enforce_sizes_attribute($new_attributes);
         $new_attributes = array_merge($new_attributes, $amp_attributes);
         if ($this->is_gif_url($new_attributes['src'])) {
             $this->did_convert_elements = true;
             $new_tag = 'amp-anim';
         } else {
             $new_tag = 'amp-img';
         }
         $new_node = AMP_DOM_Utils::create_node($this->dom, $new_tag, $new_attributes);
         $node->parentNode->replaceChild($new_node, $node);
     }
 }
All Usage Examples Of AMP_Image_Dimension_Extractor::extract