1. Go to this page and download the library: Download nativephp/mobile-camera 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/ */
nativephp / mobile-camera example snippets
use Native\Mobile\Facades\Camera;
// Take a photo
Camera::getPhoto();
// Record a video
Camera::recordVideo();
// Record with max duration
Camera::recordVideo(['maxDuration' => 30]);
// Using fluent API
Camera::recordVideo()
->maxDuration(60)
->id('my-video-123')
->start();
// Pick images from gallery
Camera::pickImages('images', false); // Single image
Camera::pickImages('images', true); // Multiple images
Camera::pickImages('all', true); // Any media type
use Native\Mobile\Attributes\OnNative;
use Native\Mobile\Events\Camera\PhotoTaken;
#[OnNative(PhotoTaken::class)]
public function handlePhotoTaken(string $path)
{
// Process the captured photo
$this->processPhoto($path);
}
use Native\Mobile\Attributes\OnNative;
use Native\Mobile\Events\Gallery\MediaSelected;
#[OnNative(MediaSelected::class)]
public function handleMediaSelected($success, $files, $count)
{
foreach ($files as $file) {
$this->processMedia($file);
}
}
use Native\Mobile\Testing\Native;
it('opens the camera when taking a profile photo', function () {
Native::test(ProfileEditor::class)
->tap('Take photo')
->assertPhotoRequested();
});
it('opens the gallery picker for a single image', function () {
Native::test(ProfileEditor::class)
->tap('Choose from gallery')
->assertMediaPicked(fn (array $p) => $p['mediaType'] === 'image' && $p['multiple'] === false);
});
it('does not touch the camera on a plain form save', function () {
Native::test(ProfileEditor::class)
->tap('Save')
->assertNothingCaptured();
});