Skip to content

Commit 82fc3a4

Browse files
committed
Merge branch 'release/0.1.10'
2 parents 4afe61b + e83062c commit 82fc3a4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Field/Image.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,17 @@ protected function fillFields(Post $attachment)
9292

9393
/**
9494
* @param string $size
95+
* @param bool $useOriginalFallback
9596
*
9697
* @return Image
9798
*/
98-
public function size($size)
99+
public function size($size, $useOriginalFallback = false)
99100
{
100101
if (isset($this->sizes[$size])) {
101102
return $this->fillThumbnailFields($this->sizes[$size]);
102103
}
103104

104-
return $this->fillThumbnailFields($this->sizes['thumbnail']);
105+
return $useOriginalFallback ? $this : $this->fillThumbnailFields($this->sizes['thumbnail']);
105106
}
106107

107108
/**
@@ -117,6 +118,9 @@ protected function fillThumbnailFields(array $data)
117118
$size->height = $data['height'];
118119
$size->mime_type = $data['mime-type'];
119120

121+
$urlPath = dirname($this->url);
122+
$size->url = sprintf('%s/%s', $urlPath, $size->filename);
123+
120124
return $size;
121125
}
122126

tests/ContentFieldsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,20 @@ public function testImageFieldValue()
5353
$this->assertEquals('1920', $image->width);
5454
$this->assertEquals('1080', $image->height);
5555
$this->assertEquals('maxresdefault-1.jpg', $image->filename);
56+
57+
// Test existing image size
5658
$this->assertEquals('1024', $image->size('large')->width);
59+
$this->assertNotEmpty($image->size('large')->url);
60+
61+
// Test non existing image size with thumbnail as fallback
62+
$this->assertEquals('150', $image->size('fake_size')->width);
63+
$this->assertNotEmpty($image->size('fake_size')->url);
64+
65+
// Test non existing image size with original as fallback
66+
$this->assertEquals($image->width, $image->size('fake_size', true)->width);
67+
$this->assertEquals($image->height, $image->size('fake_size', true)->height);
68+
$this->assertNotEmpty($image->size('fake_size', true)->url);
69+
5770
$this->assertEquals('image/jpeg', $image->mime_type);
5871
$this->assertEquals('This is a caption', $image->description);
5972
}

0 commit comments

Comments
 (0)