PHP code example of asignua / filament-image-annotations
1. Go to this page and download the library: Download asignua/filament-image-annotations library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asignua / filament-image-annotations example snippets
use Asignua\FilamentImageAnnotations\ImageAnnotationsPlugin;
$panel->plugin(ImageAnnotationsPlugin::make());
use Asignua\FilamentImageAnnotations\Actions\AnnotateImageAction;
// table record action, header action or infolist action: it is a normal Filament action
AnnotateImageAction::make()->image(fn (Post $record) => $record->getFirstMedia('photos'));
use Asignua\FilamentImageAnnotations\Infolists\Components\AnnotatedImageEntry;
AnnotatedImageEntry::make('photo')
->image(fn (Post $record) => $record->getFirstMedia('photos'))
->alt('Front door');
use Asignua\FilamentImageAnnotations\AnnotatedUpload;
AnnotatedUpload::make(
FileUpload::make('image')->image()->disk('public')->directory('notes'),
)
AnnotatedUpload::make(
SpatieMediaLibraryFileUpload::make('photos')->collection('photos')->multiple()->image(),
)
use Asignua\FilamentImageAnnotations\Forms\Components\ImageAnnotator;
ImageAnnotator::make('annotations')->image(fn (Post $record) => $record->getFirstMedia('photos'));
use Asignua\FilamentImageAnnotations\ImageAnnotations;
ImageAnnotations::for($media); // the layer for the signed-in user, or null (nothing drawn / not allowed)
ImageAnnotations::store()->shapes($source, $user); // always a sanitised layer, empty when there is none
ImageAnnotations::store()->save($source, $user, $shapes); // throws AuthorizationException; an empty layer deletes the row
ImageAnnotations::store()->forget($source); // removes the layer, no authorisation check
interface ImageSource
{
public function annotatable(): Model; // the row owner of the morph relation
public function key(): ?string; // null for an image that is its own model (Media); a path for a file in a column
public function url(): string; // displayable URL of the ORIGINAL image
public function canView(?Authenticatable $user): bool;
public function canAnnotate(?Authenticatable $user): bool;
}
use Asignua\FilamentImageAnnotations\Support\ImageSources;
app(ImageSources::class)->register(Attachment::class, fn (Attachment $attachment) => new AttachmentImageSource($attachment));
use Asignua\FilamentImageAnnotations\ImageAnnotations;
ImageAnnotations::authorizeUsing(function (?Authenticatable $user, ImageSource $source, string $ability): bool {
// $ability is 'view' or 'annotate'
return $user?->can('manage-photos') ?? false;
});
use Asignua\FilamentImageAnnotations\Concerns\HasImageAnnotations;
class Note extends Model
{
use HasImageAnnotations; // $note->imageAnnotations(); rows removed on forceDelete()
}