Qr-Code using Bacon/BaconQrCode need to save to the folder. - php

I am using Bacon/BaconQrCode library to generate Qr-Code image so how can
save the Qr-code images to the specific folder ?? please help.
My Code:-
$renderer = new \BaconQrCode\Renderer\Image\Png();
$renderer->setHeight(256);
$renderer->setWidth(256);
$writer = new \BaconQrCode\Writer($renderer);
$writer->writeFile('www.google.com', 'qrcode.png');
How can I save this Qr-code image to the folder to show or fetch from other location.

The \BaconQrCode\Writer->writeFile uses file_put_contents method so you can just add an absolute path to your directory like : $writer->writeFile('www.google.com', '../public/qrcodes/qrcode.png');
I haven't tried yet but i hope it works for you.

Related

How to upload,get and update an image or file in laravel ? What is the correct way?

What is the correct way to upload,update and get an image or file in laravel ? I had gone through laravel docs and other references but its confusing.Can anyone show a complete simple example for
any disk configuration in filesystems.php
a simple method to upload and update image in controller
and what will be the image full url?
input type file name is image you can store directly into images folder
return $path = $request->image->store('images');

Add remote images to PhpSpreadseet cell

There is a simple two-column table on a website: product name and product image. It's very easy to render in HTML.
The task would be creating an Xlsx file with these columns.
The images are not stored locally but all of them are remote images with full URL.
The export contains ~100-200 rows.
I tried to create a resource with imagecreatefromjpeg and adding it with MemoryDrawing but it took a huge amount of resources.
I tried with Html helper's toRichTextObject and a simple tag but got empty result.
How is it possible to add a remote image to a PhpSpreadsheet cell? It doesn't need working offline, it's fine to load the remote images when the file is opened.
As #FabriceFabiyi mentionned in his comment, and after reading:
PhpSpreadseet documentation on drawing.
PHP documentation on file_get_contents.
PHP documentation on file_set_contents.
This worked for me:
$image = file_get_contents('https://website.com/path/to/image');
$imageName = 'a_nice_image_name';
//You can save the image wherever you want
//I would highly recommand using a temporary directory
$temp_image=tempnam(sys_get_temp_dir(), $imageName);
file_put_contents($temp_image, $image);
// And then PhpSpreadsheet acts just like it would do with a local image
$drawing->setPath($temp_image);
$drawing->setHeight(36);
$drawing->setWorksheet($sheet);
$drawing->setCoordinates('B15');
More on temporary directories in the PHP docs:
sys_get_temp_dir()
tempnam()
There is an example how add image to your excel export:
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$drawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing();
$drawing->setName('Paid');
$drawing->setDescription('Paid');
$drawing->setPath('/images/image-1.png'); // put your path and image here
$drawing->setHeight(30);
$drawing->setCoordinates('A5');
$drawing->setOffsetX(110);
$drawing->setRotation(25);
$drawing->getShadow()->setVisible(true);
$drawing->getShadow()->setDirection(45);
$drawing->setWorksheet($spreadsheet->getActiveSheet());
Specifying coordinates for the image might help, as per the examples and the documentation
$objDrawing->setCoordinates('A3');
Note that an image isn't in a cell/column/row, but overlaid over the main sheet at the same position as that cell/column/row

How to fill image in pdf file using pdftk

This is my sample code.
I'm stuck on how to insert images into this.
I would be grateful for any help:
include('autoload.php');
use mikehaertl\pdftk\Pdf;
$dat = "review.png";
$pdf = new Pdf('Josco.pdf');
$pdf->fillForm(['signature'=>$dat ]);
$pdf->saveAs('my.pdf');
I don't know how to fill image in image type field. Please find attached
the pdf file for reference :
[1]: https://drive.google.com/file/d/1wz_mhdCFbG5o_1CgF6VlIJ4Gh70Ne8-E/view?usp=sharing
It is not possible to add image in a pdf using pdftk alone. A possibility would be to use tcpdf or fpdf to generate a pdf file of a blank page with the signature located where you want. Then to use the pdftk stamp function to stamp this generated file on the source pdf

PDF Image thumbnail preview in laravel 5.1?

I have file module, where I want to list all files,with thumbnail preview.
as like follows,
I am storing files in storage folder,which is not accessible via http.
So How can I provide thumbnail preview for docs especially image and PDF.
Is there any package availabe in laravel 5.1?
The preview image of a PDF file is usually the first page of the PDF file.
You can use ImageMagick to obtain that first page of the PDF file.
<?php
$imagick = new imagick('sample.pdf[0]'); // 0 specifies the first page of the pdf
$imagick->setImageFormat('jpg'); // set the format of the output image
header('Content-Type: image/jpeg'); // set the header for the browser to understand
echo $imagick; // display the image
?>
You can also output (save the contents of the image in a file) and store it under a thumbnail folder with the PDF name as the file name. like ( sample.jpg )
As for a solution based on laravel, I don't think laravel has any package that can do the same
Though the question was posted quite a long ago but I'm answering because it might helps others. There is a package for generating image from pdf. Pdf to Image. You should have Imagick and Ghostscript installed

Overwrite image in php while uploading

I want to know that how can I overwrite images when they uploaded to server in php. For example I uploaded a photo to a folder as soon as I upload another image it will take place of previous image. Image name is not same it may differ. Thanks
Delete the previous image before uploading the new one using:
$path = $_SERVER['DOCUMENT_ROOT'].'img/img.jpg';
unlink($path);
This code basically assigns the path of the image to $path and deletes the image using unlink($path);

Categories