3

I implemented this library to generate barcodes images in my laravel project https://github.com/milon/barcode

Everything works fine, the image is generated correctly, but now i want save the barcode image in my storage folder

For the barcode image i just add a value in my database and then i convert that value in a barcode image

This is the code where i add the value in my database:

<div class="form-group {{ $errors->first('barcode', 'has-error') }}">
    <label for="title" class="col-sm-3 control-label">
        Barcode
    </label>

    <div class="col-sm-6">
        {{ Form::text('barcode', NULL, ['class' => 'form-control required', 'minlength' => 3]) }}
    </div>
</div>

And this is the code i use to generate the barcode image:

{!!  DNS1D::getBarcodeHTML("$employee->barcode", "C39")!!}
Franko Hysaj
  • 99
  • 1
  • 4
  • 11

1 Answers1

5

Try this

\Storage::disk('public')->put('test.png',base64_decode(DNS2D::getBarcodePNG("4", "PDF417")));

Make sure your storage folder has write permission.

Faraz Irfan
  • 1,306
  • 3
  • 10
  • 17
  • do i put this in my controller or when i generate the barcode image ?? – Franko Hysaj Feb 23 '18 at 14:42
  • 1
    Generate image in controller, save it and then pass it to view, you are generating it inside view that is not a good practice. – Faraz Irfan Feb 23 '18 at 14:45
  • ok thanks that helped me a lot ,but how can i put the value of the barcode as the name of the image that i store and how can i save the image as a blob – Franko Hysaj Feb 23 '18 at 15:07
  • Thanks Faraz! The key here is base64_decode. I had a scenario where I just wanted to literally pass an image back to the requestor. I actually passed this directly back in a response method because I didn't have a need to store to disk. return response(base64_decode(DNS1DFacade::getBarcodePNG($content,'C39')),200,['Content-Type' => 'image/png']); – Jordan H May 21 '21 at 20:29