I got a problem with snappy package. I'm trying to generate a pdf with a external image, but I got an error when do this:
$pdf = PDF::loadView('admin-customer.tag.pdf-view', $product)
->setOption('page-width', '100')
->setOption('page-height', '70.5')
->setOption('margin-top', 2)
->setOption('margin-bottom', 2)
->setOption('margin-left', 2)
->setOption('margin-right', 2);
return $pdf->download($product->name . '.pdf');
My view:
<div class="qrcode">
<img src="//api.qrserver.com/v1/create-qr-code/?data=http://trackagro.com.br" alt="">
<h6 class="msg">
CONSULTE PELO SEU LEITOR DE QR-CODE OU EM NOSSO SITE TRACKAGRO.COM.BR
</h6>
</div>
The error:
Page 1 of 1 Done Exit with code 1 due to network error: ContentNotFoundError " stdout: "" command: D:\Projects\empresas\trackagro\trackagro-sistema\vendor\wemersonjanuario\wkhtmltopdf-windows\bin\64bit\wkhtmltopdf --lowquality --margin-bottom "2" --margin-left "2" --margin-right "2" --margin-top "2" --page-height "70.5" --page-width "100" "C:\Users\PopApps\AppData\Local\Temp\knp_snappy5dcaeaf096db73.71503659.html" "C:\Users\PopApps\AppData\Local\Temp\knp_snappy5dcaeaf09905f2.88209190.pdf".
I've been researching and managed to solve using another library to generate qrcode, which generates the image in SVG:
https://www.simplesoftware.io/simple-qrcode/
And my code:
$pdf = PDF::loadView('admin-customer.tag.pdf-view', $product)
->setOption('page-width', '100')
->setOption('page-height', '70.5')
->setOption('margin-top', 2)
->setOption('margin-bottom', 2)
->setOption('margin-left', 2)
->setOption('margin-right', 2)
->setOption('images', true);
return $pdf->download($product->name . '.pdf');
And my view:
<img src="data:image/png;base64, {{ base64_encode(QrCode::format('png')->size(100)->generate('http://trackagro.com.br')) }}" />
Thanks a lot
Related
I will show the upload image but it shown a thumbnail,
here is my Controller Code Upload a image file
$file = $request->file('images')->getClientOriginalName();
$filename = time().$file;
$path = base_path('/Uploads');
if($request->hasFile('images')){
$file = $request->file('images');
$file->move($path, $filename);
DB::table('books')->insert($filename);
return redirect('home')->with('status', 'insert succesfully');
}
else {
dd('Request Hash No File!');
}
Here is my view
#foreach ($booksDTL as $deTailsB)
<div class="col-md-4">
<img src="{{ asset('Uploads/'.$deTailsB->images) }}" width="100%" height="100%" title="{{ $deTailsB->images }}"/>
</div>
<div class="col-md-6">
<H1>{{ ucfirst(trans($deTailsB->name)) }}</H1>
<p>{{ strtoupper($deTailsB->author) }}</p>
</div>
#endforeach
Here is the controller to show data
public function detailBook($id)
{
$booksdetail = DB::table('books')->where('id', $id)->get();
return view ('details', ['booksDTL'=>$booksdetail]);
}
and here is when i run the code
enter image description here
The upload file save into folder 'Uploads' the folder is in the out of public folder, I already run the php artisan storage:link. But the upload picture still shown in thumbnail. Do you have any suggestion to this?
I am trying to implement bootstrap carousel dynamically from input in Laravel. My slider is working properly but the image is not showing.
slider code
#foreach($sliders as $key => $slider)
<div class="carousel-item {{$key == 0 ? 'active' : '' }}">
<img src="{{url('images/slider-rms', $slider->image)}}" class="d-block w-100" alt="...">
</div>
#endforeach
The backend and slider is working fine. But I am not sure about the path.
The image folder is : public->images->slider-rms
Image saving code
$slider = new Slider();
if($request->hasFile('slider')) {
// image that inserted
$image = $request->file('slider');
$img = time(). '.'.$image->getClientOriginalExtension();
$image->move('images/slider-rms/',$img);
$slider->image = $image;
}
$slider->save();
I want to display an image for each entry in a list of posts. The name of the images are unique file names. They are all saved in a database (MySQL) table. There is more than one image for each post. The code works right. Except, when there is a post without an image filename. This is a possible scenario but i can't get the code to work. In the event there's no existing filename for a post, i want to display a default filename.
Here's my code:
Images logic:
/**
* Get a vehicle's top or main image data from the image table
*/
public function topImage($id)
{
$image = Vehiclefulldataimage::where('vehiclefulldatas_id', $id)
->orderBy('id', 'ASC')->first();
return $image;
}
Here's the blade view, Posts:
#if (count($posts) > 0)
#foreach($posts as $post)
<?php $imageFilename = (new \App\Models\Logic\Images)->topImage($post->id); ?>
<!--Item-->
<li>
<div class="preview">
#if ($imageFilename = 0)
<img src="{{ asset('images') . '/' . 'defaultImage.jpg' }}" alt="No photo">
#else
<img src="{{ asset('images') . '/' . $imageFilename->disk_image_filename }}" alt="{{ ucfirst($imageFilename->caption) . ' | ' . $post->title }}">
#endif
</div>
<div class="desc">
<h3>{{ str_limit($post->title, 100, '...') }}</h3>
</div>
</li>
<!--/Item-->
#endforeach
#endif
This is the error message i get:
"Trying to get property of Non Object"
Try the following code:
You are using an assignment operator instead of comparison operator
//#if (count($posts) > 0)
#if (!$posts->isEmpty())
#foreach($posts as $post)
<?php $imageFilename = (new \App\Models\Logic\Images)->topImage($post->id); ?>
<!--Item-->
<li>
<div class="preview">
//#if ($imageFilename = 0) this is an assignment operator not comparison operator
#if ($imageFilename->isEmpty())
<img src="{{ asset('images') . '/' . 'defaultImage.jpg' }}" alt="No photo">
#else
<img src="{{ asset('images') . '/' . $imageFilename->disk_image_filename }}" alt="{{ ucfirst($imageFilename->caption) . ' | ' . $post->title }}">
#endif
</div>
<div class="desc">
<h3>{{ str_limit($post->title, 100, '...') }}</h3>
</div>
</li>
<!--/Item-->
#endforeach
#endif
Check your if statement....what you're doing there is an assignment and not a condition test...you can include a column..with a string pointing to the path of your default image..and set it to default...then load it...as default image
All of the answers above fix your problem. However, I recommend you to fix this problem by using Laravel features, Mutators.
https://laravel.com/docs/5.8/eloquent-mutators
Laravel mutators allow you to format or modify your Model attribute.
Just in your Vehiclefulldataimage model write the code below:
public function getImageAttribute($value)
{
//can write more logic here.
return $value ?: 'path/to/your/default/image';
}
Then you don't care more if condition blade template. If your image is empty the mutator returns the default image. So, everywhere when your retrieve Vehiclefulldataimage instance the mutator works properly
Thanks everyone.
After looking at all the answers, i did a simple alteration to my code. I altered:
#if ($imageFilename = 0)
to:
#if ($imageFilename == null)
Thus, my code now looks:
#if (count($posts) > 0)
#foreach($posts as $post)
<?php $imageFilename = (new \App\Models\Logic\Images)->topImage($post->id); ?>
<!--Item-->
<li>
<div class="preview">
#if ($imageFilename == null)
<img src="{{ asset('images') . '/' . 'defaultImage.jpg' }}" alt="No photo">
#else
<img src="{{ asset('images') . '/' . $imageFilename->disk_image_filename }}" alt="{{ ucfirst($imageFilename->caption) . ' | ' . $post->title }}">
#endif
</div>
<div class="desc">
<h3>{{ str_limit($post->title, 100, '...') }}</h3>
</div>
</li>
<!--/Item-->
#endforeach
#endif
I am trying to open a pdf file when I click on my website. The PDF is uploaded from the admin, but it's showing not found 404
view
<div class="entry-content">
<a target="_blank" href="{{$post->file}}">
<p style="font-size: 18px;color: #468b10;">
{{ $post->content }}
</p>
</a>
</div>
Controller
if (request('file')) {
$file = request('file');
$file=$file_name::get($file);
$file_name = time() . $file->getClientOriginalName();
$file->move('uploads/posts', $file_name);
$data['file'] = 'uploads/posts/'.$file_name;
}
I am working on Laravel 5.4 and i use below given code.
#if( $profileurl )
<div class="">
#php
$cropped_img = "http://res.cloudinary.com/demo/image/fetch/w_150,h_150,c_thumb,g_face,r_max,f_auto/" . $profileurl ;
#endphp
<img src="{{ $cropped_img }}" height="150" width="150">
</div>
#endif
But problem is that image is not seen properly. But its url is correct.
The image is look like this.
Generated url is http://res.cloudinary.com/demo/image/fetch/w_150,h_150,c_thumb,g_face,r_max,f_auto/http://dev1.jdsoftvera.com/voting-system/public/profile/image/9ccca1ccad318a91a0a1c057663548b6Penguins.jpg
But the url is ok.
When i simply use this below code then image is seen.
<img src="{{ $profileurl }}" height="150" width="150">
This code is worked for me.
$profileurl = "http://res.cloudinary.com/demo/image/fetch/w_150,h_150,c_thumb,g_face,r_max,f_auto/" . $profileurl ;
$img = base64_encode($profileurl);
$profileurl = base64_decode($img);