Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get real URL of lazyload images #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/UsesContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,13 @@ public function images(): array
$images = $this->filter('//img')->images();

/** @var \Symfony\Component\DomCrawler\Image $image */
foreach ($images as $image) {
$result[] = $image->getUri();
}
foreach ($images as $image) {
$node = $image->getNode();
if ($node) {
$result[] = !empty($node->getAttribute('data-src')) ? $this->makeUrlAbsolute($node->getAttribute('data-src')) : $image->getUri();
}
}


return $result;
}
Expand All @@ -551,7 +555,7 @@ public function imagesWithDetails(): array
// Collect the URL and commonly interesting attributes
$result[] = [
// Re-generate the proper uri using the Symfony's image class
'url' => (new DomCrawlerImage($image, $this->currentBaseHost()))->getUri(),
'url' => !empty($image->getAttribute('data-src')) ? $this->makeUrlAbsolute($image->getAttribute('data-src')) : (new DomCrawlerImage($image, $this->currentBaseHost()))->getUri(),
'alt' => $image->getAttribute('alt'),
'width' => $image->getAttribute('width') === '' ? null : $image->getAttribute('width'),
'height' => $image->getAttribute('height') === '' ? null : $image->getAttribute('height'),
Expand Down