Improved logo display in Invoice/Estimate PDFs

This commit is contained in:
Darko Gjorgjijoski
2024-08-04 16:08:22 +02:00
parent c9e85f18da
commit c799149d2d
7 changed files with 24 additions and 9 deletions

18
app/Space/ImageUtils.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Space;
use Illuminate\Support\Facades\File;
class ImageUtils
{
/**
* Convert local path to Base64 encoded data source
*
* @return string
*/
public static function toBase64Src($path)
{
return sprintf('data:%s;base64,%s', File::mimeType($path), base64_encode(File::get($path)));
}
}

View File

@@ -398,7 +398,7 @@
<tr> <tr>
<td class="text-center"> <td class="text-center">
@if ($logo) @if ($logo)
<img class="header-logo" style="height: 50px;" src="{{ $logo }}" alt="Company Logo"> <img class="header-logo" style="height:50px" src="{{ \App\Space\ImageUtils::toBase64Src($logo) }}" alt="Company Logo">
@else @else
@if ($estimate->customer->company) @if ($estimate->customer->company)
<h2 class="header-logo"> {{ $estimate->customer->company->name }} </h2> <h2 class="header-logo"> {{ $estimate->customer->company->name }} </h2>

View File

@@ -420,7 +420,7 @@
<tr> <tr>
@if ($logo) @if ($logo)
<td width="60%" class="header-section-left"> <td width="60%" class="header-section-left">
<img class="header-logo" style="height: 50px;" src="{{ $logo }}" alt="Company Logo"> <img class="header-logo" style="height:50px" src="{{ \App\Space\ImageUtils::toBase64Src($logo) }}" alt="Company Logo">
</td> </td>
@else @else
<td width="60%" class="header-section-left" style="padding-top: 0px;"> <td width="60%" class="header-section-left" style="padding-top: 0px;">

View File

@@ -358,7 +358,7 @@
<tr> <tr>
<td width="50%" class="header-section-left"> <td width="50%" class="header-section-left">
@if ($logo) @if ($logo)
<img class="header-logo" style="height: 50px;" src="{{ $logo }}" alt="Company Logo"> <img class="header-logo" style="height:50px" src="{{ \App\Space\ImageUtils::toBase64Src($logo) }}" alt="Company Logo">
@else @else
<h1 class="header-logo"> {{ $estimate->customer->company->name }} </h1> <h1 class="header-logo"> {{ $estimate->customer->company->name }} </h1>
@endif @endif

View File

@@ -328,9 +328,6 @@
</style> </style>
@if (App::isLocale('th'))
@include('app.pdf.locale.th')
@endif
</head> </head>
<body> <body>
@@ -339,7 +336,7 @@
<tr> <tr>
<td class="text-center"> <td class="text-center">
@if ($logo) @if ($logo)
<img class="header-logo" style="height:50px" src="{{ "data:".mime_content_type($logo).";base64,".base64_encode(file_get_contents($logo)) }}" alt="Company Logo"> <img class="header-logo" style="height:50px" src="{{ \App\Space\ImageUtils::toBase64Src($logo) }}" alt="Company Logo">
@else @else
@if ($invoice->customer->company) @if ($invoice->customer->company)
<h2 class="header-logo"> {{ $invoice->customer->company->name }}</h2> <h2 class="header-logo"> {{ $invoice->customer->company->name }}</h2>

View File

@@ -389,7 +389,7 @@
<tr> <tr>
<td width="60%" class="header-section-left"> <td width="60%" class="header-section-left">
@if ($logo) @if ($logo)
<img class="header-logo" src="{{ "data:".mime_content_type($logo).";base64,".base64_encode(file_get_contents($logo)) }}" alt="Company Logo" style="height: 50px;"> <img class="header-logo" style="height:50px" src="{{ \App\Space\ImageUtils::toBase64Src($logo) }}" alt="Company Logo">
@elseif ($invoice->customer->company) @elseif ($invoice->customer->company)
<h1 class="header-logo" style="padding-top: 0px;"> <h1 class="header-logo" style="padding-top: 0px;">
{{ $invoice->customer->company->name }} {{ $invoice->customer->company->name }}

View File

@@ -318,7 +318,7 @@
<tr> <tr>
<td width="50%" class="header-section-left"> <td width="50%" class="header-section-left">
@if ($logo) @if ($logo)
<img class="header-logo" style="height: 50px;" src="{{ "data:".mime_content_type($logo).";base64,".base64_encode(file_get_contents($logo)) }}" alt="Company Logo"> <img class="header-logo" style="height:50px" src="{{ \App\Space\ImageUtils::toBase64Src($logo) }}" alt="Company Logo">
@else @else
<h1 class="header-logo"> {{ $invoice->customer->company->name }} </h1> <h1 class="header-logo"> {{ $invoice->customer->company->name }} </h1>
@endif @endif