Skip to content

Codegen

Direktori: app/Services/Codegen/

Layanan generate Barcode dan QR Code. Menghasilkan gambar PNG dari konten string.

Ringkasan

ServiceTipeOutputPenggunaan
GenerateBarcode1D Barcode (C128, EAN13, dll)PNG binaryID siswa, label buku, tag aset
GenerateQRCodeQR CodePNG binaryLink scan cepat, absensi, kode pembayaran

Kenapa Ada

  • Terpusat: Satu tempat untuk semua generate barcode/QR
  • Konsisten: Opsi encoding dan error handling yang sama
  • Testable: Service bisa di-mock tanpa menyentuh controller

Method

GenerateBarcode::generate($content, $type = 'C128', $width = 2, $height = 30): string

Generate barcode 1D PNG.

php
$barcode = app(GenerateBarcode::class);
$png = $barcode->generate('STU-2026-001', 'C128', 2, 50);

GenerateQRCode::generate($content, $size = 120, $color = [0, 0, 0]): string

Generate QR Code PNG.

php
$qr = app(GenerateQRCode::class);
$png = $qr->generate('https://sutomo.sch.id/001', 200, [0, 0, 0]);

Cara Pakai

php
// Simpan sebagai Asset
$asset = new Asset;
$asset->uploadedFile = $png;
$asset->uploadOptions = ['folder' => 'barcodes', 'file_name' => 'barcode.png'];
$asset->save();

// Return sebagai response
return response($png, 200, ['Content-Type' => 'image/png']);

File Penting

FileTujuan
app/Services/Codegen/GenerateBarcode.phpGenerate 1D barcode
app/Services/Codegen/GenerateQRCode.phpGenerate QR Code
composer.jsonDependency milon/barcode