stitchforge / laravel
Laravel package for StitchForge embroidery digitizing API
v1.0.0
2026-06-05 00:44 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/bus: ^10.0|^11.0
- illuminate/http: ^10.0|^11.0
- illuminate/log: ^10.0|^11.0
- illuminate/queue: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
README
Paket Laravel untuk konsumsi StitchForge Embroidery Digitizing API.
Instalasi
composer require stitchforge/laravel
Tambahkan ke .env:
STITCHFORGE_BASE_URL=http://localhost:8080 STITCHFORGE_API_KEY=sk-st-xxxxxxxxxxxx
Quick Start
1. Sekali Jalan — upload, digitize, download
use StitchForge\Laravel\Facades\StitchForge; // Upload gambar → digitize → tunggu → export → download StitchForge::quick( imagePath: storage_path('app/logo-bordir.png'), savePath: storage_path('app/hasil.dst'), format: 'dst', settings: ['max_colors' => 15, 'stitch_density' => 4], texts: [ ['text' => 'Mugni & Eka', 'font' => 'script', 'size' => 36], ] ); // File hasil: storage/app/hasil.dst
2. Step-by-step (full control)
use StitchForge\Laravel\Facades\StitchForge; // Login (opsional, bisa langsung pake API key) $tokens = StitchForge::auth()->login('operator@stitchforge.id', 'password'); // Upload $upload = StitchForge::uploads()->image('/path/to/image.png'); $assetId = $upload['asset_id']; // Bikin job $job = StitchForge::jobs()->create($assetId, [ 'max_colors' => 15, 'stitch_density' => 4, ], [ ['text' => 'Monogram', 'font' => 'script', 'size' => 28], ]); // Polling sampe selesai $job = StitchForge::jobs()->wait($job->id, maxWaitSeconds: 60); // Export + download $export = StitchForge::jobs()->export($job->id, 'pes'); StitchForge::jobs()->download($export->id, '/downloads/hasil.pes');
3. Via Laravel Queue (async)
use StitchForge\Laravel\Jobs\PollJobStatus; // Dispatch polling job PollJobStatus::dispatch($job->id);
Di EventServiceProvider:
use StitchForge\Laravel\Events\JobCompleted; use StitchForge\Laravel\Events\JobFailed; protected $listen = [ JobCompleted::class => [\App\Listeners\NotifyUser::class], JobFailed::class => [\App\Listeners\AlertAdmin::class], ];
4. Dari Laravel Request (form upload)
Route::post('/digitize', function (\Illuminate\Http\Request $request) { $file = $request->file('design'); $upload = StitchForge::uploads()->fromRequest($file); $job = StitchForge::jobs()->create($upload['asset_id']); return response()->json(['job_id' => $job->id, 'status' => $job->status]); });
Auth Methods
| Method | Auth | Use Case |
|---|---|---|
X-API-Key header |
Set di .env → STITCHFORGE_API_KEY |
Backend/integrasi |
Authorization: Bearer <JWT> |
Setelah auth()->login() |
Multi-user app |
Konfigurasi
// config/stitchforge.php 'base_url' => env('STITCHFORGE_BASE_URL', 'http://localhost:8080'), 'api_key' => env('STITCHFORGE_API_KEY'), 'timeout' => 30, 'retries' => 3, 'defaults' => [ 'max_colors' => 15, 'stitch_density' => 4, 'export_format' => 'dst', ],
Text Fonts
Font built-in yang tersedia:
| Font | Cocok untuk |
|---|---|
sans |
Text biasa, minimalis |
serif |
Formal, klasik |
script |
Monogram wedding, undangan |
mono |
Kode, label teknis |
bold |
Judul, headline |
Fonts API
Kelola katalog font kustom:
use StitchForge\Laravel\Facades\StitchForge; // List semua font yang tersedia $fonts = StitchForge::fonts()->list(); // Buat font baru $font = StitchForge::fonts()->create( key: 'gothic', name: 'Gothic', category: 'serif', description: 'Font gaya gotik untuk desain klasik' ); // Update font StitchForge::fonts()->update('font-id', [ 'name' => 'Gothic Bold', 'category' => 'bold', ]); // Hapus font StitchForge::fonts()->delete('font-id');
Templates API
Kelola template monogram:
use StitchForge\Laravel\Facades\StitchForge; // List semua template $templates = StitchForge::templates()->list(); // Buat template baru $template = StitchForge::templates()->create( name: 'Wedding Circle', description: 'Template lingkaran untuk monogram wedding', elements: [ ['type' => 'circle', 'radius' => 100, 'x' => 200, 'y' => 200], ], textSlots: [ ['key' => 'initials', 'label' => 'Initial Name', 'font' => 'script', 'size' => 36], ] ); // Update template StitchForge::templates()->update('template-id', [ 'name' => 'Wedding Circle v2', ]); // Hapus template StitchForge::templates()->delete('template-id'); // Resolve template dengan nilai user $composed = StitchForge::templates()->resolve('template-id', [ 'initials' => 'M & E', ]);
Pricing API
Kelola harga benang:
use StitchForge\Laravel\Facades\StitchForge; // Lihat harga saat ini $pricing = StitchForge::pricing()->get(); // Returns: ['polyester_per_kg' => 5.00, 'metallic_per_kg' => 8.50, 'rayon_per_kg' => 6.00] // Update harga StitchForge::pricing()->update([ 'polyester_per_kg' => 5.50, 'metallic_per_kg' => 9.00, 'rayon_per_kg' => 6.50, ]);