Skip to content

Commit d026e2f

Browse files
committed
fixed imageInfo to retrieve the images in the same order
1 parent 403e6a8 commit d026e2f

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/ImageInfo/Curl.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function getImagesInfo(array $images, array $config = null)
5151
foreach ($images as $k => $image) {
5252
if (strpos($image['value'], 'data:') === 0) {
5353
if ($info = static::getEmbeddedImageInfo($image['value'])) {
54-
$result[] = array_merge($image, $info);
54+
$result[$k] = array_merge($image, $info);
5555
}
5656

5757
continue;
@@ -81,14 +81,16 @@ public static function getImagesInfo(array $images, array $config = null)
8181
curl_multi_remove_handle($curl, $connection->getConnection());
8282

8383
if (($info = $connection->getInfo())) {
84-
$result[] = array_merge($images[$k], $info);
84+
$result[$k] = array_merge($images[$k], $info);
8585
}
8686
}
8787
}
8888

8989
finfo_close($finfo);
9090
curl_multi_close($curl);
9191

92+
ksort($result, SORT_NUMERIC);
93+
9294
return $result;
9395
}
9496

src/Utils.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ public static function searchValue(array $values, $value, $returnKey = false)
169169
*/
170170
public static function getFirstValue(array $values, $returnKey = false)
171171
{
172-
if (isset($values[0])) {
173-
return $returnKey ? 0 : $values[0]['value'];
172+
$first = reset($values);
173+
174+
if (is_array($first)) {
175+
return $returnKey ? key($values) : $first['value'];
174176
}
175177
}
176178

tests/UtilsTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Embed\Utils;
4+
5+
class UtilsTest extends TestCaseBase
6+
{
7+
public function testSortByProvider()
8+
{
9+
$val = [
10+
[
11+
'value' => '1',
12+
'providers' => ['html'],
13+
],[
14+
'value' => '2',
15+
'providers' => ['opengraph'],
16+
],[
17+
'value' => '2',
18+
'providers' => ['html'],
19+
]
20+
];
21+
}
22+
}

tests/WikipediaTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public function testOne()
1313
[
1414
'title' => 'Albert Einstein',
1515
'description' => $description,
16-
'imageWidth' => 3875,
17-
'imageHeight' => 5593,
16+
'imageWidth' => 3250,
17+
'imageHeight' => 4333,
1818
'type' => 'link',
1919
'providerName' => 'Wikipedia',
2020
'providerUrl' => 'https://wikipedia.org',

0 commit comments

Comments
 (0)