From 6b9c70bd36754c39ed9bc728543c332148dbedd2 Mon Sep 17 00:00:00 2001 From: Julian Pustkuchen Date: Wed, 6 May 2026 12:37:24 +0200 Subject: [PATCH 1/3] Added Property::IMAGE_ALT --- src/Elements/Image.php | 4 ++++ src/Objects/ObjectBase.php | 4 ++++ src/Property.php | 1 + 3 files changed, 9 insertions(+) diff --git a/src/Elements/Image.php b/src/Elements/Image.php index 9087336..2792160 100644 --- a/src/Elements/Image.php +++ b/src/Elements/Image.php @@ -84,6 +84,10 @@ public function getProperties(): array $properties[] = new Property(Property::IMAGE_WIDTH, $this->width); } + if (null !== $this->alt) { + $properties[] = new Property(Property::IMAGE_ALT, $this->alt); + } + if (null !== $this->userGenerated) { $properties[] = new Property(Property::IMAGE_USER_GENERATED, $this->userGenerated); } diff --git a/src/Objects/ObjectBase.php b/src/Objects/ObjectBase.php index 40e3bf9..cd4e1da 100644 --- a/src/Objects/ObjectBase.php +++ b/src/Objects/ObjectBase.php @@ -148,6 +148,7 @@ public function assignProperties(array $properties, bool $debug = false): void case Property::IMAGE_SECURE_URL: case Property::IMAGE_TYPE: case Property::IMAGE_WIDTH: + case Property::IMAGE_ALT: case Property::IMAGE_USER_GENERATED: if (\count($this->images) > 0) { $this->handleImageAttribute($this->images[\count($this->images) - 1], $name, $value); @@ -223,6 +224,9 @@ private function handleImageAttribute(Image $element, string $name, string $valu case Property::IMAGE_WIDTH: $element->width = (int) $value; break; + case Property::IMAGE_ALT: + $element->alt = $value; + break; case Property::IMAGE_TYPE: $element->type = $value; break; diff --git a/src/Property.php b/src/Property.php index 00fe7be..1df9ba7 100644 --- a/src/Property.php +++ b/src/Property.php @@ -26,6 +26,7 @@ class Property public const IMAGE_TYPE = 'og:image:type'; public const IMAGE_URL = 'og:image:url'; public const IMAGE_WIDTH = 'og:image:width'; + public const IMAGE_ALT = 'og:image:alt'; public const IMAGE_USER_GENERATED = 'og:image:user_generated'; public const LOCALE = 'og:locale'; public const LOCALE_ALTERNATE = 'og:locale:alternate'; From 68469cdb129b7cbc7bd0ceb39ce6067dc36eee48 Mon Sep 17 00:00:00 2001 From: Julian Pustkuchen Date: Wed, 6 May 2026 12:38:46 +0200 Subject: [PATCH 2/3] Added README.md example --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 255ef40..fceade6 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ $image = $object->images[0]; echo "Image[0] URL: " . $image->url; // https://i1.ytimg.com/vi/P422jZg50X4/maxresdefault.jpg echo "Image[0] height: " . $image->height; // null (May return height in pixels on other pages) echo "Image[0] width: " . $image->width; // null (May return width in pixels on other pages) +echo "Image[0] alt: " . $image->alt; // The alt text // Videos $video = $object->videos[0]; From ced00f086df49fb10c2fadb08c96c9e33a8dd606 Mon Sep 17 00:00:00 2001 From: Matthias Burtscher Date: Mon, 11 May 2026 19:31:18 +0200 Subject: [PATCH 3/3] Added image alt property and test --- src/Elements/Image.php | 5 +++++ tests/ConsumerTest.php | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/Elements/Image.php b/src/Elements/Image.php index 2792160..a319c62 100644 --- a/src/Elements/Image.php +++ b/src/Elements/Image.php @@ -46,6 +46,11 @@ class Image extends ElementBase */ public ?bool $userGenerated = null; + /** + * Alternative text for the image. + */ + public ?string $alt = null; + /** * @param string $url URL to the image file */ diff --git a/tests/ConsumerTest.php b/tests/ConsumerTest.php index 652d124..c82020d 100644 --- a/tests/ConsumerTest.php +++ b/tests/ConsumerTest.php @@ -194,6 +194,7 @@ public function testLoadHtmlImages(): void + @@ -211,6 +212,7 @@ public function testLoadHtmlImages(): void self::assertSame(300, $result->images[0]->width); self::assertSame(300, $result->images[0]->height); self::assertSame('image/jpg', $result->images[0]->type); + self::assertSame('Picture of a rock', $result->images[0]->alt); } public function testLoadHtmlVideos(): void