Skip to content

Image return update

Compare
Choose a tag to compare
@KalimeroMK KalimeroMK released this 07 Mar 14:23
· 9 commits to main since this release
  1. Find Images: The code then looks for tags within each found element.
  2. $images = $xpath->query('.//img', $element): This line finds all elements within the current element and stores them in $images.
  3. Iterate over Found Images: The loop iterates over each image found in the current element.
  4. foreach ($images as $img): This starts another loop for each image found within the current element.
  5. Extract and Validate Image URLs: The code extracts the URL from each image and checks whether it's a valid URL or a placeholder. If it's a placeholder, the code attempts to find a real image URL from alternative attributes commonly used with lazy-loaded images.
  6. $src = $img->getAttribute('src'): This line gets the src attribute of the image.
  7. If the src is a data URI or SVG (indicating a placeholder), the code checks other attributes like data-src, data-lazy-src, or data-original for an actual image URL.
  8. Convert Relative URLs to Absolute: If a valid image URL is found and it's a relative URL, the code converts it to an absolute URL based on the page's domain.
  9. $src = $this->convertToAbsoluteUrl($src, ...): This calls a method that converts a relative URL to an absolute one.
  10. Store Unique URLs: Finally, if the image URL hasn't already been added to the $imageUrls array, the code adds it.
  11. if (!in_array($src, $imageUrls)) { $imageUrls[] = $src; }: This checks if the URL is already in the array and, if not, adds it.