Mark defects on site photos in a Filament form
A site inspector walks a flat before handover. In the living room there is a crack running from the corner of the window, and the socket cover below it is loose. They take a photo. Then, back at the office, someone has to explain which crack, where exactly, and what to do about it. Usually that means the photo in one place, a description in another field ("crack, lower right of the window, about 40 cm"), and a screenshot with a red circle made in some other app and emailed around.
This article shows the same form with Warp Markup: the inspector uploads the photo and draws on it in the same form, with a circle, an arrow and a numbered pin with a note. The marks are saved with the record. All pictures are from the live demo.
The scene: one photo, two problems
The inspector opens "New site photo", types what is in the photo and uploads it. Right under the upload field, the same photo appears as a drawing area, with a small toolbar: select, pin, circle, arrow, seven colors, undo, redo and delete.
Step 1: a drawing field next to the upload
The photo is a normal Filament FileUpload. MarkupField draws on the first image of that upload with imageFrom(), and tools() keeps the toolbar to what an inspector needs.
use Filament\Forms\Components\FileUpload;
use Qalainau\FilamentWarpMarkup\Forms\MarkupField;
FileUpload::make('photo')
->image()
->disk('public')
->maxSize(5120),
MarkupField::make('photo_marks')
->imageFrom('photo')
->tools(['arrow', 'ellipse', 'pin']),
The marks are saved in one JSON column, so the model only needs a cast:
protected function casts(): array
{
return ['photo_marks' => 'array'];
}
The photo file itself is never changed. Replace the photo with a better one, and the marks stay where they were, because they are stored in the image's own pixels.
Step 2: draw while the photo is fresh
Circles and arrows are dragged. A pin is a click: it gets a number and a small note field, and the note is also listed under the photo.
The server checks the shape of what is saved. Unknown kinds of marks and broken coordinates are dropped, because the JSON comes from the browser.
Step 3: the office gets one picture
After saving, the view page shows the marks on the photo, read-only, with MarkupEntry. For a printed report or an email, the marks need to be inside the picture. MarkupImage draws them into a copy of the photo on the server, with PHP's GD, and lists the pin notes under it:
use Qalainau\FilamentWarpMarkup\MarkupImage;
$jpeg = MarkupImage::fromDisk('public', $record->photo, $record->photo_marks, [
'maxWidth' => 1200,
'notes' => true,
]);
MarkupImage::dataUri() gives the same picture as a data: URI, for an <img> in a Blade view or an email.
The list of site photos shows how many marks each one has, so the office sees at a glance which photos have work on them.
Other scenes
- Vehicle check-in: scratches and dents marked on a photo or a drawing of the car (the demo has one).
- Move-out inspections: numbered pins on wall and floor damage, then one picture in the quote.
- Maintenance reports: an arrow at the broken part, pasted into the report email.
- Returns: a circle around the damaged corner of a product.
The toolbar has more tools when you need them: rectangles, clouds, lines, freehand ink, highlight, text and stamps. Pass the ones you want to tools().
For whole projects, Warp Markup also has a drawing workspace: PDF drawings with numbered findings as records of your own model, statuses, assignees, revisions and a findings report. The photo field in this article is the small end of it.
Limits worth knowing
MarkupImageneeds PHP'sgdextension. Phone photos are turned the right way up from their EXIF data when theexifextension is installed.- The bundled font for notes in the picture covers Latin, Greek and Cyrillic letters. For Japanese, Chinese or Korean notes, set a font that has them (
MarkupImage::defaultFont()or thefontoption). - SVG images can be drawn on in the form, but
MarkupImagecannot turn them into a picture.
Try it
Open the site photos demo and press "New site photo". Upload any photo from your phone or computer, draw a circle and a pin, save, and download the picture with the marks. No sign-up, and the data is reset every hour.