Skip to content

Commit

Permalink
improve @InlinedImage to detect mime type
Browse files Browse the repository at this point in the history
  • Loading branch information
Seb33300 committed Sep 5, 2024
1 parent 8c6d394 commit 43b408c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/PdfServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public function bootingPackage()
if (! \Illuminate\Support\Str::of(\$url)->isUrl()) {
try {
\$imageContent = 'data:image/png;base64,' . base64_encode(file_get_contents(\$url));
echo '<img src=\"' . \$imageContent . '\">';
\$content = file_get_contents(\$url);
} catch(\Exception \$exception) {
throw new \Illuminate\View\ViewException('Image not found: ' . \$exception->getMessage());
}
Expand All @@ -45,11 +44,13 @@ public function bootingPackage()
throw new \Illuminate\View\ViewException('Failed to fetch the image: ' . \$response->toException());
}
\$imageContent = 'data:image/png;base64,' . base64_encode(\$response->body());
echo '<img src=\"' . \$imageContent . '\">';
\$content = \$response->body();
}
\$mime = (new finfo(FILEINFO_MIME_TYPE))->buffer(\$content) ?: 'image/png';
echo '<img src=\"data:'.\$mime.';base64,'.base64_encode(\$content).'\">';
?>";
});

}
}

0 comments on commit 43b408c

Please sign in to comment.